diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 57ec6313fdd4e9fd4840969ba36bcf2f6881ce0c..166408b83f30541aaf43c8232e2f39620f0b97cb 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -26,4 +26,49 @@ build: - /kaniko/executor --context "${CI_PROJECT_DIR}/app" --dockerfile "${CI_PROJECT_DIR}/app/Dockerfile" - --destination "${CI_REGISTRY_IMAGE}:${CI_COMMIT_TAG}" \ No newline at end of file + --destination "${CI_REGISTRY_IMAGE}:${CI_COMMIT_TAG}" + +.deploy: + stage: deploy + image: + name: alpine/k8s:1.28.2 + script: + - kubectl config use-context frank/k8s-templates:k8s-templates-agent + - | + helm upgrade \ + --install \ + --namespace "${NAMESPACE}" \ + --create-namespace \ + --atomic --wait \ + --timeout 15m0s \ + --set "backend.tag=${CI_COMMIT_TAG}" \ + --set "ingress.host=${HOST}" \ + kubetemplates k8s-templates + artifacts: + paths: + - kubernetes.yaml + expire_in: 30d + rules: + - if: $CI_COMMIT_TAG + +deploy_staging: + # Deploy the current image to the staging machine. + extends: .deploy + variables: + NAMESPACE: k8s-templates-staging + HOST: k8s.preview.sauerburger.com + environment: + name: Staging Environment + url: https://k8s.preview.sauerburger.com/ + +deploy_production: + extends: .deploy + when: manual + variables: + NAMESPACE: k8s-templates + HOST: k8s.sauerburger.com + environment: + name: Production Environment + url: https://k8s.sauerburger.com/ + + diff --git a/k8s-templates/Chart.yaml b/k8s-templates/Chart.yaml index 753df710b093c31d83067524b3ada8d5fe12bec5..df74f2d6e0bd6ac1baf7a7579aaa761adcc99642 100644 --- a/k8s-templates/Chart.yaml +++ b/k8s-templates/Chart.yaml @@ -15,10 +15,10 @@ 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.2.1 +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.2.1" +appVersion: "0.3.0" diff --git a/k8s-templates/templates/deployment.yaml b/k8s-templates/templates/deployment.yaml index 7ebb506fbafe15567e53d45fa43c0c2346bd2e74..e2cba7bbeb03e33fbfea9607953f0bd5153b9685 100644 --- a/k8s-templates/templates/deployment.yaml +++ b/k8s-templates/templates/deployment.yaml @@ -6,7 +6,6 @@ metadata: app.kubernetes.io/part-of: {{ .Release.Name }} app.kubernetes.io/name: k8s-templates app.kubernetes.io/instance: k8s-templates-main - app.kubernetes.io/version: "0.2.0" app.kubernetes.io/component: backend spec: replicas: {{ .Values.backend.replicas }} @@ -20,8 +19,6 @@ spec: app.kubernetes.io/part-of: {{ .Release.Name }} app.kubernetes.io/name: k8s-templates app.kubernetes.io/instance: k8s-templates-main - app.kubernetes.io/version: "0.2.0" - app.kubernetes.io/component: backend spec: {{- with .Values.imagePullSecrets }} imagePullSecrets: @@ -29,38 +26,36 @@ spec: {{- end }} containers: - name: backend - image: gitlab.sauerburger.com:5049/frank/k8s-templates/k8s-templates-backend:0.2.1 + image: "{{ .Values.backend.repository }}:{{ .Values.backend.tag }}" ports: - - containerPort: 8080 + - containerPort: 8080 env: - - name: DB_PASSWORD - valueFrom: + - name: "DB_PASSWORD" + valueFrom: secretKeyRef: - name: {{ .Release.Name }}-db-secret + name: "{{ .Release.Name }}-db-secret" key: password - - name: DB_USERNAME - value: {{ .Values.database.user | quote }} - - name: DB_NAME - value: {{ .Values.database.name | quote }} - - name: DB_HOST - value: {{ .Release.Name }}-database-service - - name: PRODUCTION - value: {{ .Values.backend.production | quote }} - - name: STAGING - value: {{ .Values.backend.staging | quote }} - - name: SECRET_KEY - valueFrom: + - name: DB_USERNAME + value: {{ .Values.database.user | quote }} + - name: DB_NAME + value: {{ .Values.database.name | quote }} + - name: DB_HOST + value: "{{ .Release.Name }}-database-service" + - name: PRODUCTION + value: "1" + - name: SECRET_KEY + valueFrom: secretKeyRef: - name: {{ .Release.Name }}-app-secret + name: "{{ .Release.Name }}-app-secret" key: password - - name: SUPER_EMAIL - value: {{ .Values.super.email | quote }} - - name: SUPER_USERNAME - value: {{ .Values.super.username | quote }} - - name: SUPER_PASSWORD - valueFrom: + - name: SUPER_EMAIL + value: {{ .Values.super.email | quote }} + - name: SUPER_USERNAME + value: {{ .Values.super.username | quote }} + - name: SUPER_PASSWORD + valueFrom: secretKeyRef: - name: {{ .Release.Name }}-super-secret + name: "{{ .Release.Name }}-super-secret" key: password resources: requests: @@ -84,9 +79,9 @@ spec: - mountPath: /app/webcontent/ name: static-files volumes: - - name: static-files - persistentVolumeClaim: - claimName: {{ .Release.Name }}-static-files-pvc + - name: static-files + persistentVolumeClaim: + claimName: {{ .Release.Name }}-static-files-pvc --- apiVersion: apps/v1 kind: Deployment @@ -96,8 +91,7 @@ metadata: app.kubernetes.io/part-of: {{ .Release.Name }} app.kubernetes.io/name: postgres app.kubernetes.io/instance: postgres-main - app.kubernetes.io/version: "14.0" - app.kubernetes.io/component: datbase + app.kubernetes.io/component: database spec: replicas: 1 selector: @@ -110,8 +104,7 @@ spec: app.kubernetes.io/part-of: {{ .Release.Name }} app.kubernetes.io/name: postgres app.kubernetes.io/instance: postgres-main - app.kubernetes.io/version: "14.0" - app.kubernetes.io/component: datbase + app.kubernetes.io/component: database spec: {{- with .Values.imagePullSecrets }} imagePullSecrets: @@ -168,7 +161,6 @@ metadata: app.kubernetes.io/part-of: {{ .Release.Name }} app.kubernetes.io/name: nginx app.kubernetes.io/instance: nginx-main - app.kubernetes.io/version: "1.21.5" app.kubernetes.io/component: webserver spec: replicas: 1 @@ -182,7 +174,6 @@ spec: app.kubernetes.io/part-of: {{ .Release.Name }} app.kubernetes.io/name: nginx app.kubernetes.io/instance: nginx-main - app.kubernetes.io/version: "1.21.5" app.kubernetes.io/component: backend spec: {{- with .Values.imagePullSecrets }} @@ -223,7 +214,7 @@ spec: volumes: - name: static-files persistentVolumeClaim: - claimName: {{ .Release.Name }}-static-files-pvc + claimName: "{{ .Release.Name }}-static-files-pvc" - name: config configMap: name: {{ .Release.Name }}-nginx-config diff --git a/k8s-templates/templates/ingress.yaml b/k8s-templates/templates/ingress.yaml index 2faa7465505189897e4822e143757831356eb8d2..07257f86eeb000ccbc90207dfc99e45a8e8b1a38 100644 --- a/k8s-templates/templates/ingress.yaml +++ b/k8s-templates/templates/ingress.yaml @@ -4,9 +4,9 @@ kind: Ingress metadata: annotations: {{ .Values.ingress.tlsIssuerType}}: {{ .Values.ingress.tlsIssuer | quote }} - kubernetes.io/ingress.class: nginx name: {{ .Release.Name }}-k8s-templates-ingress spec: + ingressClassName: nginx rules: - host: {{ .Values.ingress.host | quote }} http: diff --git a/k8s-templates/values.yaml b/k8s-templates/values.yaml index 70f62faed6649b698ceea07802d731e2fb2c2726..f9f19c5c41034eb5baa9434d9e8996ff72bcfbb5 100644 --- a/k8s-templates/values.yaml +++ b/k8s-templates/values.yaml @@ -1,20 +1,20 @@ ingress: - host: "" # Leave empty to disable ingress + host: "k8s.preview.sauerburger.com" # Leave empty to disable ingress tlsIssuer: "letsencrypt-production" tlsIssuerType: "cert-manager.io/cluster-issuer" super: - email: "admin@example.com" - username: "admin" + email: "frank@sauerburger.com" + username: "esel" database: user: webapp name: kubetemplates backend: - production: 1 - staging: "" replicas: 2 + repository: gitlab.sauerburger.com:5049/frank/k8s-templates + tag: 0.3.0-rc imagePullSecrets: []