From da34a6640477baacde43263e6aa2762b214aea50 Mon Sep 17 00:00:00 2001 From: Derek Roberts Date: Tue, 16 Jul 2024 20:53:08 -0700 Subject: [PATCH] chore(ci): switch to deployments, catch bugs, update tests (#87) --- .github/workflows/pr-open.yml | 5 +-- action.yml | 13 +++++--- templates/backend.yml | 63 ++++++----------------------------- templates/database.yml | 59 +++++--------------------------- templates/frontend.yml | 49 +++------------------------ 5 files changed, 35 insertions(+), 154 deletions(-) diff --git a/.github/workflows/pr-open.yml b/.github/workflows/pr-open.yml index c9b6f74..0d13df0 100644 --- a/.github/workflows/pr-open.yml +++ b/.github/workflows/pr-open.yml @@ -22,7 +22,6 @@ jobs: - name: backend file: templates/backend.yml overwrite: true - parameters: -p MIN_REPLICAS=1 -p MAX_REPLICAS=2 verification_path: /api - name: database file: templates/database.yml @@ -31,7 +30,6 @@ jobs: file: templates/frontend.yml oc_version: 4.13 overwrite: true - parameters: -p MIN_REPLICAS=1 -p MAX_REPLICAS=2 post_rollout: | oc create job "frontend-$(date +%s)" --from=cronjob/${{ github.event.repository.name }}-${{ github.event.number }}-cronjob steps: @@ -45,8 +43,7 @@ jobs: oc_token: ${{ secrets.OC_TOKEN }} oc_version: ${{ matrix.oc_version }} overwrite: ${{ matrix.overwrite }} - parameters: -p ZONE=${{ github.event.number }} -p NAME=${{ github.event.repository.name }} - ${{ matrix.parameters }} + parameters: -p ZONE=${{ github.event.number }} ${{ matrix.parameters }} post_rollout: ${{ matrix.post_rollout }} verification_path: ${{ matrix.verification_path }} - id: trigger diff --git a/action.yml b/action.yml index 536565a..d9671e3 100644 --- a/action.yml +++ b/action.yml @@ -162,7 +162,7 @@ runs: oc login --token=${{ inputs.oc_token }} --server=${{ inputs.oc_server }} oc project ${{ inputs.oc_namespace }} #Safeguard! - # Clean previous image, if any + # Clean any previous ImageStreams IFS=" " read -ra IS <<< "${{ steps.vars.outputs.imageStream }}" for i in "${IS[@]}" do @@ -178,10 +178,15 @@ runs: oc create -f - 2>&1 <<< "${TEMPLATE}" | sed 's/.*: //' fi - # Follow any active rollouts + # Follow any active rollouts; temporary support for DeploymentConfigs DDC=${{ steps.vars.outputs.deployment }} - [ -z "${DDC}" ]|| oc rollout status deployment/${DDC} -w || oc rollout status dc/${DDC} -w - + if [ ! -z "${DDC}" ]&&[ ! -z $(oc get deployment ${DDC} -o name --ignore-not-found) ]; then + # oc rollout restart deployment/${DDC} + oc rollout status deployment/${DDC} -w + elif [ ! -z "${DDC}" ]&&[ ! -z $(oc get deploymentconfig ${DDC} -o name --ignore-not-found) ]; then + oc rollout status deploymentconfig/${DDC} -w + fi + - name: Route Verification if: steps.vars.outputs.url && ( steps.diff.outputs.triggered == 'true' ) diff --git a/templates/backend.yml b/templates/backend.yml index 03728eb..26fe39a 100644 --- a/templates/backend.yml +++ b/templates/backend.yml @@ -3,22 +3,13 @@ kind: Template parameters: - name: NAME description: Module name - required: true + value: action-deployer-openshift - name: COMPONENT description: Component name value: backend - name: ZONE description: Deployment zone, e.g. pr-### or prod required: true - - name: REGISTRY - description: Container registry to import from (internal is image-registry.openshift-image-registry.svc:5000) - value: ghcr.io - - name: PROMOTE - description: Image to promote - value: ghcr.io/bcgov/quickstart-openshift/backend:latest - - name: IMAGE_TAG - description: Image tag to use - value: latest - name: DOMAIN value: apps.silver.devops.gov.bc.ca - name: CPU_REQUEST @@ -37,59 +28,28 @@ parameters: value: "250m" - name: MEMORY_LIMIT_INIT value: "250Mi" - - name: MIN_REPLICAS - description: The minimum amount of replicas for the horizontal pod autoscaler. - value: "3" - - name: MAX_REPLICAS - description: The maximum amount of replicas for the horizontal pod autoscaler. - value: "5" objects: - - apiVersion: v1 - kind: ImageStream - metadata: - labels: - app: "${NAME}-${ZONE}" - name: "${NAME}-${ZONE}-${COMPONENT}" - spec: - lookupPolicy: - local: false - tags: - - name: "${IMAGE_TAG}" - from: - kind: DockerImage - name: "${PROMOTE}" - referencePolicy: - type: Local - - apiVersion: v1 - kind: DeploymentConfig + - kind: Deployment + apiVersion: apps/v1 metadata: labels: app: "${NAME}-${ZONE}" name: "${NAME}-${ZONE}-${COMPONENT}" spec: replicas: 1 - triggers: - - type: ConfigChange - - type: ImageChange - imageChangeParams: - automatic: true - containerNames: - - "${NAME}" - from: - kind: ImageStreamTag - name: "${NAME}-${ZONE}-${COMPONENT}:${IMAGE_TAG}" selector: - deploymentconfig: "${NAME}-${ZONE}-${COMPONENT}" + matchLabels: + deployment: "${NAME}-${ZONE}-${COMPONENT}" strategy: - type: Rolling + type: RollingUpdate template: metadata: labels: app: "${NAME}-${ZONE}" - deploymentconfig: "${NAME}-${ZONE}-${COMPONENT}" + deployment: "${NAME}-${ZONE}-${COMPONENT}" spec: containers: - - image: "${NAME}-${ZONE}-${COMPONENT}:${IMAGE_TAG}" + - image: "ghcr.io/bcgov/quickstart-openshift/backend:latest" imagePullPolicy: Always name: "${NAME}" env: @@ -140,7 +100,6 @@ objects: initialDelaySeconds: 60 periodSeconds: 30 timeoutSeconds: 5 - - apiVersion: v1 kind: Service metadata: @@ -154,7 +113,7 @@ objects: port: 80 targetPort: 3000 selector: - deploymentconfig: "${NAME}-${ZONE}-${COMPONENT}" + deployment: "${NAME}-${ZONE}-${COMPONENT}" - apiVersion: route.openshift.io/v1 kind: Route metadata: @@ -181,8 +140,8 @@ objects: apiVersion: apps.openshift.io/v1 kind: DeploymentConfig name: "${NAME}-${ZONE}-${COMPONENT}" - minReplicas: "${{MIN_REPLICAS}}" - maxReplicas: "${{MAX_REPLICAS}}" + minReplicas: 1 + maxReplicas: 2 metrics: - type: Resource resource: diff --git a/templates/database.yml b/templates/database.yml index 925037c..aa719d4 100644 --- a/templates/database.yml +++ b/templates/database.yml @@ -3,36 +3,20 @@ kind: Template parameters: - name: NAME description: Module name - required: true + value: action-deployer-openshift - name: COMPONENT description: Component name value: database - name: ZONE description: Deployment zone, e.g. pr-### or prod required: true - - name: REGISTRY - description: Container registry to import from (internal is image-registry.openshift-image-registry.svc:5000) - value: ghcr.io - - name: PROMOTE - description: Image to promote - value: ghcr.io/bcgov/nr-containers/postgres:15.5 - - name: IMAGE_TAG - description: Image tag to use - value: latest - name: PVC_MOUNT_PATH description: Where to mount the PVC, subpath (e.g. data/) value: /var/lib/postgresql - name: DB_PVC_SIZE description: Volume space available for data, e.g. 512Mi, 2Gi. - displayName: Database Volume Capacity required: true value: 256Mi - - name: REGISTRY - description: Container registry to import from (internal is image-registry.openshift-image-registry.svc:5000) - value: ghcr.io - - name: PG_DATABASE - description: Postgres database name - value: database - name: DB_PASSWORD description: Password for the PostgreSQL connection user. from: "[a-zA-Z0-9]{16}" @@ -41,7 +25,7 @@ objects: - apiVersion: v1 kind: Secret metadata: - name: "${NAME}-${ZONE}-${PG_DATABASE}" + name: "${NAME}-${ZONE}-${COMPONENT}" labels: app: "${NAME}-${ZONE}" stringData: @@ -89,42 +73,17 @@ objects: requests: storage: "${DB_PVC_SIZE}" storageClassName: netapp-file-standard - - kind: ImageStream - apiVersion: v1 - metadata: - name: "${NAME}-${ZONE}-${COMPONENT}" - labels: - app: "${NAME}-${ZONE}" - spec: - lookupPolicy: - local: false - tags: - - name: "${IMAGE_TAG}" - from: - kind: DockerImage - name: "${PROMOTE}" - referencePolicy: - type: Local - - kind: DeploymentConfig - apiVersion: v1 + - kind: Deployment + apiVersion: apps/v1 metadata: name: "${NAME}-${ZONE}-${COMPONENT}" labels: app: "${NAME}-${ZONE}" spec: replicas: 1 - triggers: - - type: ConfigChange - - type: ImageChange - imageChangeParams: - automatic: true - containerNames: - - "${NAME}" - from: - kind: ImageStreamTag - name: "${NAME}-${ZONE}-${COMPONENT}:${IMAGE_TAG}" selector: - deploymentconfig: "${NAME}-${ZONE}-${COMPONENT}" + matchLabels: + deployment: "${NAME}-${ZONE}-${COMPONENT}" strategy: type: Recreate recreateParams: @@ -135,7 +94,7 @@ objects: name: "${NAME}-${ZONE}-${COMPONENT}" labels: app: "${NAME}-${ZONE}" - deploymentconfig: "${NAME}-${ZONE}-${COMPONENT}" + deployment: "${NAME}-${ZONE}-${COMPONENT}" spec: volumes: - name: "${NAME}-${ZONE}-${COMPONENT}" @@ -143,7 +102,7 @@ objects: claimName: "${NAME}-${ZONE}-${COMPONENT}" containers: - name: "${NAME}" - image: "${NAME}-${ZONE}-${COMPONENT}:${IMAGE_TAG}" + image: ghcr.io/bcgov/nr-containers/postgres:12.19 ports: - containerPort: 5432 protocol: TCP @@ -209,6 +168,6 @@ objects: protocol: TCP targetPort: 5432 selector: - deploymentconfig: "${NAME}-${ZONE}-${COMPONENT}" + deployment: "${NAME}-${ZONE}-${COMPONENT}" sessionAffinity: None type: ClusterIP diff --git a/templates/frontend.yml b/templates/frontend.yml index 1e45319..a2dfad6 100644 --- a/templates/frontend.yml +++ b/templates/frontend.yml @@ -3,22 +3,13 @@ kind: Template parameters: - name: NAME description: Module name - required: true + value: action-deployer-openshift - name: COMPONENT description: Component name value: frontend - name: ZONE description: Deployment zone, e.g. pr-### or prod required: true - - name: REGISTRY - description: Container registry to import from (internal is image-registry.openshift-image-registry.svc:5000) - value: ghcr.io - - name: PROMOTE - description: Image to promote - value: ghcr.io/bcgov/quickstart-openshift/frontend:latest - - name: IMAGE_TAG - description: Image tag to use - value: latest - name: DOMAIN value: apps.silver.devops.gov.bc.ca - name: CPU_REQUEST @@ -29,12 +20,6 @@ parameters: value: "75m" - name: MEMORY_LIMIT value: "150Mi" - - name: MIN_REPLICAS - description: The minimum amount of replicas for the horizontal pod autoscaler. - value: "3" - - name: MAX_REPLICAS - description: The maximum amount of replicas for the horizontal pod autoscaler. - value: "5" - name: LOG_LEVEL description: Caddy logging level DEBUG, INFO, WARN, ERROR, PANIC, and FATAL (https://github.com/caddyserver/caddy/blob/master/logging.go) value: "info" @@ -43,22 +28,6 @@ parameters: from: "[0-5]{1}[0-9]{1}" generate: expression objects: - - apiVersion: v1 - kind: ImageStream - metadata: - labels: - app: "${NAME}-${ZONE}" - name: "${NAME}-${ZONE}-${COMPONENT}" - spec: - lookupPolicy: - local: false - tags: - - name: "${IMAGE_TAG}" - from: - kind: DockerImage - name: "${PROMOTE}" - referencePolicy: - type: Local - apiVersion: v1 kind: DeploymentConfig metadata: @@ -69,14 +38,6 @@ objects: replicas: 1 triggers: - type: ConfigChange - - type: ImageChange - imageChangeParams: - automatic: true - containerNames: - - "${NAME}" - from: - kind: ImageStreamTag - name: "${NAME}-${ZONE}-${COMPONENT}:${IMAGE_TAG}" selector: deploymentconfig: "${NAME}-${ZONE}-${COMPONENT}" strategy: @@ -88,7 +49,7 @@ objects: deploymentconfig: "${NAME}-${ZONE}-${COMPONENT}" spec: containers: - - image: "${NAME}-${ZONE}-${COMPONENT}:${IMAGE_TAG}" + - image: "ghcr.io/bcgov/quickstart-openshift/frontend:latest" securityContext: capabilities: add: ["NET_BIND_SERVICE"] @@ -169,8 +130,8 @@ objects: apiVersion: apps.openshift.io/v1 kind: DeploymentConfig name: "${NAME}-${ZONE}-${COMPONENT}" - minReplicas: "${{MIN_REPLICAS}}" - maxReplicas: "${{MAX_REPLICAS}}" + minReplicas: 1 + maxReplicas: 2 metrics: - type: Resource resource: @@ -198,7 +159,7 @@ objects: restartPolicy: OnFailure containers: - name: ${NAME}-${ZONE}-cronjob - image: "${NAME}-${ZONE}-${COMPONENT}:${IMAGE_TAG}" + image: "ghcr.io/bcgov/quickstart-openshift/frontend:latest" imagePullPolicy: Always args: ["bash -c 'whoami'"] resources: