-
Notifications
You must be signed in to change notification settings - Fork 33
137 lines (126 loc) · 5.93 KB
/
promote-web.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
name: On Promotion to Test or Production for Web
on:
deployment
env:
PULL_NUMBER: ${{ fromJSON(github.event.deployment.payload).pr }}
MICRO_SERVICE: ${{ fromJSON(github.event.deployment.payload).microservice }}
DEPLOY_REF: ${{ github.event.deployment.ref }}
DEPLOYMENT_ID: ${{ github.event.deployment.id }}
ENVIRONMENT: ${{ github.event.deployment.environment }}
INFRA_NAME: devhub-app-web
jobs:
promote-environment:
name: Promote Web to Environment
if: fromJSON(github.event.deployment.payload).microservice == 'web' &&
(
github.event.deployment.environment == 'staging' ||
github.event.deployment.environment == 'qa' ||
github.event.deployment.environment == 'production'
)
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v1
- name: Change Deploy Status to In Progress
uses: unacast/actions-github-deployment-status@0.4.0
with:
github_token: ${{ github.token }}
status: in_progress
- name: Map the deployments environment to a valid Openshift Namespace
env:
TEST_NAMESPACE: ${{ secrets.TEST_NAMESPACE }}
PROD_NAMESPACE: ${{ secrets.PROD_NAMESPACE }}
DEV_NAMESPACE: ${{ secrets.DEV_NAMESPACE }}
SSO_TEST_URL: https://test.oidc.gov.bc.ca
SSO_PROD_URL: https://oidc.gov.bc.ca
run: |
_NAMESPACE=$(.github/helpers/github_env_to_namespace.sh ${{ github.event.deployment.environment }})
_IMAGE_TAG=$(.github/helpers/github_env_to_image_tag.sh ${{ github.event.deployment.environment }})
_SSO_BASE_URL=''
_ALGOLIA_SOURCE_INDEX=''
_ALGOLIA_DEST_INDEX_SUFFIX=''
_ALGOLIA_SOURCE_INDEX=Devhub-Algolia-${{ env.PULL_NUMBER }}
if [ "$_NAMESPACE" == "$TEST_NAMESPACE" ]; then
_SSO_BASE_URL=$SSO_TEST_URL
_ALGOLIA_DEST_INDEX_SUFFIX=-test
else
_SSO_BASE_URL=$SSO_PROD_URL
_ALGOLIA_DEST_INDEX_SUFFIX=-prod
fi
echo "DEPLOY_NAMESPACE=$_NAMESPACE" >> $GITHUB_ENV
echo "IMAGE_TAG=$_IMAGE_TAG" >> $GITHUB_ENV
echo "SUFFIX=-$_IMAGE_TAG" >> $GITHUB_ENV
echo "ALGOLIA_SOURCE_INDEX=$_ALGOLIA_SOURCE_INDEX" >> $GITHUB_ENV
echo "ALGOLIA_DEST_INDEX_SUFFIX=$_ALGOLIA_DEST_INDEX_SUFFIX" >> $GITHUB_ENV
echo "SSO_BASE_URL=$_SSO_BASE_URL" >> $GITHUB_ENV
echo "Deploying to $_NAMESPACE"
- name: Cluster Login
uses: redhat-developer/openshift-actions@v1.1
with:
openshift_server_url: ${{ secrets.OPENSHIFT_SERVER_URL }}
parameters: '{"apitoken": "${{ secrets.OPENSHIFT_SA_PASSWORD }}"}'
cmd: |
'version'
- name: Promote Algolia index to Environment
env:
ALGOLIA_API_KEY: ${{ secrets.ALGOLIA_API_KEY }}
ALGOLIA_APP_ID: ${{ secrets.ALGOLIA_APP_ID }}
ALGOLIA_SOURCE_INDEX: ${{ env.ALGOLIA_SOURCE_INDEX }}
ALGOLIA_DEST_INDEX: Algolia-Build${{ env.ALGOLIA_DEST_INDEX_SUFFIX }}
run: |
.github/helpers/clone_algolia_index.sh
- name: Import PR based Image to Environment
run: |
oc tag ${{ secrets.TOOLS_NAMESPACE }}/${{ env.INFRA_NAME }}:${{ env.PULL_NUMBER }} \
${{ env.DEPLOY_NAMESPACE }}/${{ env.INFRA_NAME }}:${{ env.IMAGE_TAG }}
- name: Run Deployment
env:
IMAGE_NAMESPACE: ${{ env.DEPLOY_NAMESPACE }}
IMAGE_TAG: ${{ env.IMAGE_TAG }}
DEPLOY_NAMESPACE: ${{ env.DEPLOY_NAMESPACE }}
SEARCHGATE_API_URL: ${{ secrets.SEARCHGATE_API_URL }}
DEVHUB_API_URL: ${{ secrets.DEVHUB_API_URL }}
SSO_BASE_URL: ${{ env.SSO_BASE_URL }}
SSO_CLIENT_ID: ${{ secrets.SSO_CLIENT }}
SSO_REALM_NAME: ${{ secrets.SSO_REALM }}
ALGOLIA_INDEX_NAME: Algolia-Build${{ env.ALGOLIA_DEST_INDEX_SUFFIX }}
run: .github/helpers/deploy_web.sh
- name: Wait for Deployment and Update Status
env:
NAMESPACE: ${{ env.DEPLOY_NAMESPACE }}
run: |
DEPLOY_STATUS=$(.github/helpers/wait_for_deployment.sh dc/$INFRA_NAME$SUFFIX)
echo "DEPLOY_STATUS=$DEPLOY_STATUS" >> $GITHUB_ENV
- name: Change Deploy Status to Success or Failure
uses: unacast/actions-github-deployment-status@0.4.0
with:
github_token: ${{ github.token }}
status: ${{ env.DEPLOY_STATUS }}
- name: 'Comment PR'
uses: actions/github-script@0.3.0
if: env.DEPLOY_STATUS == 'success'
with:
github-token: ${{ github.token }}
script: |
const { repo: { owner, repo } } = context;
github.issues.createComment({ issue_number: ${{ env.PULL_NUMBER }}, owner, repo, body: 'Deployment to ${{ github.event.deployment.environment }} succeeded!' });
- name: Clean up artifacts
if: env.DEPLOY_STATUS == 'success' && github.event.deployment.environment == 'production'
env:
TOOLS_NAMESPACE: ${{ secrets.TOOLS_NAMESPACE }}
DEV_NAMESPACE: ${{ secrets.DEV_NAMESPACE }}
PULL_NUMBER: ${{ env.PULL_NUMBER }}
run: |
echo "deleting build artifacts"
oc -n $TOOLS_NAMESPACE delete bc,configmap -l build=$INFRA_NAME-$PULL_NUMBER
echo "deleting imagestream tag"
oc -n $TOOLS_NAMESPACE delete imagestreamtag/$INFRA_NAME:$PULL_NUMBER
echo "deleting dev artifacts"
oc -n $DEV_NAMESPACE delete dc,configmap -l app=$INFRA_NAME-$PULL_NUMBER
- name: 'Clean up PR comment'
uses: actions/github-script@0.3.0
if: env.DEPLOY_STATUS == 'success' && github.event.deployment.environment == 'production'
with:
github-token: ${{ github.token }}
script: |
const { repo: { owner, repo } } = context;
github.issues.createComment({ issue_number: ${{ env.PULL_NUMBER }}, owner, repo, body: 'Cleaning up dev artifacts and build artifacts' });