Skip to content

Commit

Permalink
feat: convert dc to deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
trev-dev committed Dec 11, 2024
1 parent 260d384 commit e09ecc8
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 38 deletions.
18 changes: 9 additions & 9 deletions .github/workflows/deploy-to.openshift-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ env:

APP_NAME: 'digitalid-api'
REPO_NAME: "educ-digitalid-api"
BRANCH: "master"
BRANCH: ${{ github.ref_name }}
APP_NAME_FULL: "digitalid-api-master"
NAMESPACE: ${{ secrets.COMMON_NAMESPACE_NO_ENV }}
COMMON_NAMESPACE: ${{ secrets.COMMON_NAMESPACE_NO_ENV }}
Expand Down Expand Up @@ -148,14 +148,14 @@ jobs:
oc project ${{ env.OPENSHIFT_NAMESPACE_DEV }}
# Cancel any rollouts in progress
oc rollout cancel dc/${{ env.SPRING_BOOT_IMAGE_NAME }} 2> /dev/null \
oc rollout cancel deployment/${{ env.SPRING_BOOT_IMAGE_NAME }} 2> /dev/null \
|| true && echo "No rollout in progress"
oc tag ${{ steps.push-image.outputs.registry-path }} \
${{ env.REPO_NAME }}-${{ env.BRANCH }}:${{ env.TAG }}
# Process and apply deployment template
oc process -f tools/openshift/api.dc.yaml \
oc process -f tools/openshift/api.deployment.yaml \
-p APP_NAME=${{ env.APP_NAME }} \
-p REPO_NAME=${{ env.REPO_NAME }} \
-p BRANCH=${{ env.BRANCH }} \
Expand All @@ -169,23 +169,23 @@ jobs:
-p MAX_MEM=${{ env.MAX_MEM }} \
| oc apply -f -
curl -s https://raw.githubusercontent.com/bcgov/\
${{ env.REPO_NAME }}/master/tools/config/update-configmap.sh | bash /dev/stdin dev \
curl -s https://raw.githubusercontent.com/bcgov/${{ env.REPO_NAME }}/${{ env.BRANCH }}/tools/config/update-configmap.sh | bash /dev/stdin dev \
${{ env.APP_NAME }} \
${{ env.NAMESPACE }} \
${{ env.DB_JDBC_CONNECT_STRING }} \
${{ env.DB_PWD }} \
${{ env.DB_USER }} \
${{ env.SPLUNK_TOKEN }}
${{ env.SPLUNK_TOKEN }} \
${{ env.BRANCH }}
# Start rollout (if necessary) and follow it
oc rollout latest dc/${{ env.SPRING_BOOT_IMAGE_NAME }} 2> /dev/null \
oc rollout restart deployment/${{ env.SPRING_BOOT_IMAGE_NAME }} 2> /dev/null \
|| true && echo "Rollout in progress"
oc logs -f dc/${{ env.SPRING_BOOT_IMAGE_NAME }}
oc logs -f deployment/${{ env.SPRING_BOOT_IMAGE_NAME }}
# Get status, returns 0 if rollout is successful
oc rollout status dc/${{ env.SPRING_BOOT_IMAGE_NAME }}
oc rollout status deployment/${{ env.SPRING_BOOT_IMAGE_NAME }}
- name: ZAP Scan
uses: zaproxy/[email protected]
with:
Expand Down
15 changes: 8 additions & 7 deletions .github/workflows/deploy-to.openshift-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ env:

