-
Notifications
You must be signed in to change notification settings - Fork 1
83 lines (75 loc) · 3.49 KB
/
main_deploy_test_prod.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
# Used to trigger deployment to test and prod Openshift environnment by Image stream re-tagging and labelling pod
name: Trigger deployment to test and prod Openshift environnment by Image stream re-tagging and labelling pod
on:
workflow_dispatch:
inputs:
app:
description: 'App Name (jag-document-utils-api)'
required: true
default: 'jag-document-utils-api'
imageSourceEnv:
type: choice
description: Image Source environment
options:
- Select a Source Env Image to deploy
- dev
- test
required: true
default: 'Select a Source Env Image to deploy'
imageTargetEnv:
type: choice
description: Target Release Environment
options:
- Select a Target Env to deploy the Source Image
- test
- prod
required: true
default: 'Select a Target Env to deploy the Source Image'
jobs:
oc-image-tagging:
runs-on: ubuntu-20.04
environment: ${{ github.event.inputs.imageTargetEnv }}
steps:
# Prints vital release paramters used
- name: Print Release Variables
run: |
echo "Release Application: ${{ github.event.inputs.app }}"
echo "Release Source Environment: ${{ github.event.inputs.imageSourceEnv }}"
echo "Release Target Environment: ${{ github.event.inputs.imageTargetEnv }}"
# Get current Timestamp to be used for backup tag
- name: Get Timestamp
id: gettime
run: |
currentdatetime=$(date +"%Y-%m-%d_%H-%M_%Z")
echo "timestamp=$currentdatetime" >> $GITHUB_ENV
#Login to Openshift using OC Tools SA and Token for image stream tagging changes
- name: Authenticate OC Tools SA
uses: redhat-actions/oc-login@v1
env:
OPENSHIFT_NAMESPACE: ${{secrets.OPENSHIFT_TOOLS_NAMESPACE}}
OPENSHIFT_USER: ${{secrets.OPENSHIFT_SA_TOOLS_DEPLOYER_NAME}}
with:
openshift_server_url: ${{secrets.OPENSHIFT_SERVER_URL}}
openshift_token: ${{secrets.OPENSHIFT_SA_TOOLS_DEPLOYER_TOKEN}}
namespace: ${{secrets.OPENSHIFT_TOOLS_NAMESPACE}}
# Take a backup tag of current prod image for any future rollback
- name: Backup Prod image for any future release rollbackups
if: ${{ github.event.inputs.imageTargetEnv == 'prod' }}
env:
appName: ${{ github.event.inputs.app }}
imageTargetEnv: ${{ github.event.inputs.imageTargetEnv }}
openshiftToolsNamespace: ${{secrets.OPENSHIFT_TOOLS_NAMESPACE}}
openshiftIImageRegistry: ${{secrets.OPENSHIFT_INTERNAL_REPOSITORY}}
timestamp: ${{ env.timestamp }}
run: |
oc tag ${openshiftIImageRegistry}/${openshiftToolsNamespace}/${appName}:prod ${appName}:prod_backup_${timestamp}
# Re-Tag latest dev (source) image to other env to trigger openshift deployment via DeploymentConfig
- name: Retag dev image to target release env to trigger deployment
env:
appName: ${{ github.event.inputs.app }}
imageSourceEnv: ${{ github.event.inputs.imageSourceEnv }}
imageTargetEnv: ${{ github.event.inputs.imageTargetEnv }}
openshiftToolsNamespace: ${{secrets.OPENSHIFT_TOOLS_NAMESPACE}}
openshiftIImageRegistry: ${{secrets.OPENSHIFT_INTERNAL_REPOSITORY}}
run: |
oc tag ${openshiftIImageRegistry}/${openshiftToolsNamespace}/${appName}:${imageSourceEnv} ${appName}:${imageTargetEnv}