refactor: rename template names

This commit is contained in:
Felipe M 2022-09-05 18:43:02 +02:00
parent 3b55610e80
commit 7b9f034527
Signed by: fmartingr
GPG Key ID: 716BC147715E716F
15 changed files with 41 additions and 73 deletions

View File

@ -20,7 +20,7 @@ builds:
goarch: arm goarch: arm
- goos: windows - goos: windows
goarch: arm64 goarch: arm64
main: ./cmd/golang-app-template main: ./cmd/ichi
ldflags: ldflags:
- -s -w - -s -w
archives: archives:

View File

@ -1,4 +1,4 @@
PROJECT_NAME := golang-app-template PROJECT_NAME := ichi
SOURCE_FILES ?=./internal/... ./cmd/... ./pkg/... SOURCE_FILES ?=./internal/... ./cmd/... ./pkg/...

View File

@ -1,33 +1 @@
# golang-app-template # ichi
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
```

2
go.mod
View File

@ -1,3 +1,3 @@
module github.com/fmartingr/golang-app-template module code.fmartingr.dev/fmartingr/ichi
go 1.19 go 1.19

View File

@ -1,5 +1,5 @@
apiVersion: v2 apiVersion: v2
name: golang-app-template name: ichi
description: A Helm chart for Kubernetes description: A Helm chart for Kubernetes
type: application type: application
# This is the chart version. This version number should be incremented each time you make changes # This is the chart version. This version number should be incremented each time you make changes

View File

@ -3,13 +3,13 @@
## Install the chart ## Install the chart
``` ```
helm install --namespace golang-app-template --atomic golang-app-template . helm install --namespace ichi --atomic ichi .
``` ```
## Upgrading the chart ## Upgrading the chart
``` ```
helm upgrade --namespace golang-app-template --atomic golang-app-template . helm upgrade --namespace ichi --atomic ichi .
``` ```
## Using locally with latest dev image ## Using locally with latest dev image

View File

@ -6,16 +6,16 @@
{{- end }} {{- end }}
{{- end }} {{- end }}
{{- else if contains "NodePort" .Values.service.type }} {{- 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_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "ichi.fullname" . }})
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}") export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
echo http://$NODE_IP:$NODE_PORT echo http://$NODE_IP:$NODE_PORT
{{- else if contains "LoadBalancer" .Values.service.type }} {{- else if contains "LoadBalancer" .Values.service.type }}
NOTE: It may take a few minutes for the LoadBalancer IP to be available. 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" . }}' You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "ichi.fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "golang-app-template.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}") export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "ichi.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}")
echo http://$SERVICE_IP:{{ .Values.service.port }} echo http://$SERVICE_IP:{{ .Values.service.port }}
{{- else if contains "ClusterIP" .Values.service.type }} {{- 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 POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "ichi.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}") 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" echo "Visit http://127.0.0.1:8080 to use your application"
kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT

View File

@ -1,7 +1,7 @@
{{/* {{/*
Expand the name of the chart. Expand the name of the chart.
*/}} */}}
{{- define "golang-app-template.name" -}} {{- define "ichi.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} {{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }} {{- end }}
@ -10,7 +10,7 @@ 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). 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. If release name contains chart name it will be used as a full name.
*/}} */}}
{{- define "golang-app-template.fullname" -}} {{- define "ichi.fullname" -}}
{{- if .Values.fullnameOverride }} {{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} {{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }} {{- else }}
@ -26,16 +26,16 @@ If release name contains chart name it will be used as a full name.
{{/* {{/*
Create chart name and version as used by the chart label. Create chart name and version as used by the chart label.
*/}} */}}
{{- define "golang-app-template.chart" -}} {{- define "ichi.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} {{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }} {{- end }}
{{/* {{/*
Common labels Common labels
*/}} */}}
{{- define "golang-app-template.labels" -}} {{- define "ichi.labels" -}}
helm.sh/chart: {{ include "golang-app-template.chart" . }} helm.sh/chart: {{ include "ichi.chart" . }}
{{ include "golang-app-template.selectorLabels" . }} {{ include "ichi.selectorLabels" . }}
{{- if .Chart.AppVersion }} {{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }} {{- end }}
@ -45,17 +45,17 @@ app.kubernetes.io/managed-by: {{ .Release.Service }}
{{/* {{/*
Selector labels Selector labels
*/}} */}}
{{- define "golang-app-template.selectorLabels" -}} {{- define "ichi.selectorLabels" -}}
app.kubernetes.io/name: {{ include "golang-app-template.name" . }} app.kubernetes.io/name: {{ include "ichi.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }} app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }} {{- end }}
{{/* {{/*
Create the name of the service account to use Create the name of the service account to use
*/}} */}}
{{- define "golang-app-template.serviceAccountName" -}} {{- define "ichi.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }} {{- if .Values.serviceAccount.create }}
{{- default (include "golang-app-template.fullname" .) .Values.serviceAccount.name }} {{- default (include "ichi.fullname" .) .Values.serviceAccount.name }}
{{- else }} {{- else }}
{{- default "default" .Values.serviceAccount.name }} {{- default "default" .Values.serviceAccount.name }}
{{- end }} {{- end }}

View File

@ -1,5 +1,5 @@
{{- if .Values.ingress.enabled -}} {{- if .Values.ingress.enabled -}}
{{- $fullName := include "golang-app-template.fullname" . -}} {{- $fullName := include "ichi.fullname" . -}}
{{- $svcPort := .Values.service.port -}} {{- $svcPort := .Values.service.port -}}
{{- if and .Values.ingress.className (not (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion)) }} {{- if and .Values.ingress.className (not (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion)) }}
{{- if not (hasKey .Values.ingress.annotations "kubernetes.io/ingress.class") }} {{- if not (hasKey .Values.ingress.annotations "kubernetes.io/ingress.class") }}
@ -17,7 +17,7 @@ kind: Ingress
metadata: metadata:
name: {{ $fullName }} name: {{ $fullName }}
labels: labels:
{{- include "golang-app-template.labels" . | nindent 4 }} {{- include "ichi.labels" . | nindent 4 }}
{{- with .Values.ingress.annotations }} {{- with .Values.ingress.annotations }}
annotations: annotations:
{{- toYaml . | nindent 4 }} {{- toYaml . | nindent 4 }}

View File

@ -1,9 +1,9 @@
apiVersion: v1 apiVersion: v1
kind: Service kind: Service
metadata: metadata:
name: {{ include "golang-app-template.fullname" . }} name: {{ include "ichi.fullname" . }}
labels: labels:
{{- include "golang-app-template.labels" . | nindent 4 }} {{- include "ichi.labels" . | nindent 4 }}
spec: spec:
type: {{ .Values.service.type }} type: {{ .Values.service.type }}
ports: ports:
@ -12,4 +12,4 @@ spec:
protocol: TCP protocol: TCP
name: http name: http
selector: selector:
{{- include "golang-app-template.selectorLabels" . | nindent 4 }} {{- include "ichi.selectorLabels" . | nindent 4 }}

View File

@ -2,9 +2,9 @@
apiVersion: v1 apiVersion: v1
kind: ServiceAccount kind: ServiceAccount
metadata: metadata:
name: {{ include "golang-app-template.serviceAccountName" . }} name: {{ include "ichi.serviceAccountName" . }}
labels: labels:
{{- include "golang-app-template.labels" . | nindent 4 }} {{- include "ichi.labels" . | nindent 4 }}
{{- with .Values.serviceAccount.annotations }} {{- with .Values.serviceAccount.annotations }}
annotations: annotations:
{{- toYaml . | nindent 4 }} {{- toYaml . | nindent 4 }}

View File

@ -1,17 +1,17 @@
apiVersion: apps/v1 apiVersion: apps/v1
kind: StatefulSet kind: StatefulSet
metadata: metadata:
name: {{ include "golang-app-template.fullname" . }} name: {{ include "ichi.fullname" . }}
labels: labels:
{{- include "golang-app-template.labels" . | nindent 4 }} {{- include "ichi.labels" . | nindent 4 }}
spec: spec:
serviceName: {{ include "golang-app-template.fullname" . }} serviceName: {{ include "ichi.fullname" . }}
{{- if not .Values.autoscaling.enabled }} {{- if not .Values.autoscaling.enabled }}
replicas: {{ .Values.replicaCount }} replicas: {{ .Values.replicaCount }}
{{- end }} {{- end }}
selector: selector:
matchLabels: matchLabels:
{{- include "golang-app-template.selectorLabels" . | nindent 6 }} {{- include "ichi.selectorLabels" . | nindent 6 }}
template: template:
metadata: metadata:
{{- with .Values.podAnnotations }} {{- with .Values.podAnnotations }}
@ -19,13 +19,13 @@ spec:
{{- toYaml . | nindent 8 }} {{- toYaml . | nindent 8 }}
{{- end }} {{- end }}
labels: labels:
{{- include "golang-app-template.selectorLabels" . | nindent 8 }} {{- include "ichi.selectorLabels" . | nindent 8 }}
spec: spec:
{{- with .Values.imagePullSecrets }} {{- with .Values.imagePullSecrets }}
imagePullSecrets: imagePullSecrets:
{{- toYaml . | nindent 8 }} {{- toYaml . | nindent 8 }}
{{- end }} {{- end }}
serviceAccountName: {{ include "golang-app-template.serviceAccountName" . }} serviceAccountName: {{ include "ichi.serviceAccountName" . }}
securityContext: securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }} {{- toYaml .Values.podSecurityContext | nindent 8 }}
containers: containers:

View File

@ -1,9 +1,9 @@
apiVersion: v1 apiVersion: v1
kind: Pod kind: Pod
metadata: metadata:
name: "{{ include "golang-app-template.fullname" . }}-test-connection" name: "{{ include "ichi.fullname" . }}-test-connection"
labels: labels:
{{- include "golang-app-template.labels" . | nindent 4 }} {{- include "ichi.labels" . | nindent 4 }}
annotations: annotations:
"helm.sh/hook": test "helm.sh/hook": test
spec: spec:
@ -11,5 +11,5 @@ spec:
- name: wget - name: wget
image: busybox image: busybox
command: ['wget'] command: ['wget']
args: ['{{ include "golang-app-template.fullname" . }}:{{ .Values.service.port }}'] args: ['{{ include "ichi.fullname" . }}:{{ .Values.service.port }}']
restartPolicy: Never restartPolicy: Never

View File

@ -5,7 +5,7 @@
replicaCount: 1 replicaCount: 1
image: image:
repository: ghcr.io/fmartingr/golang-app-template repository: ghcr.io/fmartingr/ichi
pullPolicy: IfNotPresent pullPolicy: IfNotPresent
# Overrides the image tag whose default is the chart appVersion. # Overrides the image tag whose default is the chart appVersion.
# tag: "dev" # tag: "dev"
@ -50,14 +50,14 @@ ingress:
# kubernetes.io/ingress.class: nginx # kubernetes.io/ingress.class: nginx
# kubernetes.io/tls-acme: "true" # kubernetes.io/tls-acme: "true"
hosts: hosts:
- host: golang-app-template.local - host: ichi.local
paths: paths:
- path: / - path: /
pathType: ImplementationSpecific pathType: ImplementationSpecific
tls: [] tls: []
# - secretName: golang-app-template-tls # - secretName: ichi-tls
# hosts: # hosts:
# - golang-app-template.local # - ichi.local
resources: resources:
{} {}