-
Notifications
You must be signed in to change notification settings - Fork 1
118 lines (101 loc) · 3.59 KB
/
api-build-deploy.yaml
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
name: Build and Deploy API
on:
push:
branches: [ main ]
paths:
- "api/**"
workflow_dispatch:
jobs:
build-tag-push:
name: Build, Tag, Push to Artifactory
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Log In to Docker
run: |
docker login ${{ secrets.ARTIFACTORY_URL }} -u ${{ secrets.ARTIFACTORY_USERNAME }} -p ${{ secrets.ARTIFACTORY_PASSWORD }}
- name: Copy env.template
run: |
cp .env.template .env
- name: Build API Image
run: |
docker-compose build spr-api
- name: List Docker Images
run: |
docker images
- name: Tag Image
run: |
docker tag citz-imb-staff-purchasing-reimbursement_spr-api ${{ secrets.ARTIFACTORY_URL }}/${{ secrets.IMAGE_REPOSITORY }}/spr-api:latest
- name: Push Image
run: |
docker push ${{ secrets.ARTIFACTORY_URL }}/${{ secrets.IMAGE_REPOSITORY }}/spr-api:latest
deploy:
name: Deploy to OpenShift
runs-on: ubuntu-latest
needs: [ build-tag-push ]
steps:
- name: Checkout Repo
uses: actions/checkout@v3
- name: Login to Openshift
uses: redhat-actions/oc-login@v1
env:
OPENSHIFT_USER: github-actions
OPENSHIFT_NAMESPACE: ${{ secrets.OPENSHIFT_NAMESPACE }}
with:
openshift_server_url: ${{ secrets.OPENSHIFT_SERVER_URL }}
openshift_token: ${{ secrets.OPENSHIFT_TOKEN }}
namespace: ${{ secrets.OPENSHIFT_NAMESPACE }}
- name: Apply DeploymentConfig
env:
OPENSHIFT_NAMESPACE: ${{ secrets.OPENSHIFT_NAMESPACE }}
APPLICATION_NAME: staff-purchase-reimbursement
CONTAINER_NAME: spr-api
DEPLOYMENT_CONFIG: api-dc-template.yaml
IMAGE_REPOSITORY: ${{ secrets.IMAGE_REPOSITORY }}
ARTIFACTORY_URL: ${{ secrets.ARTIFACTORY_URL }}
run: |
./.github/helpers/deploy.sh
- name: Rollout Pod
continue-on-error: true
run: |
oc rollout latest dc/spr-api
healthcheck:
name: Determine Rollout Success
runs-on: ubuntu-latest
needs: [ deploy ]
steps:
- name: Login to Openshift
uses: redhat-actions/oc-login@v1
env:
OPENSHIFT_USER: github-actions
OPENSHIFT_NAMESPACE: ${{ secrets.OPENSHIFT_NAMESPACE }}
with:
openshift_server_url: ${{ secrets.OPENSHIFT_SERVER_URL }}
openshift_token: ${{ secrets.OPENSHIFT_TOKEN }}
namespace: ${{ secrets.OPENSHIFT_NAMESPACE }}
- name: Check Status of Rollout
run: |
oc rollout status -n ${{ secrets.OPENSHIFT_NAMESPACE }} dc/spr-api --watch
cleanup:
name: Clean Up Old Objects
runs-on: ubuntu-latest
needs: [ healthcheck ]
steps:
- name: Login to Openshift
uses: redhat-actions/oc-login@v1
env:
OPENSHIFT_USER: github-actions
OPENSHIFT_NAMESPACE: ${{ secrets.OPENSHIFT_NAMESPACE }}
with:
openshift_server_url: ${{ secrets.OPENSHIFT_SERVER_URL }}
openshift_token: ${{ secrets.OPENSHIFT_TOKEN }}
namespace: ${{ secrets.OPENSHIFT_NAMESPACE }}
- name: Remove old pod objects
run: |
oc delete pod --namespace=${{ secrets.OPENSHIFT_NAMESPACE }} --field-selector status.phase=Succeeded
- name: Remove old replication controllers
run: |
oc delete rc --namespace=${{ secrets.OPENSHIFT_NAMESPACE }} --field-selector status.replicas=0