|
4 | 4 | paths-ignore: |
5 | 5 | - '**.md' |
6 | 6 | - '**.png' |
| 7 | +env: |
| 8 | + DOCKER_APP_IMAGE_NAME: "ghcr.io/hasadna/open-bus-stride-db/open-bus-stride-db" |
| 9 | + DOCKER_BACKUP_IMAGE_NAME: "ghcr.io/hasadna/open-bus-stride-db/open-bus-stride-db-backup" |
7 | 10 | jobs: |
8 | 11 | ci: |
9 | | - runs-on: ubuntu-20.04 |
| 12 | + runs-on: ubuntu-latest |
10 | 13 | steps: |
11 | | - - env: |
12 | | - DOCKER_APP_IMAGE_NAME: "ghcr.io/hasadna/open-bus-stride-db/open-bus-stride-db" |
13 | | - DOCKER_BACKUP_IMAGE_NAME: "ghcr.io/hasadna/open-bus-stride-db/open-bus-stride-db-backup" |
14 | | - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 14 | + - uses: actions/checkout@v6 |
| 15 | + - uses: docker/login-action@v3 |
| 16 | + with: |
| 17 | + registry: ghcr.io |
| 18 | + username: ${{ github.actor }} |
| 19 | + password: ${{ github.token }} |
| 20 | + - uses: docker/build-push-action@v6 |
| 21 | + with: |
| 22 | + push: true |
| 23 | + tags: | |
| 24 | + ${{ format('{0}:{1}', env.DOCKER_APP_IMAGE_NAME, github.sha) }} |
| 25 | + ${{ (github.event_name == 'push' && github.ref == 'refs/heads/main') && format('{0}:latest', env.DOCKER_APP_IMAGE_NAME) || '' }} |
| 26 | + cache-from: type=gha |
| 27 | + cache-to: type=gha,mode=max |
| 28 | + - uses: docker/build-push-action@v6 |
| 29 | + with: |
| 30 | + context: backup |
| 31 | + push: true |
| 32 | + tags: | |
| 33 | + ${{ format('{0}:{1}', env.DOCKER_BACKUP_IMAGE_NAME, github.sha) }} |
| 34 | + ${{ (github.event_name == 'push' && github.ref == 'refs/heads/main') && format('{0}:latest', env.DOCKER_BACKUP_IMAGE_NAME) || '' }} |
| 35 | + cache-from: type=gha |
| 36 | + cache-to: type=gha,mode=max |
| 37 | + - run: | |
| 38 | + set -euo pipefail |
| 39 | + docker run -e POSTGRES_PASSWORD=123456 -p 5432:5432 -v `pwd`/.data/db:/var/lib/postgresql/data -d postgres:13 |
| 40 | + sleep 5 |
| 41 | + docker run --network host -e SQLALCHEMY_URL=postgresql://postgres:123456@localhost ${DOCKER_APP_IMAGE_NAME}:${{ github.sha }} |
| 42 | + docker build -t docgen -f docgen.Dockerfile . |
| 43 | + docker run --network host -e SQLALCHEMY_URL=postgresql://postgres:123456@localhost \ |
| 44 | + -v "`pwd`/docgen_output:/output" \ |
| 45 | + --entrypoint python docgen bin/docgen.py /output |
| 46 | + git config user.name "open-bus-stride-db-ci" |
| 47 | + git config user.email "open-bus-stride-db-ci@localhost" |
| 48 | + if ! diff docgen_output/DATA_MODEL.md ./DATA_MODEL.md || ! diff docgen_output/dbschema.png ./dbschema.png; then |
| 49 | + cp -f docgen_output/DATA_MODEL.md ./DATA_MODEL.md |
| 50 | + cp -f docgen_output/dbschema.png ./dbschema.png |
| 51 | + git add ./DATA_MODEL.md && git add ./dbschema.png |
| 52 | + git commit -m "automatic update of the data model documentation" |
| 53 | + git push |
| 54 | + fi |
| 55 | + - if: ${{ github.ref == 'refs/heads/main' }} |
| 56 | + env: |
15 | 57 | HASADNA_K8S_DEPLOY_KEY: ${{ secrets.HASADNA_K8S_DEPLOY_KEY }} |
16 | 58 | SIRI_ETL_DEPLOY_KEY: ${{ secrets.SIRI_ETL_DEPLOY_KEY }} |
17 | 59 | STRIDE_API_DEPLOY_KEY: ${{ secrets.STRIDE_API_DEPLOY_KEY }} |
18 | 60 | STRIDE_ETL_DEPLOY_KEY: ${{ secrets.STRIDE_ETL_DEPLOY_KEY }} |
19 | 61 | run: | |
20 | | - curl -s https://raw.githubusercontent.com/OriHoch/uumpa-ci-toolbox/65a0704332e63d51f63981dbb25cd83682dc4078/bin/github_actions_install.sh \ |
21 | | - | bash -s 65a0704332e63d51f63981dbb25cd83682dc4078 OriHoch/uumpa-ci-toolbox &&\ |
22 | | - uci github actions self-checkout --config-user-name "open-bus-stride-db-ci" &&\ |
23 | | - uci github actions docker-login &&\ |
24 | | - uci docker build-cache \ |
25 | | - --cache-from "${DOCKER_APP_IMAGE_NAME}:latest" \ |
26 | | - -- -t app . &&\ |
27 | | - uci docker tag-push \ |
28 | | - --source-tag-name app \ |
29 | | - --push-tag-name "${DOCKER_APP_IMAGE_NAME}:${GITHUB_SHA}" &&\ |
30 | | - uci docker build-cache \ |
31 | | - --cache-from "${DOCKER_BACKUP_IMAGE_NAME}:latest" \ |
32 | | - -- -t backup backup &&\ |
33 | | - uci docker tag-push \ |
34 | | - --source-tag-name backup \ |
35 | | - --push-tag-name "${DOCKER_BACKUP_IMAGE_NAME}:${GITHUB_SHA}" &&\ |
36 | | - docker run -e POSTGRES_PASSWORD=123456 -p 5432:5432 -v `pwd`/.data/db:/var/lib/postgresql/data -d postgres:13 &&\ |
37 | | - sleep 5 &&\ |
38 | | - docker run --network host -e SQLALCHEMY_URL=postgresql://postgres:123456@localhost app &&\ |
39 | | - docker build -t docgen -f docgen.Dockerfile . &&\ |
40 | | - docker run --network host -e SQLALCHEMY_URL=postgresql://postgres:123456@localhost \ |
41 | | - -v "`pwd`/docgen_output:/output" \ |
42 | | - --entrypoint python docgen bin/docgen.py /output &&\ |
43 | | - if ! diff docgen_output/DATA_MODEL.md ./DATA_MODEL.md || ! diff docgen_output/dbschema.png ./dbschema.png; then |
44 | | - cp -f docgen_output/DATA_MODEL.md ./DATA_MODEL.md &&\ |
45 | | - cp -f docgen_output/dbschema.png ./dbschema.png &&\ |
46 | | - git add ./DATA_MODEL.md && git add ./dbschema.png &&\ |
47 | | - git commit -m "automatic update of the data model documentation" &&\ |
48 | | - git push |
49 | | - fi &&\ |
50 | | - if [ "$(uci github actions get-branch-name)" == "main" ]; then |
51 | | - uci docker tag-push \ |
52 | | - --source-tag-name app \ |
53 | | - --push-tag-name "${DOCKER_APP_IMAGE_NAME}:latest" &&\ |
54 | | - uci docker tag-push \ |
55 | | - --source-tag-name backup \ |
56 | | - --push-tag-name "${DOCKER_BACKUP_IMAGE_NAME}:latest" &&\ |
57 | | - if ! git log -1 --pretty=format:"%s" | grep -- --no-deploy; then |
58 | | - cd `mktemp -d` &&\ |
59 | | - echo "${HASADNA_K8S_DEPLOY_KEY}" > hasadna_k8s_deploy_key &&\ |
60 | | - chmod 400 hasadna_k8s_deploy_key &&\ |
61 | | - export GIT_SSH_COMMAND="ssh -i `pwd`/hasadna_k8s_deploy_key -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" &&\ |
62 | | - git clone git@github.com:hasadna/hasadna-k8s.git &&\ |
63 | | - cd hasadna-k8s &&\ |
64 | | - python update_yaml.py '{"strideDbAppImage":"'"${DOCKER_APP_IMAGE_NAME}:${GITHUB_SHA}"'"}' apps/openbus/values-hasadna-auto-updated.yaml &&\ |
65 | | - git config --global user.name "Open Bus Stride DB CI" &&\ |
66 | | - git config --global user.email "open-bus-stride-db-ci@localhost" &&\ |
67 | | - git add apps/openbus/values-hasadna-auto-updated.yaml && git commit -m "automatic update of open bus stride db" &&\ |
68 | | - git push origin master &&\ |
69 | | - echo "${SIRI_ETL_DEPLOY_KEY}" > siri_etl_deploy_key &&\ |
70 | | - chmod 400 siri_etl_deploy_key &&\ |
71 | | - export GIT_SSH_COMMAND="ssh -i `pwd`/siri_etl_deploy_key -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" &&\ |
72 | | - git clone git@github.com:hasadna/open-bus-siri-etl.git &&\ |
73 | | - cd open-bus-siri-etl &&\ |
74 | | - bin/update_stride_db_dependencies.py "${GITHUB_SHA}" &&\ |
75 | | - git commit -m "automatic update of open bus stride db dependencies" &&\ |
76 | | - git push origin main &&\ |
77 | | - echo "${STRIDE_API_DEPLOY_KEY}" > stride_api_deploy_key &&\ |
78 | | - chmod 400 stride_api_deploy_key &&\ |
79 | | - export GIT_SSH_COMMAND="ssh -i `pwd`/stride_api_deploy_key -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" &&\ |
80 | | - git clone git@github.com:hasadna/open-bus-stride-api.git &&\ |
81 | | - cd open-bus-stride-api &&\ |
82 | | - bin/update_stride_db_dependencies.py "${GITHUB_SHA}" &&\ |
83 | | - git commit -m "automatic update of open bus stride db dependencies" &&\ |
84 | | - git push origin main &&\ |
85 | | - echo "${STRIDE_ETL_DEPLOY_KEY}" > stride_etl_deploy_key &&\ |
86 | | - chmod 400 stride_etl_deploy_key &&\ |
87 | | - export GIT_SSH_COMMAND="ssh -i `pwd`/stride_etl_deploy_key -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" &&\ |
88 | | - git clone git@github.com:hasadna/open-bus-stride-etl.git &&\ |
89 | | - cd open-bus-stride-etl &&\ |
90 | | - echo "${GITHUB_SHA}" > stride-db-latest-commit.txt &&\ |
91 | | - git add stride-db-latest-commit.txt &&\ |
92 | | - git commit -m "automatic update of open bus stride db dependencies" &&\ |
| 62 | + set -euo pipefail |
| 63 | + if ! git log -1 --pretty=format:"%s" | grep -- --no-deploy; then |
| 64 | + cd `mktemp -d` |
| 65 | + echo "${HASADNA_K8S_DEPLOY_KEY}" > hasadna_k8s_deploy_key |
| 66 | + chmod 400 hasadna_k8s_deploy_key |
| 67 | + export GIT_SSH_COMMAND="ssh -i `pwd`/hasadna_k8s_deploy_key -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" |
| 68 | + git clone git@github.com:hasadna/hasadna-k8s.git |
| 69 | + cd hasadna-k8s |
| 70 | + python update_yaml.py '{"strideDbAppImage":"'"${DOCKER_APP_IMAGE_NAME}:${GITHUB_SHA}"'"}' apps/openbus/values-hasadna-auto-updated.yaml |
| 71 | + git config --global user.name "Open Bus Stride DB CI" |
| 72 | + git config --global user.email "open-bus-stride-db-ci@localhost" |
| 73 | + git add apps/openbus/values-hasadna-auto-updated.yaml && git commit -m "automatic update of open bus stride db" |
| 74 | + git push origin master |
| 75 | + echo "${SIRI_ETL_DEPLOY_KEY}" > siri_etl_deploy_key |
| 76 | + chmod 400 siri_etl_deploy_key |
| 77 | + export GIT_SSH_COMMAND="ssh -i `pwd`/siri_etl_deploy_key -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" |
| 78 | + git clone git@github.com:hasadna/open-bus-siri-etl.git |
| 79 | + cd open-bus-siri-etl |
| 80 | + bin/update_stride_db_dependencies.py "${GITHUB_SHA}" |
| 81 | + git commit -m "automatic update of open bus stride db dependencies" |
| 82 | + git push origin main |
| 83 | + echo "${STRIDE_API_DEPLOY_KEY}" > stride_api_deploy_key |
| 84 | + chmod 400 stride_api_deploy_key |
| 85 | + export GIT_SSH_COMMAND="ssh -i `pwd`/stride_api_deploy_key -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" |
| 86 | + git clone git@github.com:hasadna/open-bus-stride-api.git |
| 87 | + cd open-bus-stride-api |
| 88 | + bin/update_stride_db_dependencies.py "${GITHUB_SHA}" |
| 89 | + git commit -m "automatic update of open bus stride db dependencies" |
| 90 | + git push origin main |
| 91 | + echo "${STRIDE_ETL_DEPLOY_KEY}" > stride_etl_deploy_key |
| 92 | + chmod 400 stride_etl_deploy_key |
| 93 | + export GIT_SSH_COMMAND="ssh -i `pwd`/stride_etl_deploy_key -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" |
| 94 | + git clone git@github.com:hasadna/open-bus-stride-etl.git |
| 95 | + cd open-bus-stride-etl |
| 96 | + echo "${GITHUB_SHA}" > stride-db-latest-commit.txt |
| 97 | + git add stride-db-latest-commit.txt |
| 98 | + git commit -m "automatic update of open bus stride db dependencies" |
93 | 99 | git push origin main |
94 | 100 | fi |
95 | | - fi |
|
0 commit comments