-
Notifications
You must be signed in to change notification settings - Fork 0
162 lines (158 loc) · 6.55 KB
/
docker-build-dev.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
name: Dev - Build & Push docker images
on:
push:
branches: [ "dev" ]
paths-ignore:
- '.github/**'
- '.gitignore'
- 'database/**'
- 'documentation/**'
- 'openshift/**'
- 'tests/**'
- 'CODE_OF_CONDUCT.md'
- 'COMPLIANCE.yaml'
- 'CONTRIBUTING.md'
- 'LICENSE'
- 'README.md'
- 'SECURITY.md'
# Allow manual workflow triggering
workflow_dispatch:
# Workflow dependencies
env:
TARGET_ENV: dev
GH_TOKEN: ${{secrets.GH_API_TOKEN}}
OC_CLUSTER: ${{ vars.OPENSHIFT_CLUSTER }}
OC_REGISTRY: ${{ vars.OPENSHIFT_REGISTRY }}
OC_AUTH_TOKEN: ${{ secrets.OPENSHIFT_TOKEN }}
OC_TARGET_PROJECT: ${{ vars.OPENSHIFT_NAMESPACE }}
JFROG_USERNAME: ${{ secrets.ARTIFACTORY_USERNAME }}
JFROG_PASSWORD: ${{ secrets.ARTIFACTORY_PASSWORD }}
JFROG_REPO_PATH: ${{ vars.ARTIFACTORY_REPO }}
JFROG_SERVICE: ${{ vars.ARTIFACTORY_SERVICE }}
UGM_BUILD_VERSION: ${{vars.UGM_BUILD_VERSION}}
UGM_BUILD_REVISION: ${{vars.UGM_BUILD_REVISION}}
UGM_RELEASE_PREFIX: API_v
UGM_RELEASE_MESSAGE: "Development deployment"
jobs:
Setup:
runs-on: ubuntu-latest
environment: dev
steps:
- name: Get variables
run: |
echo "Target: $TARGET_ENV"
echo "BaseRef: $GITHUB_REF_NAME"
echo "Environment: $TARGET_ENV OC_TARGET_PROJECT=$OC_TARGET_PROJECT"
echo "Environment: $TARGET_ENV JFROG_REPO_PATH=$JFROG_REPO_PATH"
echo "..."
env | sort
- name: Get current date
id: date_selector
run: echo "DATE=$(date +'%B %e, %Y')" >> $GITHUB_OUTPUT
outputs:
DATE: ${{steps.date_selector.outputs.DATE}}
Branch:
needs: [Setup]
runs-on: ubuntu-latest
environment: dev
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: '1'
- name: Get short commitId
id: get_commit
run: echo "SHA_SHORT=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
- name: List merged branch
id: get_branch
run: |
# Get the latest merge commit message
LATEST_MERGE_COMMIT=$(git log --merges --pretty=format:"%s" -1)
git log
# Print the latest merge commit message for debugging
echo "Latest merge commit message: $LATEST_MERGE_COMMIT"
# Check if the latest merge commit matches "Merge pull request * from bcgov/*"
if echo "$LATEST_MERGE_COMMIT" | grep -qE 'Merge pull request #[0-9]+ from bcgov/[^ ]+'; then
# Extract the branch name
MERGED_BRANCH=$(echo "$LATEST_MERGE_COMMIT" | grep -oE 'from bcgov/[^ ]+' | sed 's/from bcgov\///')
echo "Merged branch: $MERGED_BRANCH"
echo "MERGED_BRANCH=$MERGED_BRANCH" >> $GITHUB_OUTPUT
else
echo "Direct push into dev branch"
echo "MERGED_BRANCH=push" >> $GITHUB_OUTPUT
fi
outputs:
SHA_SHORT: ${{steps.get_commit.outputs.SHA_SHORT}}
MERGED_BRANCH: ${{steps.get_branch.outputs.MERGED_BRANCH}}
PushVariables:
needs: [Setup,Branch]
runs-on: ubuntu-latest
environment: dev
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: '1'
- name: Set repository version variables
id: set_version
run: |
gh variable set UGM_BUILD_REVISION --env ${{env.TARGET_ENV}} --body "${{needs.Branch.outputs.SHA_SHORT}}"
echo "UGM_BUILD_REVISION=${{needs.Branch.outputs.SHA_SHORT}}" >> $GITHUB_ENV
- name: Get repository version variables
id: get_version
run: |
gh variable list --env ${{env.TARGET_ENV}}
echo "..."
echo "buildArgs --env ${{env.TARGET_ENV}} UNITY_BUILD_VERSION: ${{env.UGM_BUILD_VERSION}}, UNITY_BUILD_REVISION: ${{env.UGM_BUILD_REVISION}}, Merged Branch: ${{needs.Branch.outputs.MERGED_BRANCH}}"
Build:
needs: [Setup,Branch,PushVariables]
runs-on: ubuntu-latest
environment: dev
steps:
- uses: actions/checkout@v4
- name: Build dotnetapp docker images
run: docker compose build
working-directory: ./applications/dotnetapp
- name: Build aspnetapp docker images
run: docker compose build
working-directory: ./applications/aspnetapp
- name: Build Docker images
run: |
rm -f ./docker-compose.override.yml
echo "buildArgs UNITY_BUILD_VERSION: ${{env.UGM_BUILD_VERSION}}, UNITY_BUILD_REVISION: ${{env.UGM_BUILD_REVISION}}"
docker compose build --build-arg UNITY_BUILD_VERSION=${{env.UGM_BUILD_VERSION}} --build-arg UNITY_BUILD_REVISION=${{env.UGM_BUILD_REVISION}}
working-directory: ./applications/Unity.GrantManager
- name: Connect to JFrog Artifactory non-interactive login using --password-stdin
run: |
echo "$JFROG_PASSWORD" | docker login -u "$JFROG_USERNAME" --password-stdin $JFROG_SERVICE
- name: Push application images to Artifactory container registry
run: |
docker tag dotnetapp $JFROG_SERVICE/$JFROG_REPO_PATH/dotnetapp
docker push $JFROG_SERVICE/$JFROG_REPO_PATH/dotnetapp
docker tag aspnetapp $JFROG_SERVICE/$JFROG_REPO_PATH/aspnetapp
docker push $JFROG_SERVICE/$JFROG_REPO_PATH/aspnetapp
docker tag unity-grantmanager-dbmigrator $JFROG_SERVICE/$JFROG_REPO_PATH/unity-grantmanager-dbmigrator
docker push $JFROG_SERVICE/$JFROG_REPO_PATH/unity-grantmanager-dbmigrator
docker tag unity-grantmanager-web $JFROG_SERVICE/$JFROG_REPO_PATH/unity-grantmanager-web
docker push $JFROG_SERVICE/$JFROG_REPO_PATH/unity-grantmanager-web
- name: Disconnect docker from JFrog Artifactory
run: |
docker logout
- name: Connect to OpenShift API non-interactive login using current session token
run: |
oc login --token=$OC_AUTH_TOKEN --server=$OC_CLUSTER
oc registry login
docker login -u unused -p $(oc whoami -t) $OC_REGISTRY
- name: Push application images to OpenShift container registry
run: |
docker tag dotnetapp $OC_REGISTRY/$OC_TARGET_PROJECT/dotnetapp
docker push $OC_REGISTRY/$OC_TARGET_PROJECT/dotnetapp
docker tag aspnetapp $OC_REGISTRY/$OC_TARGET_PROJECT/aspnetapp
docker push $OC_REGISTRY/$OC_TARGET_PROJECT/aspnetapp
docker tag unity-grantmanager-dbmigrator $OC_REGISTRY/$OC_TARGET_PROJECT/unity-grantmanager-dbmigrator
docker push $OC_REGISTRY/$OC_TARGET_PROJECT/unity-grantmanager-dbmigrator
docker tag unity-grantmanager-web $OC_REGISTRY/$OC_TARGET_PROJECT/unity-grantmanager-web
docker push $OC_REGISTRY/$OC_TARGET_PROJECT/unity-grantmanager-web
- name: Disconnect docker from OpenShift container registry
run: |
docker logout