Skip to content

Commit 40505c8

Browse files
Add liquibase deployment scripts.
1 parent 8d3f219 commit 40505c8

File tree

12 files changed

+393
-1
lines changed

12 files changed

+393
-1
lines changed
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
name: Liquibase DDL application
2+
run-name: Deploy Liquibase to ${{ inputs.ENVIRONMENT_NAME }}
3+
4+
on:
5+
workflow_dispatch:
6+
inputs:
7+
ENVIRONMENT_NAME:
8+
required: true
9+
type: choice
10+
options:
11+
- dev
12+
- qa
13+
- dlvr
14+
- test
15+
- prod
16+
NAMESPACE:
17+
required: true
18+
type: choice
19+
options:
20+
- e980f4-dev
21+
- e980f4-test
22+
- e980f4-prod
23+
TAG:
24+
required: false
25+
type: string
26+
default: latest
27+
28+
jobs:
29+
30+
ddl_dockerbuild:
31+
runs-on: ubuntu-latest
32+
environment:
33+
name: ${{ inputs.ENVIRONMENT_NAME }}
34+
permissions:
35+
contents: read
36+
packages: write
37+
steps:
38+
- name: Checkout
39+
uses: actions/checkout@v4
40+
41+
- name: Set up QEMU
42+
uses: docker/setup-qemu-action@v3
43+
44+
- name: Set up Docker Buildx
45+
uses: docker/setup-buildx-action@v3
46+
47+
- name: Login to GitHub Container Registry
48+
uses: docker/login-action@v2
49+
with:
50+
registry: ${{ vars.REGISTRY }}
51+
username: ${{ github.actor }}
52+
password: ${{ secrets.GITHUB_TOKEN }}
53+
54+
- name: Extract metadata (tags, labels) for Docker
55+
id: meta_pr
56+
uses: docker/metadata-action@v5
57+
with:
58+
images: ${{ vars.REGISTRY}}/${{ github.repository_owner }}/farms-liquibase
59+
tags: |
60+
type=schedule
61+
type=raw,value=${{ github.base_ref }}
62+
type=ref,event=tag
63+
type=raw,value=${{ inputs.TAG }}
64+
${{ toJson(github.event.pull_request.number) == '{}' && format( 'type=raw,value=pr-{0}', github.event.pull_request.number) || '' }}
65+
66+
67+
- name: Build and push
68+
uses: docker/build-push-action@v5
69+
with:
70+
context: ./farms-liquibase
71+
push: true
72+
tags: ${{ steps.meta_pr.outputs.tags }}
73+
labels: ${{ steps.meta_pr.outputs.labels }}
74+
75+
76+
ddl_deploy:
77+
needs: ddl_dockerbuild
78+
uses: ./.github/workflows/openshift-deploy.yml
79+
secrets: inherit
80+
with:
81+
MICROSERVICE_NAME: farms-liquibase
82+
ENVIRONMENT_NAME: ${{ inputs.ENVIRONMENT_NAME }}
83+
NAMESPACE: ${{ inputs.NAMESPACE }}
84+
TAG: ${{ inputs.TAG }}
85+
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
name: openshift deploy
2+
run-name: Deploy ${{ inputs.MICROSERVICE_NAME }} to ${{ inputs.ENVIRONMENT_NAME}}
3+
4+
on:
5+
workflow_dispatch:
6+
inputs:
7+
MICROSERVICE_NAME:
8+
required: true
9+
type: choice
10+
options:
11+
- farms-api
12+
ENVIRONMENT_NAME:
13+
required: true
14+
type: choice
15+
options:
16+
- dev
17+
- qa
18+
- dlvr
19+
- test
20+
- prod
21+
NAMESPACE:
22+
required: true
23+
type: choice
24+
options:
25+
- e980f4-dev
26+
- e980f4-test
27+
- e980f4-prod
28+
TAG:
29+
required: false
30+
type: string
31+
default: latest
32+
workflow_call:
33+
inputs:
34+
MICROSERVICE_NAME:
35+
required: true
36+
type: string
37+
ENVIRONMENT_NAME:
38+
required: true
39+
type: string
40+
NAMESPACE:
41+
required: true
42+
type: string
43+
TAG:
44+
required: true
45+
type: string
46+
default: latest
47+
48+
jobs:
49+
build:
50+
runs-on: ubuntu-latest
51+
environment:
52+
name: ${{ inputs.ENVIRONMENT_NAME }}
53+
permissions:
54+
contents: read
55+
packages: write
56+
steps:
57+
- name: Checkout
58+
uses: actions/checkout@v4
59+
60+
- name: Copy openshift yaml files
61+
run: mkdir staging && cp openshift/${{ inputs.MICROSERVICE_NAME }}*.yaml staging/
62+
63+
- name: Login to GitHub Container Registry
64+
uses: docker/login-action@v2
65+
with:
66+
registry: ${{ vars.REGISTRY }}
67+
username: ${{ github.actor }}
68+
password: ${{ secrets.GITHUB_TOKEN }}
69+
70+
71+
- name: update IMAGE NAME variable if needed
72+
id: updateImageName
73+
run: |
74+
export IMAGE_NAME='farms-api'
75+
echo "IMAGE_NAME=$IMAGE_NAME" >> $GITHUB_OUTPUT
76+
77+
- name: Get digest of docker image
78+
id: getDigest
79+
run: |
80+
export IMAGE='ghcr.io/${{github.repository_owner}}/${{ steps.updateImageName.outputs.IMAGE_NAME}}:${{ inputs.TAG }}'
81+
docker pull $IMAGE
82+
echo "IMAGE_BY_DIGEST=$(docker inspect --format='{{index .RepoDigests 0}}' $IMAGE)" >> $GITHUB_OUTPUT
83+
84+
- name: Fill yaml files
85+
uses: cschleiden/replace-tokens@v1.2
86+
with:
87+
files: staging/**.yaml
88+
env:
89+
#Common variables
90+
LICENSE_PLATE: 'e980f4'
91+
#Vault path is different for prod than all other environments
92+
VAULT_RESOURCE: ${{ inputs.NAMESPACE == 'e980f4-prod' && 'prod' || 'nonprod' }}
93+
ENV: ${{ inputs.ENVIRONMENT_NAME }}
94+
NAMESPACE: ${{ inputs.NAMESPACE }}
95+
TAG: ${{ inputs.TAG }}
96+
IMAGE_BY_DIGEST: ${{ steps.getDigest.outputs.IMAGE_BY_DIGEST }}
97+
SID: ${{ github.run_id }}
98+
LOG_LEVEL: ${{ vars.LOG_LEVEL }}
99+
CONNECTION_TIMEOUT: ${{ vars.CONNECTION_TIMEOUT }}
100+
101+
POSTGRES_USERNAME: ${{ vars.POSTGRES_USERNAME}}
102+
103+
104+
#API variables
105+
API_CPU_REQUEST: ${{ vars.API_CPU_REQUEST }}
106+
API_CPU_LIMIT: ${{ vars.API_CPU_LIMIT }}
107+
API_MEMORY_REQUEST: ${{ vars.API_MEMORY_REQUEST }}
108+
API_MEMORY_LIMIT: ${{ vars.API_MEMORY_LIMIT }}
109+
MAX_API_COUNT: ${{ vars.MAX_APP_COUNT }}
110+
111+
POSTGRES_RESOURCE_NAME: ${{ vars.POSTGRES_RESOURCE_NAME }}
112+
113+
TOMCAT_MAX_THREADS: ${{ vars.TOMCAT_MAX_THREADS }}
114+
TOMCAT_PORT: ${{ vars.TOMCAT_PORT }}
115+
TIME_ZONE: ${{ vars.TIME_ZONE }}
116+
117+
118+
#DB/Liquibase variables:
119+
POSTGRES_MAXACTIVE: '10'
120+
CHANGELOG_FILE: changelog.json
121+
122+
123+
#Frontend variables
124+
MAX_UI_COUNT: ${{ vars.MAX_UI_COUNT }}
125+
FARMS_REST_URI: https://farms-api-route-${{ inputs.ENVIRONMENT_NAME }}-${{inputs.NAMESPACE}}.apps.silver.devops.gov.bc.ca/farms-api/v1
126+
127+
ACTIVE_PORT: ${{ vars.TOMCAT_PORT }}
128+
LOCAL_CHECKTOKEN_ENDPOINT: ${{ vars.LOCAL_CHECKTOKEN_ENDPOINT }}
129+
130+
WEB_PATH: ${{ vars.WEB_PATH }}
131+
132+
#Explicit install of oc cli tool
133+
- name: Install oc
134+
uses: redhat-actions/oc-installer@v1
135+
136+
- name: Authenticate and set context
137+
uses: redhat-actions/oc-login@v1
138+
with:
139+
openshift_server_url: ${{secrets.OPENSHIFT_SERVER_URL}}
140+
openshift_token: ${{secrets.OPENSHIFT_TOKEN}}
141+
namespace: ${{ inputs.NAMESPACE }}
142+
143+
- name: Apply .yaml files to openshift
144+
run: |
145+
for file in staging/*
146+
do
147+
oc apply -f "$file"
148+
done
149+
150+
151+
152+
153+
154+
155+
156+

crunchy-postgres/charts/crunchy-postgres/values.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ pgBackRest:
6666
bucket: "pit#{ENV}#"
6767
endpoint: "nrs.objectstore.gov.bc.ca"
6868
region: "ca-central-1"
69-
directoryName: pituw#{ENV}#
69+
directoryName: farms#{ENV}#
7070

7171
repoHost:
7272
requests:

farms-liquibase/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.~sql

farms-liquibase/Dockerfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
FROM liquibase/liquibase:4.30.0
2+
3+
COPY ./scripts ./scripts
4+
COPY ./changelog.json .
5+
COPY ./liquibase.properties .

farms-liquibase/changelog.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"databaseChangeLog": [
3+
{
4+
"include": {
5+
"file": "scripts/01_00_xx/01_00_00/00/farms.01_00_00_00.ddl.json"
6+
}
7+
}
8+
]
9+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
changeLogFile: changelog.json
2+
driver: org.postgresql.Driver
3+
schema: farms
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
-- Role: "proxy_farms_rest"
2+
-- DROP ROLE "proxy_farms_rest";
3+
4+
CREATE ROLE "proxy_farms_rest" WITH
5+
LOGIN
6+
NOSUPERUSER
7+
INHERIT
8+
NOCREATEDB
9+
NOCREATEROLE
10+
NOREPLICATION
11+
PASSWORD '${POSTGRES_PROXY_USER_PASSWORD}';
12+
13+
ALTER ROLE proxy_farms_rest SET search_path TO farms;
14+
15+
ALTER USER proxy_farms_rest set TIMEZONE to 'America/New_York';
16+
17+
COMMENT ON ROLE "proxy_farms_rest" IS 'Proxy account for Farmer Access to Risk Management Service.';
18+
19+
GRANT "app_farms_rest_proxy" TO "proxy_farms_rest";
20+
21+
GRANT USAGE ON SCHEMA "farms" TO "app_farms_rest_proxy";
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"databaseChangeLog": [
3+
{
4+
"changeSet": {
5+
"author": "hwang",
6+
"id": "1",
7+
"changes": [
8+
{
9+
"sqlFile": {
10+
"relativeToChangelogFile": "true",
11+
"path": "ddl/roles/farms.ddl.create_login_proxy_farms_rest.sql"
12+
}
13+
}
14+
]
15+
}
16+
}
17+
]
18+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
kind: ConfigMap
2+
apiVersion: v1
3+
metadata:
4+
name: farms-liquibase-config-#{ENV}#
5+
namespace: '#{NAMESPACE}#'
6+
managedFields:
7+
- manager: Mozilla
8+
operation: Update
9+
apiVersion: v1
10+
time: '2025-03-26T14:00:00Z'
11+
fieldsType: FieldsV1
12+
labels:
13+
app: farms-api-#{ENV}#
14+
project: farms-#{ENV}#
15+
immutable: false
16+
data:
17+
LIQUIBASE_COMMAND_URL: jdbc:postgresql://crunchy-postgres-#{ENV}#-pgbouncer.#{NAMESPACE}#.svc.cluster.local/farms#{ENV}#

0 commit comments

Comments
 (0)