-
Notifications
You must be signed in to change notification settings - Fork 2
39 lines (39 loc) · 1.85 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
name: CI
on:
push:
jobs:
ci:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- env:
DOCKER_APP_IMAGE_NAME: "ghcr.io/hasadna/open-knesset-backend/open-knesset-backend"
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DEPLOY_KEY: ${{ secrets.KNESSET_DATA_K8S_DEPLOY_KEY }}
run: |
echo "${GITHUB_TOKEN}" | docker login ghcr.io -u hasadna --password-stdin &&\
if docker pull "${DOCKER_APP_IMAGE_NAME}:latest"; then
CACHE_FROM_ARG="--cache-from ${DOCKER_APP_IMAGE_NAME}:latest"
else
CACHE_FROM_ARG=""
fi &&\
docker build $CACHE_FROM_ARG --build-arg VERSION=${GITHUB_SHA} -t app . &&\
docker tag app "${DOCKER_APP_IMAGE_NAME}:${GITHUB_SHA}" &&\
docker push "${DOCKER_APP_IMAGE_NAME}:${GITHUB_SHA}" &&\
if [ "${GITHUB_REF}" == "refs/heads/main" ]; then
docker tag app "${DOCKER_APP_IMAGE_NAME}:latest" &&\
docker push "${DOCKER_APP_IMAGE_NAME}:latest" &&\
if ! git log -1 --pretty=format:"%s" | grep -- --no-deploy; then
cd `mktemp -d` &&\
echo "${DEPLOY_KEY}" > deploy_key &&\
chmod 400 deploy_key &&\
export GIT_SSH_COMMAND="ssh -i `pwd`/deploy_key -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" &&\
git clone [email protected]:OriHoch/knesset-data-k8s.git &&\
cd knesset-data-k8s &&\
python update_yaml.py '{"backendImage":"'"${DOCKER_APP_IMAGE_NAME}:${GITHUB_SHA}"'"}' apps/site/values-auto-updated.yaml &&\
git config --global user.name "Open Knesset Backend CI" &&\
git config --global user.email "open-knesset-backend-ci@localhost" &&\
git add apps/site/values-auto-updated.yaml && git commit -m "automatic update of open knesset backend" &&\
git push origin master
fi
fi