Skip to content

Commit

Permalink
feat(ci): use cronjob (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
DerekRoberts authored Mar 25, 2024
1 parent b7407bd commit 7532dc1
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 105 deletions.
9 changes: 7 additions & 2 deletions .github/workflows/pr-open.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ jobs:

deploys:
name: Deploys
env:
JOB: ${{ github.event.repository.name }}-${{ github.event.number }}-sync
needs: [builds]
runs-on: ubuntu-latest
steps:
Expand All @@ -39,8 +41,11 @@ jobs:
oc_server: ${{ vars.OC_SERVER }}
oc_token: ${{ secrets.OC_TOKEN }}
overwrite: true
parameters:
-p ZONE=${{ github.event.number }} -p PROMOTE=bcgov/nr-spar-data/sync:${{ github.event.number }}
parameters: -p ZONE=${{ github.event.number }} -p TAG=${{ github.event.number }}
post_rollout:
oc create job ${{ env.JOB }}-${{ github.run_number }} --from=cronjob/${{ env.JOB }} && \
sleep 10 && \
oc logs -l job-name=${{ env.JOB }}-${{ github.run_number }} --tail=50 --follow
triggers: ('sync/')

results:
Expand Down
176 changes: 73 additions & 103 deletions sync/openshift.deploy.yml
Original file line number Diff line number Diff line change
@@ -1,117 +1,87 @@
apiVersion: template.openshift.io/v1
kind: Template
parameters:
- name: NAME
description: Module name
value: nr-spar-data
- name: COMPONENT
description: Component name
value: sync
### Required - do not hard code
- name: TAG
description: Docker tag; e.g. PR-### or prod
required: true
- name: ZONE
description: Deployment zone, e.g. pr-### or prod
description: Deployment zone, e.g. pr-###, test or prod
required: true
- name: IMAGE_TAG
description: Image tag to use
value: latest
- name: CPU_REQUEST
value: "25m"
- name: MEMORY_REQUEST
value: "50Mi"
- name: CPU_LIMIT
value: "75m"
- name: MEMORY_LIMIT
value: "150Mi"
- name: MIN_REPLICAS
description: The minimum amount of replicas for the horizontal pod autoscaler.
value: "1"
- name: MAX_REPLICAS
description: The maximum amount of replicas for the horizontal pod autoscaler.
value: "1"

### Recommended - suggest hard coding
- name: APP
description: Application/component name
value: sync
- name: ORG
description: GitHub organization name
value: bcgov
- name: REPO
description: Repository name
value: nr-spar-data

### Usually a bad idea - not recommended
- name: CRON_MINUTES
description: Random number, 0-60, for scheduling cronjobs
from: "[0-5]{1}[0-9]{1}"
generate: expression
- name: JOB_BACKOFF_LIMIT
description: "The number of attempts to try for a successful job outcome"
value: "3"
- name: JOB_HISTORY_FAIL
description: "The number of failed jobs that will be retained"
value: "2"
- name: JOB_HISTORY_SUCCESS
description: "The number of successful jobs that will be retained"
value: "5"
- name: REGISTRY
description: Container registry to import from (internal is image-registry.openshift-image-registry.svc:5000)
description: Source container registry
value: ghcr.io
- name: PROMOTE
description: Image (namespace/name:tag) to promote/import
value: bcgov/nr-spar-data/sync:test
objects:
- apiVersion: v1
kind: ImageStream
- kind: CronJob
apiVersion: "batch/v1"
metadata:
name: ${REPO}-${ZONE}-${APP}
labels:
app: "${NAME}-${ZONE}"
name: "${NAME}-${ZONE}-${COMPONENT}"
app: ${REPO}-${ZONE}
cronjob: ${REPO}-${ZONE}
spec:
lookupPolicy:
local: false
tags:
- name: "${IMAGE_TAG}"
from:
kind: DockerImage
name: "${REGISTRY}/${PROMOTE}"
referencePolicy:
type: Local
- apiVersion: v1
kind: DeploymentConfig
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}"
strategy:
type: Rolling
template:
schedule: "${CRON_MINUTES} 8 * * *" # Run daily at 8:xx AM UTC
startingDeadlineSeconds: 60
concurrencyPolicy: "Replace"
successfulJobsHistoryLimit: "${{JOB_HISTORY_SUCCESS}}"
failedJobsHistoryLimit: "${{JOB_HISTORY_FAIL}}"
jobTemplate:
metadata:
labels:
app: "${NAME}-${ZONE}"
deploymentconfig: "${NAME}-${ZONE}-${COMPONENT}"
app: ${REPO}-${ZONE}
cronjob: ${REPO}-${ZONE}
spec:
containers:
- image: "${NAME}-${ZONE}-${COMPONENT}:${IMAGE_TAG}"
imagePullPolicy: Always
name: "${NAME}"
env:
- name: PYTHONPATH
value: /app/src
ports:
- containerPort: 3000
protocol: TCP
resources:
requests:
cpu: "${CPU_REQUEST}"
memory: "${MEMORY_REQUEST}"
limits:
cpu: "${CPU_LIMIT}"
memory: "${MEMORY_LIMIT}"
- apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
labels:
app: "${NAME}-${ZONE}"
name: "${NAME}-${ZONE}-${COMPONENT}"
spec:
scaleTargetRef:
apiVersion: apps.openshift.io/v1
kind: DeploymentConfig
name: "${NAME}-${ZONE}-${COMPONENT}"
minReplicas: "${{MIN_REPLICAS}}"
maxReplicas: "${{MAX_REPLICAS}}"
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 100
backoffLimit: ${{JOB_BACKOFF_LIMIT}}
template:
metadata:
labels:
app: ${REPO}-${ZONE}
cronjob: ${REPO}-${ZONE}
spec:
containers:
- name: ${REPO}-${ZONE}
image: "${REGISTRY}/${ORG}/${REPO}/${APP}:${TAG}"
# env:
# - name: POSTGRES_SERVICE
# value: "${REPO}-${ZONE}-database"
resources:
limits:
cpu: 250m
requests:
cpu: 50m
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
imagePullPolicy: Always
restartPolicy: Never
terminationGracePeriodSeconds: 30
activeDeadlineSeconds: 1600
dnsPolicy: ClusterFirst
serviceAccountName: pipeline
schedulerName: default-scheduler

0 comments on commit 7532dc1

Please sign in to comment.