-
Notifications
You must be signed in to change notification settings - Fork 1
142 lines (126 loc) · 4.85 KB
/
build-deploy.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
name: Build
on:
workflow_dispatch:
pull_request:
types:
- closed
branches:
- main
- dev
env:
SERVICE_NAME: rpkm67-frontend
IMAGE_NAME: ghcr.io/${{ github.repository }}
IMAGE_TAG_DEV: <WILL_BE_SET>
IMAGE_TAG_PROD: <WILL_BE_SET>
jobs:
build:
name: Build
runs-on: ubuntu-latest
if: github.event.pull_request.merged == true || github.event_name == 'workflow_dispatch'
outputs:
IMAGE_TAG_DEV: ${{ steps.tag_action.outputs.new_tag }}-dev
IMAGE_TAG_PROD: ${{ steps.tag_action.outputs.new_tag }}-prod
permissions:
contents: write
packages: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: '0'
- name: Bump version and push tag
uses: anothrNick/github-tag-action@1.64.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
WITH_V: true
RELEASE_BRANCHES: dev
DEFAULT_BUMP: patch
id: tag_action
- name: Set IMAGE_TAG
run: |
echo "IMAGE_TAG_DEV=${{ steps.tag_action.outputs.new_tag }}-dev" >> $GITHUB_ENV
echo "IMAGE_TAG_PROD=${{ steps.tag_action.outputs.new_tag }}-prod" >> $GITHUB_ENV
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Log in to the Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ github.token }}
- name: Build and Push Docker Image (DEV)
uses: docker/build-push-action@v3
with:
push: true
tags: ${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG_DEV }},${{ env.IMAGE_NAME }}:latest
cache-from: type=registry,ref=${{ env.IMAGE_NAME }}:buildcache
cache-to: type=registry,ref=${{ env.IMAGE_NAME }}:buildcache,mode=max
build-args: |
APP_ENV=development
API_BASE_URL=${{ vars.DEV_API_BASE_URL }}
BAAN_ANNOUCE_DATE=${{ vars.DEV_BAAN_ANNOUCE_DATE }}
CLOSED_BAAN_SELECTION_DATE=${{ vars.DEV_CLOSED_BAAN_SELECTION_DATE }}
FIRST_DATE_DATE=${{ vars.DEV_FIRST_DATE_DATE }}
FRESHY_NIGHT_DATE=${{ vars.DEV_FRESHY_NIGHT_DATE }}
FRESHY_NIGHT_EVENT=${{ vars.DEV_FRESHY_NIGHT_EVENT }}
RPKM_DAY_1=${{ vars.DEV_RPKM_DAY_1 }}
RPKM_DAY_2=${{ vars.DEV_RPKM_DAY_2 }}
RUP_PEUN_DATE=${{ vars.DEV_RUP_PEUN_DATE }}
- name: Build and Push Docker Image (PROD)
uses: docker/build-push-action@v3
if: github.ref == 'refs/heads/main'
with:
push: true
tags: ${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG_PROD }},${{ env.IMAGE_NAME }}:latest
cache-from: type=registry,ref=${{ env.IMAGE_NAME }}:buildcache
cache-to: type=registry,ref=${{ env.IMAGE_NAME }}:buildcache,mode=max
build-args: |
APP_ENV=production
API_BASE_URL=${{ vars.PROD_API_BASE_URL }}
BAAN_ANNOUCE_DATE=${{ vars.PROD_BAAN_ANNOUCE_DATE }}
CLOSED_BAAN_SELECTION_DATE=${{ vars.PROD_CLOSED_BAAN_SELECTION_DATE }}
FIRST_DATE_DATE=${{ vars.PROD_FIRST_DATE_DATE }}
FRESHY_NIGHT_DATE=${{ vars.PROD_FRESHY_NIGHT_DATE }}
FRESHY_NIGHT_EVENT=${{ vars.PROD_FRESHY_NIGHT_EVENT }}
RPKM_DAY_1=${{ vars.PROD_RPKM_DAY_1 }}
RPKM_DAY_2=${{ vars.PROD_RPKM_DAY_2 }}
RUP_PEUN_DATE=${{ vars.PROD_RUP_PEUN_DATE }}
send_message_dev:
needs: build
uses: ./.github/workflows/send-message.yml
secrets: inherit
with:
IMAGE_TAG: ${{ needs.build.outputs.IMAGE_TAG_DEV }}
send_message_prod:
if: github.ref == 'refs/heads/main'
needs: build
uses: ./.github/workflows/send-message.yml
secrets: inherit
with:
IMAGE_TAG: ${{ needs.build.outputs.IMAGE_TAG_PROD }}
cd:
name: Continuous Deployment
needs: build
runs-on: ubuntu-latest
env:
IMAGE_TAG_DEV: ${{ needs.build.outputs.IMAGE_TAG_DEV }}
IMAGE_TAG_PROD: ${{ needs.build.outputs.IMAGE_TAG_PROD }}
steps:
- name: Checkout DevOps repository
uses: actions/checkout@v4
with:
repository: isd-sgcu/rpkm67-devops
token: ${{ secrets.RPKM67_DEVOPS_TOKEN }}
- name: Update image tag in dev
uses: mikefarah/yq@master
with:
cmd: yq -i '.[0].value = "${{ env.IMAGE_NAME }}:" + strenv(IMAGE_TAG_DEV)' isd/${{ env.SERVICE_NAME }}/deployment.yaml
- name: Update image tag in prod
uses: mikefarah/yq@master
if: github.ref == 'refs/heads/main'
with:
cmd: yq -i '.[0].value = "${{ env.IMAGE_NAME }}:" + strenv(IMAGE_TAG_PROD)' prod/${{ env.SERVICE_NAME }}/deployment.yaml
- name: Commit & Push changes
uses: actions-js/push@v1.4
with:
repository: isd-sgcu/rpkm67-devops
github_token: ${{ secrets.RPKM67_DEVOPS_TOKEN }}