generated from fmartingr/golang-app-template
Initial commit
This commit is contained in:
commit
3b55610e80
|
@ -0,0 +1,32 @@
|
|||
name: Go
|
||||
|
||||
on:
|
||||
workflow_call:
|
||||
inputs:
|
||||
go_versions:
|
||||
type: string
|
||||
description: Go versions to run workflow on
|
||||
required: true
|
||||
|
||||
jobs:
|
||||
build:
|
||||
permissions:
|
||||
contents: read
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
go_version: ${{ fromJSON(inputs.go_versions) }}
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Set up go
|
||||
uses: actions/setup-go@v2
|
||||
with:
|
||||
go-version: ${{ matrix.go_version }}
|
||||
|
||||
- name: Run GoReleaser
|
||||
uses: goreleaser/goreleaser-action@v2
|
||||
with:
|
||||
distribution: goreleaser
|
||||
version: latest
|
||||
args: build --single-target --snapshot
|
|
@ -0,0 +1,40 @@
|
|||
name: "Build Docker"
|
||||
|
||||
on:
|
||||
workflow_call:
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
buildx:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: read # Required to read dist files (and repository)
|
||||
packages: write # Required to push packages to GHCR
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
name: Build Docker
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- uses: actions/download-artifact@v3
|
||||
with:
|
||||
name: dist
|
||||
path: dist
|
||||
|
||||
- name: Log in to registry
|
||||
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin
|
||||
|
||||
- name: Buildx
|
||||
run: |
|
||||
REPOSITORY=ghcr.io/${{ github.repository }}
|
||||
|
||||
TAG_COMMIT=$(git describe --tag)
|
||||
TAG_MAIN=latest
|
||||
if [ -z "$(git tag --points-at HEAD)" ]
|
||||
then
|
||||
TAG_MAIN="dev"
|
||||
fi
|
||||
|
||||
CONTAINER_BUILDX_OPTIONS="--push --output=type=registry --tag $REPOSITORY:$TAG_COMMIT --tag $REPOSITORY:$TAG_MAIN" make buildx
|
|
@ -0,0 +1,19 @@
|
|||
name: Go
|
||||
|
||||
on:
|
||||
workflow_call:
|
||||
outputs:
|
||||
go_versions:
|
||||
description: "The golang version matrix"
|
||||
value: ${{ jobs.go-versions.outputs.matrix }}
|
||||
|
||||
jobs:
|
||||
go-versions:
|
||||
name: Lookup go versions
|
||||
runs-on: ubuntu-latest
|
||||
outputs:
|
||||
matrix: ${{ steps.versions.outputs.matrix }}
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: arnested/go-version-action@v1
|
||||
id: versions
|
|
@ -0,0 +1,17 @@
|
|||
name: "golangci-lint"
|
||||
|
||||
on: workflow_call
|
||||
|
||||
jobs:
|
||||
golangci:
|
||||
permissions:
|
||||
contents: read
|
||||
pull-requests: read
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: golangci-lint
|
||||
uses: golangci/golangci-lint-action@v2
|
||||
with:
|
||||
version: latest
|
||||
only-new-issues: true
|
|
@ -0,0 +1,33 @@
|
|||
name: goreleaser
|
||||
|
||||
on:
|
||||
workflow_call:
|
||||
|
||||
jobs:
|
||||
goreleaser:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: write # Required to upload dist files
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v2
|
||||
with:
|
||||
go-version: 1.19
|
||||
|
||||
- name: Run GoReleaser
|
||||
uses: goreleaser/goreleaser-action@v2
|
||||
with:
|
||||
version: latest
|
||||
args: release --rm-dist
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: dist
|
||||
path: ./dist/*
|
|
@ -0,0 +1,28 @@
|
|||
name: "Unit Tests"
|
||||
|
||||
on:
|
||||
workflow_call:
|
||||
inputs:
|
||||
go_versions:
|
||||
type: string
|
||||
description: Go versions to run workflow on
|
||||
required: true
|
||||
|
||||
jobs:
|
||||
test:
|
||||
permissions:
|
||||
contents: read
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
go_version: ${{ fromJSON(inputs.go_versions) }}
|
||||
name: Go ${{ matrix.go_version }} unit tests
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- name: Setup go
|
||||
uses: actions/setup-go@v2
|
||||
with:
|
||||
go-version: ${{ matrix.go_version }}
|
||||
|
||||
- run: make test
|
|
@ -0,0 +1,26 @@
|
|||
name: "Pull Request"
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches:
|
||||
- latest
|
||||
|
||||
concurrency:
|
||||
group: ci-pull-request-${{ github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
go-versions:
|
||||
uses: ./.github/workflows/_go-versions.yml
|
||||
call-lint:
|
||||
uses: ./.github/workflows/_golangci-lint.yml
|
||||
call-build:
|
||||
uses: ./.github/workflows/_build.yml
|
||||
needs: go-versions
|
||||
with:
|
||||
go_versions: ${{ needs.go-versions.outputs.go_versions }}
|
||||
call-test:
|
||||
uses: ./.github/workflows/_test.yml
|
||||
needs: go-versions
|
||||
with:
|
||||
go_versions: ${{ needs.go-versions.outputs.go_versions }}
|
|
@ -0,0 +1,20 @@
|
|||
name: goreleaser
|
||||
|
||||
# Keep in mind that the first run of this workflow will probable be pushed
|
||||
# without tags, so it will fail on the git command.
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [latest]
|
||||
tags: ["v*"]
|
||||
|
||||
concurrency:
|
||||
group: ci-push-version-${{ github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
goreleaser:
|
||||
uses: ./.github/workflows/_goreleaser.yml
|
||||
docker-buildx:
|
||||
needs: goreleaser
|
||||
uses: ./.github/workflows/_docker-buildx.yml
|
|
@ -0,0 +1,23 @@
|
|||
# Binaries for programs and plugins
|
||||
*.exe
|
||||
*.exe~
|
||||
*.dll
|
||||
*.so
|
||||
*.dylib
|
||||
|
||||
# Test binary, built with `go test -c`
|
||||
*.test
|
||||
|
||||
# Output of the go coverage tool
|
||||
coverage.*
|
||||
|
||||
# Dependency directories (remove the comment below to include it)
|
||||
# vendor/
|
||||
|
||||
# CI
|
||||
build/
|
||||
dist/
|
||||
|
||||
# Editors
|
||||
*~
|
||||
.vscode
|
|
@ -0,0 +1,44 @@
|
|||
before:
|
||||
hooks:
|
||||
- go mod tidy
|
||||
builds:
|
||||
- env:
|
||||
- CGO_ENABLED=0
|
||||
goos:
|
||||
- linux
|
||||
- windows
|
||||
- darwin
|
||||
goarch:
|
||||
- amd64
|
||||
- arm64
|
||||
- arm
|
||||
goarm:
|
||||
- 6
|
||||
- 7
|
||||
ignore:
|
||||
- goos: windows
|
||||
goarch: arm
|
||||
- goos: windows
|
||||
goarch: arm64
|
||||
main: ./cmd/golang-app-template
|
||||
ldflags:
|
||||
- -s -w
|
||||
archives:
|
||||
- replacements:
|
||||
darwin: macos
|
||||
386: i386
|
||||
amd64: x86_64
|
||||
source:
|
||||
enabled: true
|
||||
name_template: "{{ .ProjectName }}-{{ .Version }}-sources"
|
||||
format: "tar.gz"
|
||||
checksum:
|
||||
name_template: "checksums.txt"
|
||||
snapshot:
|
||||
name_template: "{{ .Tag }}-dev"
|
||||
changelog:
|
||||
sort: asc
|
||||
filters:
|
||||
exclude:
|
||||
- "^docs:"
|
||||
- "^test:"
|
|
@ -0,0 +1,27 @@
|
|||
# Build stage
|
||||
ARG ALPINE_VERSION
|
||||
|
||||
FROM docker.io/library/alpine:${ALPINE_VERSION} AS builder
|
||||
ARG TARGETARCH
|
||||
ARG TARGETOS
|
||||
ARG TARGETVARIANT
|
||||
ARG BIN_NAME
|
||||
COPY dist/${BIN_NAME}_${TARGETOS}_${TARGETARCH}${TARGETVARIANT}/${BIN_NAME} /usr/bin/${BIN_NAME}
|
||||
RUN apk add --no-cache ca-certificates tzdata && \
|
||||
chmod +x /usr/bin/${BIN_NAME}
|
||||
|
||||
# Server image
|
||||
FROM scratch
|
||||
ARG BIN_NAME
|
||||
ARG SOURCE_URL
|
||||
ARG MAINTAINER
|
||||
|
||||
ENV PORT 8080
|
||||
LABEL org.opencontainers.image.source="${SOURCE_URL}"
|
||||
LABEL maintainer="${MAINTAINER}"
|
||||
|
||||
COPY --from=builder /usr/bin/${BIN_NAME} /usr/bin/${BIN_NAME}
|
||||
COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo
|
||||
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
|
||||
|
||||
ENTRYPOINT ["/usr/bin/${BIN_NAME}"]
|
|
@ -0,0 +1,97 @@
|
|||
PROJECT_NAME := golang-app-template
|
||||
|
||||
SOURCE_FILES ?=./internal/... ./cmd/... ./pkg/...
|
||||
|
||||
TEST_OPTIONS ?= -v -failfast -race -bench=. -benchtime=100000x -cover -coverprofile=coverage.out
|
||||
TEST_TIMEOUT ?=1m
|
||||
|
||||
CLEAN_OPTIONS ?=-modcache -testcache
|
||||
|
||||
CGO_ENABLED := 0
|
||||
|
||||
BUILDS_PATH := ./dist
|
||||
FROM_MAKEFILE := y
|
||||
|
||||
CONTAINER_RUNTIME := podman
|
||||
CONTAINERFILE_NAME := Containerfile
|
||||
CONTAINER_ALPINE_VERSION := 3.16
|
||||
CONTAINER_SOURCE_URL := "https://github.com/fmartingr/${PROJECT_NAME}"
|
||||
CONTAINER_MAINTAINER := "Felipe Martin <me@fmartingr.com>"
|
||||
CONTAINER_BIN_NAME := ${PROJECT_NAME}
|
||||
|
||||
BUILDX_PLATFORMS := linux/amd64,arm64,linux/arm/v7
|
||||
|
||||
export PROJECT_NAME
|
||||
export FROM_MAKEFILE
|
||||
|
||||
export CGO_ENABLED
|
||||
|
||||
export SOURCE_FILES
|
||||
export TEST_OPTIONS
|
||||
export TEST_TIMEOUT
|
||||
export BUILDS_PATH
|
||||
|
||||
export CONTAINER_RUNTIME
|
||||
export CONTAINERFILE_NAME
|
||||
export CONTAINER_ALPINE_VERSION
|
||||
export CONTAINER_SOURCE_URL
|
||||
export CONTAINER_MAINTAINER
|
||||
export CONTAINER_BIN_NAME
|
||||
|
||||
export BUILDX_PLATFORMS
|
||||
|
||||
.PHONY: all
|
||||
all: help
|
||||
|
||||
# this is godly
|
||||
# https://news.ycombinator.com/item?id=11939200
|
||||
.PHONY: help
|
||||
help: ### this screen. Keep it first target to be default
|
||||
ifeq ($(UNAME), Linux)
|
||||
@grep -P '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | \
|
||||
awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'
|
||||
else
|
||||
@# this is not tested, but prepared in advance for you, Mac drivers
|
||||
@awk -F ':.*###' '$$0 ~ FS {printf "%15s%s\n", $$1 ":", $$2}' \
|
||||
$(MAKEFILE_LIST) | grep -v '@awk' | sort
|
||||
endif
|
||||
|
||||
.PHONY: clean
|
||||
clean: ### clean test cache, build files
|
||||
$(info: Make: Clean)
|
||||
@rm -rf ${BUILDS_PATH}
|
||||
@go clean ${CLEAN_OPTIONS}
|
||||
@-docker buildx rm ${PROJECT_NAME}_builder
|
||||
|
||||
.PHONY: build
|
||||
build: clean ### builds the project for the setup os/arch combinations
|
||||
$(info: Make: Build)
|
||||
@goreleaser build --rm-dist --snapshot
|
||||
|
||||
.PHONY: buildx
|
||||
buildx:
|
||||
$(info: Make: Buildx)
|
||||
@bash scripts/buildx.sh
|
||||
|
||||
.PHONY: quick-run
|
||||
quick-run: ### Executes the project using golang
|
||||
@go run ./cmd/${PROJECT_NAME}/*.go
|
||||
|
||||
.PHONY: run
|
||||
run: ### Executes the project build locally
|
||||
@make build
|
||||
${BUILDS_PATH}/${PROJECT_NAME}
|
||||
|
||||
.PHONY: format
|
||||
format: ### Executes the formatting pipeline on the project
|
||||
$(info: Make: Format)
|
||||
@bash scripts/format.sh
|
||||
|
||||
.PHONY: lint
|
||||
lint: ### Check the project for errors
|
||||
$(info: Make: Lint)
|
||||
@bash scripts/lint.sh
|
||||
|
||||
.PHONY: test
|
||||
test: ### Runs the test suite
|
||||
@bash scripts/test.sh
|
|
@ -0,0 +1,33 @@
|
|||
# golang-app-template
|
||||
|
||||
Golang application template for GitHub.
|
||||
|
||||
Contains:
|
||||
- Basic running Go code (just a `cmd` so everything else works)
|
||||
- A `Makefile` with some Quality of Life for contributing and executing common tasks.
|
||||
- A `Containerfile` with a boilerplate container with no dependencies.
|
||||
- [Goreleaser](https://goreleaser.com) configuration and CI.
|
||||
- A basic Helm chart
|
||||
- Github actions to build, test and release binaries and container images to the Github container registry.
|
||||
|
||||
|
||||
## Using the template
|
||||
|
||||
1. Press the **Use this template** button at the top of this repository.
|
||||
2. Find and replace `golang-app-template` everywhere you need
|
||||
3. Rename `cmd/golang-app-template`
|
||||
4. `make quick-run`
|
||||
|
||||
## Makefile
|
||||
|
||||
```
|
||||
$ make help
|
||||
build: builds the project for the setup os/arch combinations
|
||||
clean: clean test cache, build files
|
||||
format: Executes the formatting pipeline on the project
|
||||
help: this screen. Keep it first target to be default
|
||||
lint: Check the project for errors
|
||||
quick-run: Executes the project using golang
|
||||
run: Executes the project build locally
|
||||
test: Runs the test suite
|
||||
```
|
|
@ -0,0 +1,7 @@
|
|||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
fmt.Println("I come in peace.")
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
module github.com/fmartingr/golang-app-template
|
||||
|
||||
go 1.19
|
|
@ -0,0 +1,23 @@
|
|||
# Patterns to ignore when building packages.
|
||||
# This supports shell glob matching, relative path matching, and
|
||||
# negation (prefixed with !). Only one pattern per line.
|
||||
.DS_Store
|
||||
# Common VCS dirs
|
||||
.git/
|
||||
.gitignore
|
||||
.bzr/
|
||||
.bzrignore
|
||||
.hg/
|
||||
.hgignore
|
||||
.svn/
|
||||
# Common backup files
|
||||
*.swp
|
||||
*.bak
|
||||
*.tmp
|
||||
*.orig
|
||||
*~
|
||||
# Various IDEs
|
||||
.project
|
||||
.idea/
|
||||
*.tmproj
|
||||
.vscode/
|
|
@ -0,0 +1,13 @@
|
|||
apiVersion: v2
|
||||
name: golang-app-template
|
||||
description: A Helm chart for Kubernetes
|
||||
type: application
|
||||
# This is the chart version. This version number should be incremented each time you make changes
|
||||
# to the chart and its templates, including the app version.
|
||||
# Versions are expected to follow Semantic Versioning (https://semver.org/)
|
||||
version: 0.3.0
|
||||
# This is the version number of the application being deployed. This version number should be
|
||||
# incremented each time you make changes to the application. Versions are not expected to
|
||||
# follow Semantic Versioning. They should reflect the version the application is using.
|
||||
# It is recommended to use it with quotes.
|
||||
appVersion: "0.3.0"
|
|
@ -0,0 +1,17 @@
|
|||
# Helm chart
|
||||
|
||||
## Install the chart
|
||||
|
||||
```
|
||||
helm install --namespace golang-app-template --atomic golang-app-template .
|
||||
```
|
||||
|
||||
## Upgrading the chart
|
||||
|
||||
```
|
||||
helm upgrade --namespace golang-app-template --atomic golang-app-template .
|
||||
```
|
||||
|
||||
## Using locally with latest dev image
|
||||
|
||||
A `values.local.yml` file is provided which will point the installation to the latest `dev` image.
|
|
@ -0,0 +1,22 @@
|
|||
1. Get the application URL by running these commands:
|
||||
{{- if .Values.ingress.enabled }}
|
||||
{{- range $host := .Values.ingress.hosts }}
|
||||
{{- range .paths }}
|
||||
http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- else if contains "NodePort" .Values.service.type }}
|
||||
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "golang-app-template.fullname" . }})
|
||||
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
|
||||
echo http://$NODE_IP:$NODE_PORT
|
||||
{{- else if contains "LoadBalancer" .Values.service.type }}
|
||||
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
|
||||
You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "golang-app-template.fullname" . }}'
|
||||
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "golang-app-template.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}")
|
||||
echo http://$SERVICE_IP:{{ .Values.service.port }}
|
||||
{{- else if contains "ClusterIP" .Values.service.type }}
|
||||
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "golang-app-template.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
|
||||
export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}")
|
||||
echo "Visit http://127.0.0.1:8080 to use your application"
|
||||
kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT
|
||||
{{- end }}
|
|
@ -0,0 +1,62 @@
|
|||
{{/*
|
||||
Expand the name of the chart.
|
||||
*/}}
|
||||
{{- define "golang-app-template.name" -}}
|
||||
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
|
||||
{{- end }}
|
||||
|
||||
{{/*
|
||||
Create a default fully qualified app name.
|
||||
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
|
||||
If release name contains chart name it will be used as a full name.
|
||||
*/}}
|
||||
{{- define "golang-app-template.fullname" -}}
|
||||
{{- if .Values.fullnameOverride }}
|
||||
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
|
||||
{{- else }}
|
||||
{{- $name := default .Chart.Name .Values.nameOverride }}
|
||||
{{- if contains $name .Release.Name }}
|
||||
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
|
||||
{{- else }}
|
||||
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
|
||||
{{/*
|
||||
Create chart name and version as used by the chart label.
|
||||
*/}}
|
||||
{{- define "golang-app-template.chart" -}}
|
||||
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
|
||||
{{- end }}
|
||||
|
||||
{{/*
|
||||
Common labels
|
||||
*/}}
|
||||
{{- define "golang-app-template.labels" -}}
|
||||
helm.sh/chart: {{ include "golang-app-template.chart" . }}
|
||||
{{ include "golang-app-template.selectorLabels" . }}
|
||||
{{- if .Chart.AppVersion }}
|
||||
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
|
||||
{{- end }}
|
||||
app.kubernetes.io/managed-by: {{ .Release.Service }}
|
||||
{{- end }}
|
||||
|
||||
{{/*
|
||||
Selector labels
|
||||
*/}}
|
||||
{{- define "golang-app-template.selectorLabels" -}}
|
||||
app.kubernetes.io/name: {{ include "golang-app-template.name" . }}
|
||||
app.kubernetes.io/instance: {{ .Release.Name }}
|
||||
{{- end }}
|
||||
|
||||
{{/*
|
||||
Create the name of the service account to use
|
||||
*/}}
|
||||
{{- define "golang-app-template.serviceAccountName" -}}
|
||||
{{- if .Values.serviceAccount.create }}
|
||||
{{- default (include "golang-app-template.fullname" .) .Values.serviceAccount.name }}
|
||||
{{- else }}
|
||||
{{- default "default" .Values.serviceAccount.name }}
|
||||
{{- end }}
|
||||
{{- end }}
|
|
@ -0,0 +1,61 @@
|
|||
{{- if .Values.ingress.enabled -}}
|
||||
{{- $fullName := include "golang-app-template.fullname" . -}}
|
||||
{{- $svcPort := .Values.service.port -}}
|
||||
{{- if and .Values.ingress.className (not (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion)) }}
|
||||
{{- if not (hasKey .Values.ingress.annotations "kubernetes.io/ingress.class") }}
|
||||
{{- $_ := set .Values.ingress.annotations "kubernetes.io/ingress.class" .Values.ingress.className}}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- if semverCompare ">=1.19-0" .Capabilities.KubeVersion.GitVersion -}}
|
||||
apiVersion: networking.k8s.io/v1
|
||||
{{- else if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}}
|
||||
apiVersion: networking.k8s.io/v1beta1
|
||||
{{- else -}}
|
||||
apiVersion: extensions/v1beta1
|
||||
{{- end }}
|
||||
kind: Ingress
|
||||
metadata:
|
||||
name: {{ $fullName }}
|
||||
labels:
|
||||
{{- include "golang-app-template.labels" . | nindent 4 }}
|
||||
{{- with .Values.ingress.annotations }}
|
||||
annotations:
|
||||
{{- toYaml . | nindent 4 }}
|
||||
{{- end }}
|
||||
spec:
|
||||
{{- if and .Values.ingress.className (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion) }}
|
||||
ingressClassName: {{ .Values.ingress.className }}
|
||||
{{- end }}
|
||||
{{- if .Values.ingress.tls }}
|
||||
tls:
|
||||
{{- range .Values.ingress.tls }}
|
||||
- hosts:
|
||||
{{- range .hosts }}
|
||||
- {{ . | quote }}
|
||||
{{- end }}
|
||||
secretName: {{ .secretName }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
rules:
|
||||
{{- range .Values.ingress.hosts }}
|
||||
- host: {{ .host | quote }}
|
||||
http:
|
||||
paths:
|
||||
{{- range .paths }}
|
||||
- path: {{ .path }}
|
||||
{{- if and .pathType (semverCompare ">=1.18-0" $.Capabilities.KubeVersion.GitVersion) }}
|
||||
pathType: {{ .pathType }}
|
||||
{{- end }}
|
||||
backend:
|
||||
{{- if semverCompare ">=1.19-0" $.Capabilities.KubeVersion.GitVersion }}
|
||||
service:
|
||||
name: {{ $fullName }}
|
||||
port:
|
||||
number: {{ $svcPort }}
|
||||
{{- else }}
|
||||
serviceName: {{ $fullName }}
|
||||
servicePort: {{ $svcPort }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- end }}
|
|
@ -0,0 +1,15 @@
|
|||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: {{ include "golang-app-template.fullname" . }}
|
||||
labels:
|
||||
{{- include "golang-app-template.labels" . | nindent 4 }}
|
||||
spec:
|
||||
type: {{ .Values.service.type }}
|
||||
ports:
|
||||
- port: {{ .Values.app.http.port }}
|
||||
targetPort: http
|
||||
protocol: TCP
|
||||
name: http
|
||||
selector:
|
||||
{{- include "golang-app-template.selectorLabels" . | nindent 4 }}
|
|
@ -0,0 +1,12 @@
|
|||
{{- if .Values.serviceAccount.create -}}
|
||||
apiVersion: v1
|
||||
kind: ServiceAccount
|
||||
metadata:
|
||||
name: {{ include "golang-app-template.serviceAccountName" . }}
|
||||
labels:
|
||||
{{- include "golang-app-template.labels" . | nindent 4 }}
|
||||
{{- with .Values.serviceAccount.annotations }}
|
||||
annotations:
|
||||
{{- toYaml . | nindent 4 }}
|
||||
{{- end }}
|
||||
{{- end }}
|
|
@ -0,0 +1,62 @@
|
|||
apiVersion: apps/v1
|
||||
kind: StatefulSet
|
||||
metadata:
|
||||
name: {{ include "golang-app-template.fullname" . }}
|
||||
labels:
|
||||
{{- include "golang-app-template.labels" . | nindent 4 }}
|
||||
spec:
|
||||
serviceName: {{ include "golang-app-template.fullname" . }}
|
||||
{{- if not .Values.autoscaling.enabled }}
|
||||
replicas: {{ .Values.replicaCount }}
|
||||
{{- end }}
|
||||
selector:
|
||||
matchLabels:
|
||||
{{- include "golang-app-template.selectorLabels" . | nindent 6 }}
|
||||
template:
|
||||
metadata:
|
||||
{{- with .Values.podAnnotations }}
|
||||
annotations:
|
||||
{{- toYaml . | nindent 8 }}
|
||||
{{- end }}
|
||||
labels:
|
||||
{{- include "golang-app-template.selectorLabels" . | nindent 8 }}
|
||||
spec:
|
||||
{{- with .Values.imagePullSecrets }}
|
||||
imagePullSecrets:
|
||||
{{- toYaml . | nindent 8 }}
|
||||
{{- end }}
|
||||
serviceAccountName: {{ include "golang-app-template.serviceAccountName" . }}
|
||||
securityContext:
|
||||
{{- toYaml .Values.podSecurityContext | nindent 8 }}
|
||||
containers:
|
||||
- name: {{ .Chart.Name }}
|
||||
securityContext:
|
||||
{{- toYaml .Values.securityContext | nindent 12 }}
|
||||
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
|
||||
imagePullPolicy: {{ .Values.image.pullPolicy }}
|
||||
ports:
|
||||
- name: http
|
||||
containerPort: {{ .Values.app.http.port }}
|
||||
protocol: TCP
|
||||
livenessProbe:
|
||||
httpGet:
|
||||
path: {{ .Values.app.probes.liveness.path }}
|
||||
port: http
|
||||
readinessProbe:
|
||||
httpGet:
|
||||
path: {{ .Values.app.probes.readiness.path }}
|
||||
port: http
|
||||
resources:
|
||||
{{- toYaml .Values.resources | nindent 12 }}
|
||||
{{- with .Values.nodeSelector }}
|
||||
nodeSelector:
|
||||
{{- toYaml . | nindent 8 }}
|
||||
{{- end }}
|
||||
{{- with .Values.affinity }}
|
||||
affinity:
|
||||
{{- toYaml . | nindent 8 }}
|
||||
{{- end }}
|
||||
{{- with .Values.tolerations }}
|
||||
tolerations:
|
||||
{{- toYaml . | nindent 8 }}
|
||||
{{- end }}
|
|
@ -0,0 +1,15 @@
|
|||
apiVersion: v1
|
||||
kind: Pod
|
||||
metadata:
|
||||
name: "{{ include "golang-app-template.fullname" . }}-test-connection"
|
||||
labels:
|
||||
{{- include "golang-app-template.labels" . | nindent 4 }}
|
||||
annotations:
|
||||
"helm.sh/hook": test
|
||||
spec:
|
||||
containers:
|
||||
- name: wget
|
||||
image: busybox
|
||||
command: ['wget']
|
||||
args: ['{{ include "golang-app-template.fullname" . }}:{{ .Values.service.port }}']
|
||||
restartPolicy: Never
|
|
@ -0,0 +1,2 @@
|
|||
image:
|
||||
tag: "dev"
|
|
@ -0,0 +1,99 @@
|
|||
# Default values.
|
||||
# This is a YAML-formatted file.
|
||||
# Declare variables to be passed into your templates.
|
||||
|
||||
replicaCount: 1
|
||||
|
||||
image:
|
||||
repository: ghcr.io/fmartingr/golang-app-template
|
||||
pullPolicy: IfNotPresent
|
||||
# Overrides the image tag whose default is the chart appVersion.
|
||||
# tag: "dev"
|
||||
|
||||
imagePullSecrets: []
|
||||
nameOverride: ""
|
||||
fullnameOverride: ""
|
||||
|
||||
serviceAccount:
|
||||
# Specifies whether a service account should be created
|
||||
create: true
|
||||
# Annotations to add to the service account
|
||||
annotations: {}
|
||||
# The name of the service account to use.
|
||||
# If not set and create is true, a name is generated using the fullname template
|
||||
name: ""
|
||||
|
||||
podAnnotations: {}
|
||||
|
||||
podSecurityContext:
|
||||
{}
|
||||
# fsGroup: 2000
|
||||
|
||||
securityContext:
|
||||
{}
|
||||
# capabilities:
|
||||
# drop:
|
||||
# - ALL
|
||||
# readOnlyRootFilesystem: true
|
||||
# runAsNonRoot: true
|
||||
# runAsUser: 1000
|
||||
|
||||
service:
|
||||
type: ClusterIP
|
||||
port: 8080
|
||||
|
||||
ingress:
|
||||
enabled: true
|
||||
className: ""
|
||||
annotations:
|
||||
{}
|
||||
# kubernetes.io/ingress.class: nginx
|
||||
# kubernetes.io/tls-acme: "true"
|
||||
hosts:
|
||||
- host: golang-app-template.local
|
||||
paths:
|
||||
- path: /
|
||||
pathType: ImplementationSpecific
|
||||
tls: []
|
||||
# - secretName: golang-app-template-tls
|
||||
# hosts:
|
||||
# - golang-app-template.local
|
||||
|
||||
resources:
|
||||
{}
|
||||
# We usually recommend not to specify default resources and to leave this as a conscious
|
||||
# choice for the user. This also increases chances charts run on environments with little
|
||||
# resources, such as Minikube. If you do want to specify resources, uncomment the following
|
||||
# lines, adjust them as necessary, and remove the curly braces after 'resources:'.
|
||||
# limits:
|
||||
# cpu: 100m
|
||||
# memory: 128Mi
|
||||
# requests:
|
||||
# cpu: 100m
|
||||
# memory: 128Mi
|
||||
|
||||
autoscaling:
|
||||
enabled: false
|
||||
minReplicas: 1
|
||||
maxReplicas: 100
|
||||
targetCPUUtilizationPercentage: 80
|
||||
# targetMemoryUtilizationPercentage: 80
|
||||
|
||||
nodeSelector: {}
|
||||
|
||||
tolerations: []
|
||||
|
||||
affinity: {}
|
||||
|
||||
probes:
|
||||
path: /liveness
|
||||
|
||||
app:
|
||||
http:
|
||||
port: 8080
|
||||
|
||||
probes:
|
||||
liveness:
|
||||
path: /liveness
|
||||
readiness:
|
||||
path: /liveness
|
|
@ -0,0 +1,29 @@
|
|||
#!/usr/bin/env bash
|
||||
set -ex
|
||||
|
||||
if [ -z "$FROM_MAKEFILE" ]; then
|
||||
echo "Do not call this file directly - use the make command"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
CONTAINER_RUNTIME=docker # Forcing docker
|
||||
|
||||
if [ "$CONTAINER_RUNTIME" == "docker" ]; then
|
||||
$CONTAINER_RUNTIME buildx create --use --name ${PROJECT_NAME}_builder
|
||||
fi
|
||||
|
||||
cp -r dist/${PROJECT_NAME}_linux_arm_7 dist/${PROJECT_NAME}_linux_armv7
|
||||
cp -r dist/${PROJECT_NAME}_linux_amd64_v1 dist/${PROJECT_NAME}_linux_amd64
|
||||
|
||||
$CONTAINER_RUNTIME buildx build \
|
||||
-f ${CONTAINERFILE_NAME} \
|
||||
--platform=${BUILDX_PLATFORMS} \
|
||||
--build-arg "ALPINE_VERSION=${CONTAINER_ALPINE_VERSION}" \
|
||||
--build-arg "BIN_NAME=${CONTAINER_BIN_NAME}" \
|
||||
--build-arg "SOURCE_URL=${CONTAINER_SOURCE_URL}" \
|
||||
--build-arg "MAINTAINER=${CONTAINER_MAINTAINER}" \
|
||||
${CONTAINER_BUILDX_OPTIONS} .
|
||||
|
||||
if [ "$CONTAINER_RUNTIME" == "docker" ]; then
|
||||
$CONTAINER_RUNTIME buildx rm ${PROJECT_NAME}_builder
|
||||
fi
|
|
@ -0,0 +1,22 @@
|
|||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
if [ -z "$FROM_MAKEFILE" ]; then
|
||||
echo "Do not call this file directly - use the make command"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Enable/Disable formatters
|
||||
GOFMT_ENABLED=${GOFMT_ENABLED:-y}
|
||||
|
||||
# Add go binaries path to current $PATH
|
||||
PATH=$PATH:$(go env GOPATH)/bin
|
||||
|
||||
files=$(find . -name '*.go')
|
||||
|
||||
for file in $files
|
||||
do
|
||||
if [ "$GOFMT_ENABLED" == "y" ]; then
|
||||
gofmt -w -s $file
|
||||
fi
|
||||
done
|
|
@ -0,0 +1,9 @@
|
|||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
if [ -z "$FROM_MAKEFILE" ]; then
|
||||
echo "Do not call this file directly - use the make command"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
golangci-lint run --tests=false
|
|
@ -0,0 +1,20 @@
|
|||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
if [ -z "$FROM_MAKEFILE" ]; then
|
||||
echo "Do not call this file directly - use the make command"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
COVERAGE_PATH=coverage.out
|
||||
COVERAGE_HTML_PATH=coverage.html
|
||||
CGO_ENABLED=1 # Used for -race
|
||||
|
||||
go test ${TEST_OPTIONS} ${SOURCE_FILES} -timeout=${TEST_TIMEOUT}
|
||||
|
||||
echo
|
||||
echo "== Coverage report =="
|
||||
echo
|
||||
|
||||
go tool cover -html=${COVERAGE_PATH} -o ${COVERAGE_HTML_PATH}
|
||||
go tool cover -func=${COVERAGE_PATH}
|
Loading…
Reference in New Issue