diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4aa74df..6c33d0d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,6 +18,7 @@ concurrency: env: IMAGE: ghcr.io/textyly/crossly-ui + MANIFESTS: ghcr.io/textyly/crossly-ui-manifests jobs: test: @@ -77,6 +78,16 @@ jobs: test "$(docker exec smoke id -u)" != 0 docker rm -f smoke + - name: Check that the manifests render + run: kubectl kustomize deploy/k8s > /dev/null + + - uses: fluxcd/flux2/action@3fa784edd773d56630bb9f62645e08f70c2cff0a # v2.10.0 + with: + version: 2.10.0 + + - name: Check that the manifests package + run: flux build artifact --path deploy/k8s --output "$RUNNER_TEMP/manifests.tgz" + - name: Log in to the container registry if: github.event_name == 'push' uses: docker/login-action@81c6f93d4bc991e510b342a00b419b3bb4efc5c6 # v4.7.0 @@ -100,6 +111,16 @@ jobs: org.opencontainers.image.licenses=Apache-2.0 cache-from: type=gha + - name: Publish the manifests with the new image tag + if: github.event_name == 'push' + env: + TAG: ${{ steps.meta.outputs.tag }} + run: | + sed -i "s|newTag: .*|newTag: ${TAG}|" deploy/k8s/kustomization.yaml + grep -q "newTag: ${TAG}" deploy/k8s/kustomization.yaml + flux push artifact "oci://${MANIFESTS}:${TAG}" --path=deploy/k8s --source="${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}" --revision="${GITHUB_REF_NAME}@sha1:${GITHUB_SHA}" + flux tag artifact "oci://${MANIFESTS}:${TAG}" --tag main + - name: Summary if: github.event_name == 'push' - run: echo "Published \`${IMAGE}:${{ steps.meta.outputs.tag }}\`" >> "$GITHUB_STEP_SUMMARY" + run: echo "Published \`${IMAGE}:${{ steps.meta.outputs.tag }}\` and \`${MANIFESTS}:${{ steps.meta.outputs.tag }}\`" >> "$GITHUB_STEP_SUMMARY" diff --git a/deploy/k8s/kustomization.yaml b/deploy/k8s/kustomization.yaml new file mode 100644 index 0000000..15e9426 --- /dev/null +++ b/deploy/k8s/kustomization.yaml @@ -0,0 +1,13 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization + +namespace: crossly + +resources: + - ui-deployment.yaml + - ui-service.yaml + - ui-ingress.yaml + +images: + - name: ghcr.io/textyly/crossly-ui + newTag: main-8064a8b-1793537585 diff --git a/deploy/k8s/ui-deployment.yaml b/deploy/k8s/ui-deployment.yaml new file mode 100644 index 0000000..02f7706 --- /dev/null +++ b/deploy/k8s/ui-deployment.yaml @@ -0,0 +1,76 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: crossly-ui + labels: + app.kubernetes.io/name: crossly-ui + app.kubernetes.io/component: ui + app.kubernetes.io/part-of: crossly +spec: + replicas: 2 + selector: + matchLabels: + app.kubernetes.io/name: crossly-ui + template: + metadata: + labels: + app.kubernetes.io/name: crossly-ui + app.kubernetes.io/component: ui + app.kubernetes.io/part-of: crossly + spec: + automountServiceAccountToken: false + securityContext: + runAsNonRoot: true + runAsUser: 101 + runAsGroup: 101 + seccompProfile: + type: RuntimeDefault + affinity: + podAntiAffinity: + preferredDuringSchedulingIgnoredDuringExecution: + - weight: 100 + podAffinityTerm: + topologyKey: kubernetes.io/hostname + labelSelector: + matchLabels: + app.kubernetes.io/name: crossly-ui + containers: + - name: ui + # tag comes from the images entry in kustomization.yaml + image: ghcr.io/textyly/crossly-ui + ports: + - name: http + containerPort: 8080 + securityContext: + allowPrivilegeEscalation: false + readOnlyRootFilesystem: true + capabilities: + drop: [ALL] + readinessProbe: + httpGet: + path: / + port: http + initialDelaySeconds: 2 + periodSeconds: 5 + timeoutSeconds: 2 + livenessProbe: + httpGet: + path: / + port: http + initialDelaySeconds: 5 + periodSeconds: 20 + timeoutSeconds: 2 + resources: + requests: + cpu: 10m + memory: 16Mi + limits: + cpu: 200m + memory: 64Mi + volumeMounts: + - name: tmp + mountPath: /tmp + volumes: + - name: tmp + emptyDir: + sizeLimit: 16Mi diff --git a/deploy/k8s/ui-ingress.yaml b/deploy/k8s/ui-ingress.yaml new file mode 100644 index 0000000..9847d0a --- /dev/null +++ b/deploy/k8s/ui-ingress.yaml @@ -0,0 +1,19 @@ +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: crossly + labels: + app.kubernetes.io/name: crossly + app.kubernetes.io/part-of: crossly +spec: + rules: + - host: crossly.localhost + http: + paths: + - path: / + pathType: Prefix + backend: + service: + name: crossly-ui + port: + name: http diff --git a/deploy/k8s/ui-service.yaml b/deploy/k8s/ui-service.yaml new file mode 100644 index 0000000..d6adcdb --- /dev/null +++ b/deploy/k8s/ui-service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: crossly-ui + labels: + app.kubernetes.io/name: crossly-ui + app.kubernetes.io/component: ui + app.kubernetes.io/part-of: crossly +spec: + selector: + app.kubernetes.io/name: crossly-ui + ports: + - name: http + port: 80 + targetPort: http