APP_NAME: 'digitalid-api'
REPO_NAME: "educ-digitalid-api"
BRANCH: "master"
BRANCH: ${{ github.ref_name }}
NAMESPACE: ${{ secrets.COMMON_NAMESPACE_NO_ENV }}
COMMON_NAMESPACE: ${{ secrets.COMMON_NAMESPACE_NO_ENV }}
TAG: "latest"
Expand Down Expand Up @@ -113,15 +113,15 @@ jobs:
oc project ${{ env.OPENSHIFT_NAMESPACE }}
# Cancel any rollouts in progress
oc rollout cancel dc/${{ env.SPRING_BOOT_IMAGE_NAME }} 2> /dev/null \
oc rollout cancel deployment/${{ env.SPRING_BOOT_IMAGE_NAME }} 2> /dev/null \
|| true && echo "No rollout in progress"
oc tag \
${{ env.NAMESPACE }}-dev/${{ env.REPO_NAME }}-${{ env.BRANCH }}:${{ steps.get-latest-tag.outputs.tag }} \
${{ env.NAMESPACE }}-prod/${{ env.REPO_NAME }}-${{ env.BRANCH }}:${{ steps.get-latest-tag.outputs.tag }}
# Process and apply deployment template
oc process -f tools/openshift/api.dc.yaml \
oc process -f tools/openshift/api.deployment.yaml \
-p APP_NAME=${{ env.APP_NAME }} \
-p REPO_NAME=${{ env.REPO_NAME }} \
-p BRANCH=${{ env.BRANCH }} \
Expand All @@ -143,13 +143,14 @@ jobs:
${{ env.DB_JDBC_CONNECT_STRING }} \
${{ env.DB_PWD }} \
${{ env.DB_USER }} \
${{ env.SPLUNK_TOKEN }}
${{ env.SPLUNK_TOKEN }} \
${{ env.BRANCH }}
# Start rollout (if necessary) and follow it
oc rollout latest dc/${{ env.SPRING_BOOT_IMAGE_NAME }} 2> /dev/null \
oc rollout restart deployment/${{ env.SPRING_BOOT_IMAGE_NAME }} 2> /dev/null \
|| true && echo "Rollout in progress"
oc logs -f dc/${{ env.SPRING_BOOT_IMAGE_NAME }}
oc logs -f deployment/${{ env.SPRING_BOOT_IMAGE_NAME }}
# Get status, returns 0 if rollout is successful
oc rollout status dc/${{ env.SPRING_BOOT_IMAGE_NAME }}
oc rollout status deployment/${{ env.SPRING_BOOT_IMAGE_NAME }}
17 changes: 9 additions & 8 deletions .github/workflows/deploy-to.openshift-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ env:

APP_NAME: 'digitalid-api'
REPO_NAME: "educ-digitalid-api"
BRANCH: "master"
BRANCH: ${{ github.ref_name }}
APP_NAME_FULL: "digitalid-api-master"
NAMESPACE: ${{ secrets.COMMON_NAMESPACE_NO_ENV }}
COMMON_NAMESPACE: ${{ secrets.COMMON_NAMESPACE_NO_ENV }}
Expand Down Expand Up @@ -116,15 +116,15 @@ jobs:
oc project ${{ env.OPENSHIFT_NAMESPACE_TEST }}
# Cancel any rollouts in progress
oc rollout cancel dc/${{ env.SPRING_BOOT_IMAGE_NAME }} 2> /dev/null \
oc rollout cancel deployment/${{ env.SPRING_BOOT_IMAGE_NAME }} 2> /dev/null \
|| true && echo "No rollout in progress"
oc tag \
${{ env.NAMESPACE }}-dev/${{ env.REPO_NAME }}-${{ env.BRANCH }}:${{ env.TAG }} \
${{ env.NAMESPACE }}-test/${{ env.REPO_NAME }}-${{ env.BRANCH }}:${{ env.TAG }}
# Process and apply deployment template
oc process -f tools/openshift/api.dc.yaml \
oc process -f tools/openshift/api.deployment.yaml \
-p APP_NAME=${{ env.APP_NAME }} \
-p REPO_NAME=${{ env.REPO_NAME }} \
-p BRANCH=${{ env.BRANCH }} \
Expand All @@ -138,23 +138,24 @@ jobs:
-p MAX_MEM=${{ env.MAX_MEM }} \
| oc apply -f -
curl -s https://raw.githubusercontent.com/bcgov/${{ env.REPO_NAME }}/master/tools/config/update-configmap.sh \
curl -s https://raw.githubusercontent.com/bcgov/${{ env.REPO_NAME }}/${{ env.BRANCH }}/tools/config/update-configmap.sh \
| bash /dev/stdin test \
${{ env.APP_NAME }} \
${{ env.NAMESPACE }} \
${{ env.DB_JDBC_CONNECT_STRING }} \
${{ env.DB_PWD }} \
${{ env.DB_USER }} \
${{ env.SPLUNK_TOKEN }}
${{ env.SPLUNK_TOKEN }} \
${{ env.BRANCH }}
# Start rollout (if necessary) and follow it
oc rollout latest dc/${{ env.SPRING_BOOT_IMAGE_NAME }} 2> /dev/null \
oc rollout restart deployment/${{ env.SPRING_BOOT_IMAGE_NAME }} 2> /dev/null \
|| true && echo "Rollout in progress"
oc logs -f dc/${{ env.SPRING_BOOT_IMAGE_NAME }}
oc logs -f deployment/${{ env.SPRING_BOOT_IMAGE_NAME }}
# Get status, returns 0 if rollout is successful
oc rollout status dc/${{ env.SPRING_BOOT_IMAGE_NAME }}
oc rollout status deployment/${{ env.SPRING_BOOT_IMAGE_NAME }}
- name: ZAP Scan
uses: zaproxy/[email protected]
Expand Down
7 changes: 4 additions & 3 deletions tools/config/update-configmap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ DB_JDBC_CONNECT_STRING=$4
DB_PWD=$5
DB_USER=$6
SPLUNK_TOKEN=$7
BRANCH=$8

