-
Notifications
You must be signed in to change notification settings - Fork 0
103 lines (84 loc) · 3.58 KB
/
cd.yml
File metadata and controls
103 lines (84 loc) · 3.58 KB
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
name: CD ( Continuous deployment) workflow
env:
OPENSHIFT_SERVER: ${{ vars.OPENSHIFT_SERVER }}
OPENSHIFT_TOKEN: ${{ secrets.OPENSHIFT_TOKEN }}
OPENSHIFT_NAMESPACE: games-store
IMAGE_REGISTRY_USER: ${{ secrets.IMAGE_REGISTRY_USER }}
IMAGE_REGISTRY_PASSWORD: ${{ secrets.IMAGE_REGISTRY_PASSWORD }}
IMAGE_PULL_SECRET_NAME: games-store-service-ips
# This CD ( Continuous deployment) Workflow will be triggered only for pushed release tags ( created by CI/CD - Continuous Integration + delivery pipeline)
on:
push:
tags:
- '*'
jobs:
deploy_to_openshift:
environment: staging
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3
with:
ref: main
fetch-depth: 0
- name: Start CD Continuous Deployment Pipeline
shell: bash
run: |
export tag=$(git describe)
echo "About to deploy version $tag to environment"
echo "Get release metadata information from pushed tag:"
git tag $tag -n 3
- name: Install oc
uses: redhat-actions/openshift-tools-installer@v1
with:
oc: 4.15.0
- name: Log In To OpenShift
uses: redhat-actions/oc-login@v1
with:
openshift_server_url: ${{ env.OPENSHIFT_SERVER }}
openshift_token: ${{ env.OPENSHIFT_TOKEN }}
insecure_skip_tls_verify: true
namespace: ${{ env.OPENSHIFT_NAMESPACE }}
- name: Create namespace if doesn't exists
shell: bash
run: |
oc new-project ${{ env.OPENSHIFT_NAMESPACE }}
oc project ${{ env.OPENSHIFT_NAMESPACE }}
continue-on-error: true
- name: Check if Image pull secret exists
continue-on-error: true
id: ipsExists
shell: bash
run: |
oc get secret ${{ env.IMAGE_PULL_SECRET_NAME}}
- name: Create Image pull secret if doesn't exists
if: ${{ steps.ipsExists.outcome == 'failure' }}
shell: bash
run: |
oc create secret docker-registry ${{ env.IMAGE_PULL_SECRET_NAME}} --docker-server=quay.io --docker-username=${{ env.IMAGE_REGISTRY_USER}} --docker-password=${{ env.IMAGE_REGISTRY_PASSWORD}}
# Without this, pod will not be able to pull the image from private registry.
- name: Patch service account with pull secret
shell: bash
run: |
oc patch sa default --type='json' -p='[{"op": "add", "path": "/secrets/1", "value": {"name": "${{ env.IMAGE_PULL_SECRET_NAME}}" } }]'
oc secrets link default ${{ env.IMAGE_PULL_SECRET_NAME}} --for=pull
- name: Deploy to cluster from manifests
shell: bash
run: oc apply -f deploy/
- name: Extract full Server Route name for Swagger-UI
id: swagger
shell: bash
run: |
export route=$(oc get route -o=jsonpath='{.items[].spec.host}')
echo "url=https://$route" >> $GITHUB_OUTPUT
# Setup dynamically the service route as server for swagger-ui, in order to be able to run all endpoints automatically from swagger-ui.
- name: Setup the service route for swagger-ui
env:
OPENAPI_ROUTE: ${{ steps.swagger.outputs.url }}
shell: bash
run: |
oc set env deployment -l app=games-store-service QUARKUS_SMALLRYE_OPENAPI_SERVERS=${{ env.OPENAPI_ROUTE }}
- name: Completed CD pipeline
shell: bash
run: |
echo "Successfully deployed version V${{ github.ref_name }} of games-store-service microservice to openshift cluster=> ${{ env.OPENSHIFT_SERVER }}!"