-
Notifications
You must be signed in to change notification settings - Fork 7
71 lines (71 loc) · 3.19 KB
/
ci.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
name: CI
on:
push:
jobs:
ci:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- env:
ETL_IMAGE_NAME: "ghcr.io/data-for-change/anyway-etl/anyway-etl"
NGINX_IMAGE_NAME: "ghcr.io/data-for-change/anyway-etl/anyway-etl-nginx"
AIRFLOW_IMAGE_NAME: "ghcr.io/data-for-change/anyway-etl/anyway-etl-airflow"
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DFC_IAC_DEPLOY_KEY: ${{ secrets.DFC_IAC_DEPLOY_KEY }}
run: |
if [[ "${GITHUB_REF}" =~ ^refs/tags/.* ]]; then
TAG_NAME="${GITHUB_REF/refs\/tags\//}"
else
TAG_NAME=""
fi
echo "${GITHUB_TOKEN}" | docker login ghcr.io -u data-for-change --password-stdin &&\
if docker pull "${ETL_IMAGE_NAME}:latest"; then
CACHE_FROM_ARG="--cache-from ${ETL_IMAGE_NAME}:latest"
else
CACHE_FROM_ARG=""
fi &&\
docker build $CACHE_FROM_ARG -t etl . &&\
docker tag etl "${ETL_IMAGE_NAME}:${GITHUB_SHA}" &&\
docker push "${ETL_IMAGE_NAME}:${GITHUB_SHA}" &&\
if docker pull "${AIRFLOW_IMAGE_NAME}:latest"; then
CACHE_FROM_ARG="--cache-from ${AIRFLOW_IMAGE_NAME}:latest"
else
CACHE_FROM_ARG=""
fi &&\
docker build $CACHE_FROM_ARG -t airflow airflow_server &&\
docker tag airflow "${AIRFLOW_IMAGE_NAME}:${GITHUB_SHA}" &&\
docker push "${AIRFLOW_IMAGE_NAME}:${GITHUB_SHA}" &&\
if docker pull "${NGINX_IMAGE_NAME}:latest"; then
CACHE_FROM_ARG="--cache-from ${NGINX_IMAGE_NAME}:latest"
else
CACHE_FROM_ARG=""
fi &&\
docker build $CACHE_FROM_ARG -t aenginx nginx &&\
docker tag aenginx "${NGINX_IMAGE_NAME}:${GITHUB_SHA}" &&\
docker push "${NGINX_IMAGE_NAME}:${GITHUB_SHA}" &&\
if [ "${GITHUB_REF}" == "refs/heads/main" ]; then
PUSH_TAG=latest
elif [ "${TAG_NAME}" != "" ]; then
PUSH_TAG="${TAG_NAME}"
fi &&\
if [ "${PUSH_TAG}" != "" ]; then
docker tag etl "${ETL_IMAGE_NAME}:${PUSH_TAG}" &&\
docker push "${ETL_IMAGE_NAME}:${PUSH_TAG}" &&\
docker tag airflow "${AIRFLOW_IMAGE_NAME}:${PUSH_TAG}" &&\
docker push "${AIRFLOW_IMAGE_NAME}:${PUSH_TAG}" &&\
docker tag aenginx "${NGINX_IMAGE_NAME}:${PUSH_TAG}" &&\
docker push "${NGINX_IMAGE_NAME}:${PUSH_TAG}" &&\
if [ "${TAG_NAME}" != "" ]; then
cd `mktemp -d` &&\
echo "${DFC_IAC_DEPLOY_KEY}" > dfc_iac_deploy_key &&\
chmod 400 dfc_iac_deploy_key &&\
export GIT_SSH_COMMAND="ssh -i `pwd`/dfc_iac_deploy_key -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" &&\
git clone git@github.com:data-for-change/dfc-iac.git &&\
cd dfc-iac &&\
git config --global user.name "Anyway ETL CI" &&\
git config --global user.email "anyway-etl-ci@localhost" &&\
bin/update_anyway_env.py '{"etlNginxImage":"'"${NGINX_IMAGE_NAME}:${TAG_NAME}"'","airflowImage":"'"${AIRFLOW_IMAGE_NAME}:${TAG_NAME}"'"}' &&\
git add apps/anyway/.env && git commit -m "automatic update of prod etl anyway" &&\
git push origin main
fi
fi