TZVALUE="America/Vancouver"
SOAM_KC_REALM_ID="master"
Expand Down Expand Up @@ -115,9 +116,9 @@ oc create -n "$OPENSHIFT_NAMESPACE-$envValue" configmap "$APP_NAME-config-map" \
--dry-run -o yaml | oc apply -f -
echo

echo Setting environment variables for "$APP_NAME"-$SOAM_KC_REALM_ID application
echo Setting environment variables for "$APP_NAME-$BRANCH" application
oc -n "$OPENSHIFT_NAMESPACE"-"$envValue" set env \
--from="configmap/$APP_NAME-config-map" "dc/$APP_NAME-$SOAM_KC_REALM_ID"
--from="configmap/$APP_NAME-config-map" "deployment/$APP_NAME-$BRANCH"

echo Creating config map "$APP_NAME-flb-sc-config-map"
oc create -n "$OPENSHIFT_NAMESPACE-$envValue" configmap "$APP_NAME"-flb-sc-config-map \
Expand All @@ -127,4 +128,4 @@ oc create -n "$OPENSHIFT_NAMESPACE-$envValue" configmap "$APP_NAME"-flb-sc-confi

echo Removing un-needed config entries
oc -n "$OPENSHIFT_NAMESPACE-$envValue" set env \
dc/"$APP_NAME"-$SOAM_KC_REALM_ID KEYCLOAK_PUBLIC_KEY-
"deployment/$APP_NAME-$SOAM_KC_REALM_ID" KEYCLOAK_PUBLIC_KEY-
22 changes: 11 additions & 11 deletions tools/openshift/api.dc.yaml → tools/openshift/api.deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,24 @@ kind: Template
labels:
template: "${REPO_NAME}-template"
metadata:
name: "${REPO_NAME}-${BRANCH}-dc"
name: "${REPO_NAME}-${BRANCH}-deployment"
objects:
- apiVersion: v1
kind: DeploymentConfig
- apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: "${APP_NAME}-${BRANCH}"
name: "${APP_NAME}-${BRANCH}"
spec:
replicas: ${{MIN_REPLICAS}}
selector:
app: "${APP_NAME}-${BRANCH}"
deploymentConfig: "${APP_NAME}-${BRANCH}"
matchLabels:
app: "${APP_NAME}-${BRANCH}"
strategy:
resources: {}
type: Rolling
type: RollingUpdate
rollingUpdate:
maxUnavailable: 25%
maxSurge: 25%
template:
metadata:
annotations:
Expand All @@ -29,7 +31,6 @@ objects:
prometheus.io/scrape: 'true'
labels:
app: "${APP_NAME}-${BRANCH}"
deploymentConfig: "${APP_NAME}-${BRANCH}"
spec:
containers:
- image: image-registry.openshift-image-registry.svc:5000/${NAMESPACE}/${REPO_NAME}-${BRANCH}:${TAG}
Expand Down Expand Up @@ -131,15 +132,14 @@ objects:
protocol: TCP
selector:
app: "${APP_NAME}-${BRANCH}"
deploymentconfig: "${APP_NAME}-${BRANCH}"
- apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: "${APP_NAME}-${BRANCH}-cpu-autoscaler"
spec:
scaleTargetRef:
apiVersion: apps.openshift.io/v1
kind: DeploymentConfig
apiVersion: apps/v1
kind: Deployment
name: "${APP_NAME}-${BRANCH}"
subresource: scale
minReplicas: ${{MIN_REPLICAS}}
Expand Down

0 comments on commit e09ecc8

Please sign in to comment.