Skip to content

Commit

Permalink
chore(ci): frontend init deploy (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
dallascrichmond authored Oct 18, 2024
1 parent ebe9005 commit 3f335dc
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 95 deletions.
97 changes: 61 additions & 36 deletions .github/workflows/.deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,50 +19,75 @@ on:
type: string

jobs:
# database:
# name: Database
# environment: ${{ inputs.environment }}
# runs-on: ubuntu-22.04
# steps:
# - name: Deploy Database
# uses: bcgov-nr/[email protected]
# with:
# oc_namespace: ${{ vars.OC_NAMESPACE }}
# oc_server: ${{ vars.OC_SERVER }}
# oc_token: ${{ secrets.OC_TOKEN }}
# file: database/openshift.deploy.yml
# overwrite: false
# parameters:
# -p TAG=${{ inputs.tag }} -p TARGET=${{ inputs.target }}
init:
name: Init
runs-on: ubuntu-latest
steps:
- name: Initialize
uses: bcgov-nr/[email protected]
with:
oc_namespace: ${{ vars.OC_NAMESPACE }}
oc_server: ${{ vars.OC_SERVER }}
oc_token: ${{ secrets.OC_TOKEN }}
oc_version: "4.14.37"
file: common/openshift.init.yml
overwrite: true
parameters:
-p NAME_SUFFIX=-dev-${{ inputs.target }}
-p DB_PASSWORD=${{ secrets.DB_PASSWORD }}
-p DB_USER=${{ secrets.DB_USER }}
-p DB_NAME=${{ secrets.DB_NAME }}
-p DB_PORT=${{ secrets.DB_PORT }}

database:
name: Database
needs: [init]
environment: ${{ inputs.environment }}
runs-on: ubuntu-22.04
steps:
- name: Deploy Database
uses: bcgov-nr/[email protected]
with:
oc_namespace: ${{ vars.OC_NAMESPACE }}
oc_server: ${{ vars.OC_SERVER }}
oc_token: ${{ secrets.OC_TOKEN }}
file: database/openshift.deploy.yml
overwrite: false
parameters:
-p NAME_SUFFIX=-dev-${{ inputs.target }}
-p IMAGE_TAG=${{ inputs.tag }}
-p TARGET=${{ inputs.target }}

# backend:
# name: Backend
# needs: [database]
# environment: ${{ inputs.environment }}
# runs-on: ubuntu-22.04
# steps:
# - name: Deploy Backend
# uses: bcgov-nr/[email protected]
# with:
# oc_namespace: ${{ vars.OC_NAMESPACE }}
# oc_server: ${{ vars.OC_SERVER }}
# oc_token: ${{ secrets.OC_TOKEN }}
# file: backend/openshift.deploy.yml
# overwrite: true
# parameters:
# -p TAG=${{ inputs.tag }} -p TARGET=${{ inputs.target }}
# verification_path: /api/health
# verification_retry_attempts: "5"
# verification_retry_seconds: "15"
backend:
name: Backend
needs: [init, database]
environment: ${{ inputs.environment }}
runs-on: ubuntu-22.04
steps:
- name: Deploy Backend
uses: bcgov-nr/[email protected]
with:
oc_namespace: ${{ vars.OC_NAMESPACE }}
oc_server: ${{ vars.OC_SERVER }}
oc_token: ${{ secrets.OC_TOKEN }}
file: backend/openshift.deploy.yml
overwrite: true
parameters:
-p NAME_SUFFIX=-dev-${{ inputs.target }}
-p IMAGE_TAG=${{ inputs.tag }}
-p TARGET=${{ inputs.target }}
verification_path: /api/health
verification_retry_attempts: "5"
verification_retry_seconds: "15"

frontend:
name: Frontend
# needs: [backend]
needs: [init, database, backend]
environment: ${{ inputs.environment }}
runs-on: ubuntu-22.04
steps:
- name: Deploy Frontend
uses: bcgov-nr/[email protected].0
uses: bcgov-nr/[email protected].1
with:
oc_namespace: ${{ vars.OC_NAMESPACE }}
oc_server: ${{ vars.OC_SERVER }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr-open.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
# https://github.com/bcgov/quickstart-openshift-helpers
deploys:
name: Deploy
# needs: [builds]
needs: [builds]
secrets: inherit
uses: ./.github/workflows/.deploy.yml

Expand Down
45 changes: 24 additions & 21 deletions backend/openshift.deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ parameters:
- name: ORG
description: Organization name; e.g. bcgov or bcdevops
value: bcgov
- name: TAG
- name: IMAGE_TAG
description: Image tag; e.g. PR number or latest
required: true
- name: TARGET
Expand All @@ -20,13 +20,16 @@ parameters:
description: Password for the PostgreSQL connection user.
from: '[a-zA-Z0-9]{16}'
generate: expression
- name: NAME_SUFFIX
description: Suffix for the name
required: true
objects:
- kind: Service
apiVersion: v1
metadata:
labels:
app: ${APP}-${TARGET}
name: ${APP}-${TARGET}-${COMPONENT}
app: nr-nmp${NAME_SUFFIX}
name: nr-nmp-backend${NAME_SUFFIX}
spec:
type: ClusterIP
ports:
Expand All @@ -35,50 +38,50 @@ objects:
protocol: TCP
name: http-3000
selector:
service: ${APP}-${TARGET}-${COMPONENT}
service: nr-nmp-backend${NAME_SUFFIX}
- kind: Deployment
apiVersion: apps/v1
metadata:
labels:
app: ${APP}-${TARGET}
deployment: ${APP}-${TARGET}-${COMPONENT}
name: ${APP}-${TARGET}-${COMPONENT}
app: nr-nmp${NAME_SUFFIX}
deployment: nr-nmp-backend${NAME_SUFFIX}
name: nr-nmp-backend${NAME_SUFFIX}
spec:
strategy:
type: Recreate
selector:
matchLabels:
deployment: ${APP}-${TARGET}-${COMPONENT}
deployment: nr-nmp-backend${NAME_SUFFIX}
template:
metadata:
labels:
app: ${APP}-${TARGET}
deployment: ${APP}-${TARGET}-${COMPONENT}
service: ${APP}-${TARGET}-${COMPONENT}
app: nr-nmp${NAME_SUFFIX}
deployment: nr-nmp-backend${NAME_SUFFIX}
service: nr-nmp-backend${NAME_SUFFIX}
spec:
containers:
- name: ${APP}-${TARGET}-${COMPONENT}
image: ghcr.io/${ORG}/${APP}/${COMPONENT}:${TAG}
- name: nr-nmp-backend${NAME_SUFFIX}
image: ghcr.io/bcgov/nr-nmp/backend:${IMAGE_TAG}
imagePullPolicy: Always
env:
- name: LOG_LEVEL
value: info
- name: POSTGRES_HOST
value: ${APP}-${TARGET}-database
value: nr-nmp-database${NAME_SUFFIX}
- name: POSTGRES_DB
valueFrom:
secretKeyRef:
name: ${APP}-${TARGET}-database
name: nr-nmp-database${NAME_SUFFIX}
key: database-name
- name: POSTGRES_PASSWORD
valueFrom:
secretKeyRef:
name: ${APP}-${TARGET}-database
name: nr-nmp-database${NAME_SUFFIX}
key: database-password
- name: POSTGRES_USER
valueFrom:
secretKeyRef:
name: ${APP}-${TARGET}-database
name: nr-nmp-database${NAME_SUFFIX}
key: database-user
ports:
- containerPort: 3000
Expand Down Expand Up @@ -114,15 +117,15 @@ objects:
apiVersion: route.openshift.io/v1
metadata:
labels:
app: ${APP}-${TARGET}
name: ${APP}-${TARGET}-${COMPONENT}
app: nr-nmp${NAME_SUFFIX}
name: nr-nmp-backend${NAME_SUFFIX}
spec:
host: ${APP}-${TARGET}-${COMPONENT}.apps.silver.devops.gov.bc.ca
host: nr-nmp-backend${NAME_SUFFIX}.apps.silver.devops.gov.bc.ca
port:
targetPort: http-3000
to:
kind: Service
name: ${APP}-${TARGET}-${COMPONENT}
name: nr-nmp-backend${NAME_SUFFIX}
weight: 100
tls:
termination: edge
Expand Down
23 changes: 23 additions & 0 deletions common/openshift.init.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
apiVersion: v1
kind: Template
parameters:
- name: NAME_SUFFIX
required: true
- name: DB_PASSWORD
required: true
- name: DB_USER
required: true
- name: DB_NAME
required: true
- name: DB_PORT
required: true
objects:
- apiVersion: v1
kind: Secret
metadata:
name: nr-nmp-database${NAME_SUFFIX}
stringData:
database-name: ${DB_NAME}
database-password: ${DB_PASSWORD}
database-port: ${DB_PORT}
database-user: ${DB_USER}
62 changes: 25 additions & 37 deletions database/openshift.deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,15 @@ parameters:
- name: ORG
description: Organization name; e.g. bcgov or bcdevops
value: bcgov
- name: TAG
description: Image tag; e.g. PR number or latest
required: true
- name: TARGET
description: Deployment target; e.g. PR number, test or prod
required: true
- name: DB_PASSWORD
description: Password for the PostgreSQL connection user.
from: "[a-zA-Z0-9]{16}"
generate: expression
- name: IMAGE_TAG
description: Image tag; e.g. PR number or latest
required: true
- name: NAME_SUFFIX
description: Suffix for the name
required: true
objects:
- apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
Expand All @@ -44,23 +43,12 @@ objects:
spec:
policyTypes:
- Ingress
- apiVersion: v1
kind: Secret
metadata:
name: ${APP}-${TARGET}-${COMPONENT}
labels:
app: ${APP}-${TARGET}
stringData:
database-name: postgres
database-password: ${DB_PASSWORD}
database-port: "5432"
database-user: postgres
- kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: ${APP}-${TARGET}-${COMPONENT}
name: nr-nmp-database${NAME_SUFFIX}
labels:
app: ${APP}-${TARGET}
app: nr-nmp${NAME_SUFFIX}
spec:
accessModes:
- ReadWriteOnce
Expand All @@ -71,33 +59,33 @@ objects:
- kind: Deployment
apiVersion: apps/v1
metadata:
name: ${APP}-${TARGET}-${COMPONENT}
name: nr-nmp-database${NAME_SUFFIX}
labels:
app: ${APP}-${TARGET}
app: nr-nmp${NAME_SUFFIX}
spec:
replicas: 1
selector:
matchLabels:
deployment: ${APP}-${TARGET}-${COMPONENT}
deployment: nr-nmp-database${NAME_SUFFIX}
strategy:
type: Recreate
recreateParams:
timeoutSeconds: 600
activeDeadlineSeconds: 21600
template:
metadata:
name: ${APP}-${TARGET}-${COMPONENT}
name: nr-nmp-database${NAME_SUFFIX}
labels:
app: ${APP}-${TARGET}
deployment: ${APP}-${TARGET}-${COMPONENT}
app: nr-nmp${NAME_SUFFIX}
deployment: nr-nmp-database${NAME_SUFFIX}
spec:
volumes:
- name: ${APP}-${TARGET}-${COMPONENT}
- name: nr-nmp-database${NAME_SUFFIX}
persistentVolumeClaim:
claimName: ${APP}-${TARGET}-${COMPONENT}
claimName: nr-nmp-database${NAME_SUFFIX}
containers:
- name: ${APP}-${TARGET}
image: ghcr.io/${ORG}/${APP}/${COMPONENT}:${TAG}
- name: nr-nmp${NAME_SUFFIX}
image: ghcr.io/bcgov/nr-nmp/database:${IMAGE_TAG}
ports:
- containerPort: 5432
protocol: TCP
Expand Down Expand Up @@ -136,20 +124,20 @@ objects:
- name: POSTGRES_DB
valueFrom:
secretKeyRef:
name: ${APP}-${TARGET}-${COMPONENT}
name: nr-nmp-database${NAME_SUFFIX}
key: database-name
- name: POSTGRES_PASSWORD
valueFrom:
secretKeyRef:
name: ${APP}-${TARGET}-${COMPONENT}
name: nr-nmp-database${NAME_SUFFIX}
key: database-password
- name: POSTGRES_USER
valueFrom:
secretKeyRef:
name: ${APP}-${TARGET}-${COMPONENT}
name: nr-nmp-database${NAME_SUFFIX}
key: database-user
volumeMounts:
- name: ${APP}-${TARGET}-${COMPONENT}
- name: nr-nmp-database${NAME_SUFFIX}
mountPath: "/var/lib/postgresql"
terminationMessagePath: "/dev/termination-log"
terminationMessagePolicy: File
Expand All @@ -162,8 +150,8 @@ objects:
kind: Service
metadata:
labels:
app: ${APP}-${TARGET}
name: ${APP}-${TARGET}-${COMPONENT}
app: nr-nmp${NAME_SUFFIX}
name: nr-nmp-database${NAME_SUFFIX}
spec:
ports:
- name: postgresql
Expand All @@ -172,6 +160,6 @@ objects:
protocol: TCP
targetPort: 5432
selector:
deployment: ${APP}-${TARGET}-${COMPONENT}
deployment: nr-nmp-database${NAME_SUFFIX}
sessionAffinity: None
type: ClusterIP

0 comments on commit 3f335dc

Please sign in to comment.