Skip to content

Commit

Permalink
chore(ci): switch to deployments, catch bugs, update tests (#87)
Browse files Browse the repository at this point in the history
  • Loading branch information
DerekRoberts authored Jul 17, 2024
1 parent 45c0086 commit da34a66
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 154 deletions.
5 changes: 1 addition & 4 deletions .github/workflows/pr-open.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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
Expand Down
13 changes: 9 additions & 4 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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' )
Expand Down
63 changes: 11 additions & 52 deletions templates/backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -140,7 +100,6 @@ objects:
initialDelaySeconds: 60
periodSeconds: 30
timeoutSeconds: 5

- apiVersion: v1
kind: Service
metadata:
Expand All @@ -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:
Expand All @@ -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:
Expand Down
59 changes: 9 additions & 50 deletions templates/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand All @@ -41,7 +25,7 @@ objects:
- apiVersion: v1
kind: Secret
metadata:
name: "${NAME}-${ZONE}-${PG_DATABASE}"
name: "${NAME}-${ZONE}-${COMPONENT}"
labels:
app: "${NAME}-${ZONE}"
stringData:
Expand Down Expand Up @@ -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:
Expand All @@ -135,15 +94,15 @@ objects:
name: "${NAME}-${ZONE}-${COMPONENT}"
labels:
app: "${NAME}-${ZONE}"
deploymentconfig: "${NAME}-${ZONE}-${COMPONENT}"
deployment: "${NAME}-${ZONE}-${COMPONENT}"
spec:
volumes:
- name: "${NAME}-${ZONE}-${COMPONENT}"
persistentVolumeClaim:
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
Expand Down Expand Up @@ -209,6 +168,6 @@ objects:
protocol: TCP
targetPort: 5432
selector:
deploymentconfig: "${NAME}-${ZONE}-${COMPONENT}"
deployment: "${NAME}-${ZONE}-${COMPONENT}"
sessionAffinity: None
type: ClusterIP
49 changes: 5 additions & 44 deletions templates/frontend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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"]
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit da34a66

Please sign in to comment.