-
Notifications
You must be signed in to change notification settings - Fork 0
215 lines (191 loc) · 7.35 KB
/
push.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
name: Keboola Component Build & Deploy Pipeline
on: [ push ]
concurrency: ci-${{ github.ref }} # to avoid tag collisions in the ECR
env:
# repository variables:
KBC_DEVELOPERPORTAL_APP: "kds-team.ex-kafka-consumer" # replace with your component id
KBC_DEVELOPERPORTAL_VENDOR: "kds-team" # replace with your vendor
DOCKERHUB_USER: ${{ secrets.DOCKERHUB_USER }}
KBC_DEVELOPERPORTAL_USERNAME: ${{ vars.KBC_DEVELOPERPORTAL_USERNAME }}
# repository secrets:
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} # recommended for pushing to ECR
KBC_DEVELOPERPORTAL_PASSWORD: ${{ secrets.KBC_DEVELOPERPORTAL_PASSWORD }}
# (Optional) Test KBC project: https://connection.keboola.com/admin/projects/0000
KBC_TEST_PROJECT_CONFIGS: "" # space separated list of config ids
KBC_STORAGE_TOKEN: ${{ secrets.KBC_STORAGE_TOKEN }} # required for running KBC tests
jobs:
push_event_info:
name: Push Event Info
runs-on: ubuntu-latest
outputs:
app_image_tag: ${{ steps.tag.outputs.app_image_tag }}
is_semantic_tag: ${{ steps.tag.outputs.is_semantic_tag }}
is_default_branch: ${{ steps.default_branch.outputs.is_default_branch }}
is_deploy_ready: ${{ steps.deploy_ready.outputs.is_deploy_ready }}
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Fetch all branches from remote repository
run: git fetch --prune --unshallow --tags -f
- name: Get current branch name
id: current_branch
run: |
if [[ ${{ github.ref }} != "refs/tags/"* ]]; then
branch_name=${{ github.ref_name }}
echo "branch_name=$branch_name" | tee -a $GITHUB_OUTPUT
else
raw=$(git branch -r --contains ${{ github.ref }})
branch="$(echo ${raw//origin\//} | tr -d '\n')"
echo "branch_name=$branch" | tee -a $GITHUB_OUTPUT
fi
- name: Is current branch the default branch
id: default_branch
run: |
echo "default_branch='${{ github.event.repository.default_branch }}'"
if [ "${{ github.event.repository.default_branch }}" = "${{ steps.current_branch.outputs.branch_name }}" ]; then
echo "is_default_branch=true" | tee -a $GITHUB_OUTPUT
else
echo "is_default_branch=false" | tee -a $GITHUB_OUTPUT
fi
- name: Set image tag
id: tag
run: |
TAG="${GITHUB_REF##*/}"
IS_SEMANTIC_TAG=$(echo "$TAG" | grep -q '^v\?[0-9]\+\.[0-9]\+\.[0-9]\+$' && echo true || echo false)
echo "is_semantic_tag=$IS_SEMANTIC_TAG" | tee -a $GITHUB_OUTPUT
echo "app_image_tag=$TAG" | tee -a $GITHUB_OUTPUT
- name: Deploy-Ready check
id: deploy_ready
run: |
if [[ "${{ steps.default_branch.outputs.is_default_branch }}" == "true" \
&& "${{ github.ref }}" == refs/tags/* \
&& "${{ steps.tag.outputs.is_semantic_tag }}" == "true" ]]; then
echo "is_deploy_ready=true" | tee -a $GITHUB_OUTPUT
else
echo "is_deploy_ready=false" | tee -a $GITHUB_OUTPUT
fi
build:
name: Docker Image Build
runs-on: ubuntu-latest
needs:
- push_event_info
env:
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
tags: ${{ env.KBC_DEVELOPERPORTAL_APP }}:latest
outputs: type=docker,dest=/tmp/${{ env.KBC_DEVELOPERPORTAL_APP }}.tar
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ env.KBC_DEVELOPERPORTAL_APP }}
path: /tmp/${{ env.KBC_DEVELOPERPORTAL_APP }}.tar
tests:
name: Run Tests
runs-on: ubuntu-latest
needs:
- push_event_info
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Run Tests
run: |
docker compose build test
docker compose run test
tests-kbc:
name: Run KBC Tests
needs:
- push_event_info
- build
runs-on: ubuntu-latest
steps:
- name: Set up environment variables
run: |
echo "KBC_TEST_PROJECT_CONFIGS=${KBC_TEST_PROJECT_CONFIGS}" >> $GITHUB_ENV
echo "KBC_STORAGE_TOKEN=${{ secrets.KBC_STORAGE_TOKEN }}" >> $GITHUB_ENV
- name: Run KBC test jobs
if: env.KBC_TEST_PROJECT_CONFIGS != '' && env.KBC_STORAGE_TOKEN != ''
uses: keboola/action-run-configs-parallel@master
with:
token: ${{ secrets.KBC_STORAGE_TOKEN }}
componentId: ${{ env.KBC_DEVELOPERPORTAL_APP }}
tag: ${{ needs.push_event_info.outputs.app_image_tag }}
configs: ${{ env.KBC_TEST_PROJECT_CONFIGS }}
push:
name: Docker Image Push
runs-on: ubuntu-latest
needs:
- push_event_info
- tests
- tests-kbc
env:
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: ${{ env.KBC_DEVELOPERPORTAL_APP }}
path: /tmp
- name: Load Image & Run Tests
run: |
docker load --input /tmp/${{ env.KBC_DEVELOPERPORTAL_APP }}.tar
docker image ls -a
- name: Docker login
if: env.DOCKERHUB_TOKEN
run: docker login --username "${{ env.DOCKERHUB_USER }}" --password "${{ env.DOCKERHUB_TOKEN }}"
- name: Push image to ECR
uses: keboola/action-push-to-ecr@master
with:
vendor: ${{ env.KBC_DEVELOPERPORTAL_VENDOR }}
app_id: ${{ env.KBC_DEVELOPERPORTAL_APP }}
username: ${{ env.KBC_DEVELOPERPORTAL_USERNAME }}
password: ${{ secrets.KBC_DEVELOPERPORTAL_PASSWORD }}
tag: ${{ needs.push_event_info.outputs.app_image_tag }}
push_latest: ${{ needs.push_event_info.outputs.is_deploy_ready }}
source_image: ${{ env.KBC_DEVELOPERPORTAL_APP }}
deploy:
name: Deploy to KBC
env:
KBC_DEVELOPERPORTAL_PASSWORD: ${{ secrets.KBC_DEVELOPERPORTAL_PASSWORD }}
needs:
- push_event_info
- build
- push
if: needs.push_event_info.outputs.is_deploy_ready == 'true'
runs-on: ubuntu-latest
steps:
- name: Set Developer Portal Tag
uses: keboola/action-set-tag-developer-portal@master
with:
vendor: ${{ env.KBC_DEVELOPERPORTAL_VENDOR }}
app_id: ${{ env.KBC_DEVELOPERPORTAL_APP }}
username: ${{ env.KBC_DEVELOPERPORTAL_USERNAME }}
password: ${{ secrets.KBC_DEVELOPERPORTAL_PASSWORD }}
tag: ${{ needs.push_event_info.outputs.app_image_tag }}
update_developer_portal_properties:
name: Developer Portal Properties Update
env:
KBC_DEVELOPERPORTAL_PASSWORD: ${{ secrets.KBC_DEVELOPERPORTAL_PASSWORD }}
needs:
- push_event_info
- build
- push
runs-on: ubuntu-latest
if: needs.push_event_info.outputs.is_deploy_ready == 'true'
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Update developer portal properties
run: |
chmod +x scripts/developer_portal/*.sh
scripts/developer_portal/update_properties.sh