From bdd23a9610ec37c99c8e1002b415a7f171b97189 Mon Sep 17 00:00:00 2001 From: Fergus MacConnell Date: Wed, 4 Sep 2024 16:18:43 -0700 Subject: [PATCH] chore(ci): Add OpenShift deploy template. (#47) --- .github/workflows/.deploy.yml | 37 +++++++++++ .github/workflows/pr-open.yml | 8 ++- frontend/openshift.deploy.yml | 113 ++++++++++++++++++++++++++++++++++ 3 files changed, 157 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/.deploy.yml create mode 100644 frontend/openshift.deploy.yml diff --git a/.github/workflows/.deploy.yml b/.github/workflows/.deploy.yml new file mode 100644 index 000000000..4d713259f --- /dev/null +++ b/.github/workflows/.deploy.yml @@ -0,0 +1,37 @@ +name: .Deploys + +on: + workflow_call: + inputs: + environment: + description: GitHub environment; e.g. PR number (omit), TEST or PROD + required: false + type: string + tag: + description: Image tag; e.g. PR number or latest + default: ${{ github.event.number }} + required: false + type: string + target: + description: Deployment target; e.g. PR number (omit), test or prod + default: ${{ github.event.number }} + required: false + type: string + +jobs: + frontend: + name: Frontend + # needs: [backend] + environment: ${{ inputs.environment }} + runs-on: ubuntu-22.04 + steps: + - name: Deploy Frontend + uses: bcgov-nr/action-deployer-openshift@v3.0.0 + with: + oc_namespace: ${{ vars.OC_NAMESPACE }} + oc_server: ${{ vars.OC_SERVER }} + oc_token: ${{ secrets.OC_TOKEN }} + file: frontend/openshift.deploy.yml + overwrite: true + parameters: + -p TAG=${{ inputs.tag }} -p TARGET=${{ inputs.target }} \ No newline at end of file diff --git a/.github/workflows/pr-open.yml b/.github/workflows/pr-open.yml index 2ee248dc1..6f745f632 100644 --- a/.github/workflows/pr-open.yml +++ b/.github/workflows/pr-open.yml @@ -35,10 +35,16 @@ jobs: # oc_namespace: ${{ secrets.OC_NAMESPACE }} # oc_token: ${{ secrets.OC_TOKEN }} # with: - # triggers: ('backend/' 'frontend/' 'migrations/') + # triggers: ('frontend/') # params: # --set global.secrets.persist=false + deploy: + name: Deploy + needs: [builds] + secrets: inherit + uses: ./.github/workflows/.deploy.yml + # tests: # name: Tests # if: needs.deploys.outputs.triggered == 'true' diff --git a/frontend/openshift.deploy.yml b/frontend/openshift.deploy.yml new file mode 100644 index 000000000..200f70da3 --- /dev/null +++ b/frontend/openshift.deploy.yml @@ -0,0 +1,113 @@ +apiVersion: template.openshift.io/v1 +kind: Template +parameters: + - name: APP + description: Application name + value: nr-gwells + - name: COMPONENT + description: Component name + value: frontend + - name: ORG + description: Organization name; e.g. bcgov or bcdevops + value: bcgov + - name: TAG + description: Image tag; e.g. PR number or latest + required: true + - name: TARGET + description: Deployment target; e.g. PR number, test or prod + required: true +objects: + - kind: Service + apiVersion: v1 + metadata: + labels: + app: ${APP}-${TARGET} + name: ${APP}-${TARGET}-${COMPONENT} + spec: + type: ClusterIP + ports: + - port: 80 + targetPort: 5173 + protocol: TCP + name: http-5173 + selector: + service: ${APP}-${TARGET}-${COMPONENT} + - kind: Deployment + apiVersion: apps/v1 + metadata: + labels: + app: ${APP}-${TARGET} + deployment: ${APP}-${TARGET}-${COMPONENT} + name: ${APP}-${TARGET}-${COMPONENT} + spec: + strategy: + type: Recreate + selector: + matchLabels: + deployment: ${APP}-${TARGET}-${COMPONENT} + template: + metadata: + labels: + app: ${APP}-${TARGET} + deployment: ${APP}-${TARGET}-${COMPONENT} + service: ${APP}-${TARGET}-${COMPONENT} + spec: + containers: + - name: ${APP}-${TARGET}-${COMPONENT} + image: ghcr.io/${ORG}/${APP}/${COMPONENT}:${TAG} + # securityContext: + # runAsUser: 1011540000 + imagePullPolicy: Always + env: + - name: LOG_LEVEL + value: info + - name: VUE_APP_AXIOS_BASE_URL + value: http://${APP}-${TARGET}/gwells/api/v2/ + ports: + - name: http + containerPort: 5173 + protocol: TCP + readinessProbe: + httpGet: + path: / + port: http + scheme: HTTP + initialDelaySeconds: 90 + periodSeconds: 10 + timeoutSeconds: 10 + successThreshold: 3 + failureThreshold: 30 + livenessProbe: + successThreshold: 1 + failureThreshold: 3 + httpGet: + path: / + port: http + scheme: HTTP + initialDelaySeconds: 15 + periodSeconds: 30 + timeoutSeconds: 5 + resources: # this is optional + limits: + cpu: 150m + memory: 250Mi + requests: + cpu: 50m + memory: 175Mi + - kind: Route + apiVersion: route.openshift.io/v1 + metadata: + labels: + app: ${APP}-${TARGET} + name: ${APP}-${TARGET}-${COMPONENT} + spec: + host: nr-gwells-${TARGET}.apps.silver.devops.gov.bc.ca + port: + targetPort: http-5173 + to: + kind: Service + name: ${APP}-${TARGET}-${COMPONENT} + weight: 100 + tls: + termination: edge + insecureEdgeTerminationPolicy: Redirect \ No newline at end of file