From fe9d4a1f116126ede2285eab53bdda9b31323cf4 Mon Sep 17 00:00:00 2001 From: timwekkenbc Date: Mon, 6 May 2024 11:32:35 -0700 Subject: [PATCH] Added github actions and helm chart for testing and deploying app to openshift --- .github/workflows/build-and-deploy.yml | 68 ++++++++++++++++++++++++++ .github/workflows/test.yml | 28 +++++++++++ helm/Chart.yaml | 4 ++ helm/templates/deployment.yaml | 37 ++++++++++++++ helm/templates/service.yaml | 13 +++++ 5 files changed, 150 insertions(+) create mode 100644 .github/workflows/build-and-deploy.yml create mode 100644 .github/workflows/test.yml create mode 100644 helm/Chart.yaml create mode 100644 helm/templates/deployment.yaml create mode 100644 helm/templates/service.yaml diff --git a/.github/workflows/build-and-deploy.yml b/.github/workflows/build-and-deploy.yml new file mode 100644 index 0000000..623dc9f --- /dev/null +++ b/.github/workflows/build-and-deploy.yml @@ -0,0 +1,68 @@ +name: Build and Deploy + +on: + push: + branches: + - main + - dev + - pipeline + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + build_image: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Login to Container Registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + + - name: Build and push + uses: docker/build-push-action@v5 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + env: + NEXT_PUBLIC_API_URL: "https://brms-api-eb0f74-prod.apps.silver.devops.gov.bc.ca/api" + NEXT_PUBLIC_GO_RULES_PROJECT_ID: "5b3cafaf-0159-48a6-b5aa-d52126c127c5" + NEXT_PUBLIC_GO_RULES_BEARER_PAT: "grl_pat_1k5I78MNm3wLbR8Ey4gpU_sMWW9NElR6jBQxvip1H5OsMKBV" + NEXT_PUBLIC_GO_RULES_ACCESS_TOKEN: "UAXwXrYJchvr8LrdXaugYJmA" + + outputs: + image_tag: ${{ steps.meta.outputs.tags }} + + deploy: + needs: build_image + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Authenticate and set context for OpenShift + uses: redhat-actions/oc-login@v1 + + with: + openshift_server_url: ${{ secrets.OPENSHIFT_SERVER }} + namespace: ${{ github.ref == 'refs/heads/main' && secrets.OPENSHIFT_PROD_NAMESPACE || secrets.OPENSHIFT_DEV_NAMESPACE }} + openshift_token: ${{ github.ref == 'refs/heads/main' && secrets.OPENSHIFT_PROD_TOKEN || secrets.OPENSHIFT_DEV_TOKEN }} + insecure_skip_tls_verify: true + + - name: Run Helm + run: | + helm upgrade --install brms-frontend ./helm --set image.tag=${{ needs.build_image.outputs.image_tag }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..2818935 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,28 @@ +name: Test + +on: + push: + branches: + - '*' + pull_request: + branches: + - '*' + +jobs: + test: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Install dependencies + run: npm install + + - name: Run Jest tests with coverage + run: npm test -- --coverage + + - name: Upload coverage report + uses: actions/upload-artifact@v4 + with: + name: coverage + path: coverage diff --git a/helm/Chart.yaml b/helm/Chart.yaml new file mode 100644 index 0000000..3ae3ad5 --- /dev/null +++ b/helm/Chart.yaml @@ -0,0 +1,4 @@ +apiVersion: v2 +name: brms-frontend +description: A Helm chart for deploying brms-frontend +version: 0.1.0 diff --git a/helm/templates/deployment.yaml b/helm/templates/deployment.yaml new file mode 100644 index 0000000..a18ee8c --- /dev/null +++ b/helm/templates/deployment.yaml @@ -0,0 +1,37 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: brms-frontend + labels: + app.kubernetes.io/name: brms-frontend +spec: + replicas: {{ .Values.replicaCount }} + selector: + matchLabels: + app.kubernetes.io/name: brms-frontend + template: + metadata: + labels: + app.kubernetes.io/name: brms-frontend + spec: + containers: + - name: brms-frontend + image: '{{ .Values.image.tag }}' + ports: + - containerPort: 8080 + resources: {} + terminationMessagePath: /dev/termination-log + terminationMessagePolicy: File + imagePullPolicy: Always + restartPolicy: Always + terminationGracePeriodSeconds: 30 + dnsPolicy: ClusterFirst + securityContext: {} + schedulerName: default-scheduler + strategy: + type: RollingUpdate + rollingUpdate: + maxUnavailable: 25% + maxSurge: 25% + revisionHistoryLimit: 10 + progressDeadlineSeconds: 600 diff --git a/helm/templates/service.yaml b/helm/templates/service.yaml new file mode 100644 index 0000000..48b4dd4 --- /dev/null +++ b/helm/templates/service.yaml @@ -0,0 +1,13 @@ +apiVersion: v1 +kind: Service +metadata: + name: brms-frontend + labels: + app.kubernetes.io/name: brms-frontend +spec: + selector: + app.kubernetes.io/name: brms-frontend + ports: + - protocol: TCP + port: 8080 + targetPort: 8080 \ No newline at end of file