Skip to content
This repository has been archived by the owner on May 3, 2023. It is now read-only.

Commit

Permalink
Fix/merge main flow (#20)
Browse files Browse the repository at this point in the history
* fix: ci workflows for pr close and merge main

* fix: new job names

* fix: remove database deployment for now

* fix: wrong yaml syntax

* fix: adjust if condition to run on pull requests

* ci: fix codeql into pull requests flow

* fix: removed database deploy config files

* fix: enable codeql to run in every commit
  • Loading branch information
Ricardo Campos authored Aug 25, 2022
1 parent d261fac commit 697e04c
Show file tree
Hide file tree
Showing 7 changed files with 322 additions and 125 deletions.
159 changes: 159 additions & 0 deletions .github/openshift/deploy.backend-with-database.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
apiVersion: template.openshift.io/v1
kind: Template
metadata:
name: ${NAME}
annotations:
description: "NR Backend Starting API"
tags: "nrbestapi"
iconClass: icon-java
labels:
app: ${NAME}-${ZONE}
app.kubernetes.io/part-of: ${NAME}-${ZONE}
parameters:
- name: NAME
description: Module name
value: nrbestapi
- name: COMPONENT
description: Component name
value: service-api
- name: ZONE
description: Deployment zone, e.g. pr-### or prod
required: true
- name: IMAGE_TAG
description: Image tag to use
value: latest
- name: DOMAIN
value: apps.silver.devops.gov.bc.ca
- name: CPU_REQUEST
value: 100m
- name: MEMORY_REQUEST
value: 0.5Gi
- name: REGISTRY
description: Container registry to import from (internal is image-registry.openshift-image-registry.svc:5000)
value: ghcr.io
- name: PROMOTE
description: Image (namespace/name:tag) to promote/import
value: bcgov/nr-backend-starting-api:prod-service-api
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: ${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:
metadata:
labels:
app: ${NAME}-${ZONE}
deploymentconfig: ${NAME}-${ZONE}-${COMPONENT}
spec:
containers:
- image: ${NAME}-${ZONE}-${COMPONENT}:${IMAGE_TAG}
imagePullPolicy: Always
name: ${NAME}
env:
- name: POSTGRESQL_HOST
value: ${NAME}-${ZONE}-database
- name: POSTGRESQL_DATABASE
valueFrom:
secretKeyRef:
name: ${NAME}-${ZONE}-database
key: database-name
- name: POSTGRESQL_PASSWORD
valueFrom:
secretKeyRef:
name: ${NAME}-${ZONE}-database
key: database-password
- name: POSTGRESQL_USER
valueFrom:
secretKeyRef:
name: ${NAME}-${ZONE}-database
key: database-user
ports:
- containerPort: 8090
protocol: TCP
resources:
requests:
cpu: ${CPU_REQUEST}
memory: ${MEMORY_REQUEST}
readinessProbe:
httpGet:
path: /check
port: 8090
scheme: HTTP
initialDelaySeconds: 120
periodSeconds: 15
timeoutSeconds: 10
livenessProbe:
successThreshold: 1
failureThreshold: 3
httpGet:
path: /check
port: 8090
scheme: HTTP
initialDelaySeconds: 120
periodSeconds: 30
timeoutSeconds: 10
- apiVersion: v1
kind: Service
metadata:
labels:
app: ${NAME}-${ZONE}
name: ${NAME}-${ZONE}-${COMPONENT}
spec:
ports:
- name: 8090-tcp
protocol: TCP
port: 80
targetPort: 8090
selector:
deploymentconfig: ${NAME}-${ZONE}-${COMPONENT}
- apiVersion: route.openshift.io/v1
kind: Route
metadata:
labels:
app: ${NAME}-${ZONE}
name: ${NAME}-${ZONE}-${COMPONENT}
spec:
host: ${NAME}-${ZONE}-${COMPONENT}.${DOMAIN}
port:
targetPort: 8090-tcp
to:
kind: Service
name: ${NAME}-${ZONE}-${COMPONENT}
weight: 100
tls:
termination: edge
insecureEdgeTerminationPolicy: Redirect
18 changes: 0 additions & 18 deletions .github/openshift/deploy.backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,24 +83,6 @@ objects:
- image: ${NAME}-${ZONE}-${COMPONENT}:${IMAGE_TAG}
imagePullPolicy: Always
name: ${NAME}
env:
- name: POSTGRESQL_HOST
value: ${NAME}-${ZONE}-database
- name: POSTGRESQL_DATABASE
valueFrom:
secretKeyRef:
name: ${NAME}-${ZONE}-database
key: database-name
- name: POSTGRESQL_PASSWORD
valueFrom:
secretKeyRef:
name: ${NAME}-${ZONE}-database
key: database-password
- name: POSTGRESQL_USER
valueFrom:
secretKeyRef:
name: ${NAME}-${ZONE}-database
key: database-user
ports:
- containerPort: 8090
protocol: TCP
Expand Down
11 changes: 4 additions & 7 deletions .github/workflows/merge-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ on:
branches:
- main
paths-ignore:
- ".**"
- "**.md"
- "**.yml"
- "**.yaml"
workflow_dispatch:

env:
Expand Down Expand Up @@ -157,12 +154,12 @@ jobs:
oc login --token=${{ secrets.OC_TOKEN }} --server=${{ secrets.OC_SERVER }}
oc project ${{ secrets.OC_NAMESPACE }}
# Do not replace database; 'oc create' kicks up an error if objects already exist
oc process -f .github/openshift/deploy.database.yml -p ZONE=${{ env.ZONE }} | oc create -f - || true
#oc process -f .github/openshift/deploy.database.yml -p ZONE=${{ env.ZONE }} | oc create -f - || true
# Process and apply deployment templates
oc process -f .github/openshift/deploy.backend.yml -p ZONE=${{ env.ZONE }} \
-p PROMOTE=${{ github.repository }}:${{ env.ZONE }}-service-api | oc apply -f -
# Follow any active rollouts (see deploymentconfigs)
oc rollout status dc/${{ env.NAME }}-${{ env.ZONE }}-database -w
#oc rollout status dc/${{ env.NAME }}-${{ env.ZONE }}-database -w
oc rollout status dc/${{ env.NAME }}-${{ env.ZONE }}-service-api -w
# Remove completed build runs, build pods and deployment pods
for p in $(oc get po | grep "Completed" | awk '{print $1}')
Expand Down Expand Up @@ -296,12 +293,12 @@ jobs:
fi
# Process and apply deployment templates
oc process -f .github/openshift/deploy.database.yml -p ZONE=${{ env.ZONE }} | oc apply -f -
#oc process -f .github/openshift/deploy.database.yml -p ZONE=${{ env.ZONE }} | oc apply -f -
oc process -f .github/openshift/deploy.backend.yml -p ZONE=${{ env.ZONE }} \
-p PROMOTE=${{ github.repository }}:${{ env.PREV }}-service-api | oc apply -f -
# Follow any active rollouts (see deploymentconfigs)
oc rollout status dc/${{ env.NAME }}-${{ env.ZONE }}-database -w
#oc rollout status dc/${{ env.NAME }}-${{ env.ZONE }}-database -w
oc rollout status dc/${{ env.NAME }}-${{ env.ZONE }}-service-api -w
# Remove completed build runs, build pods and deployment pods
Expand Down
5 changes: 1 addition & 4 deletions .github/workflows/pr-close.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
name: Pull Request Close
name: PR Close

on:
pull_request:
types:
- closed
paths-ignore:
- ".**"
- "**.md"
- "**.yml"
- "**.yaml"

env:
REGISTRY: ghcr.io
Expand Down
Loading

0 comments on commit 697e04c

Please sign in to comment.