-
Notifications
You must be signed in to change notification settings - Fork 0
118 lines (104 loc) · 4.77 KB
/
build.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
name: Build container image
on:
schedule:
- cron: "*/30 * * * *"
workflow_dispatch:
env:
BRANCH_NAME: master
IMAGE_NAME: ghcr.io/ternaustralia/airflow
DOCKER_IMAGE_NAME: ternau/airflow
# Don't perform git prompt .
# This will prevent `act` from hanging when running locally with a git error.
# See https://github.com/nektos/act/issues/977#issuecomment-1037608650 for more information.
GIT_TERMINAL_PROMPT: "0"
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout the repo
uses: actions/checkout@v3
- name: Setup git
run: |
git config --global user.name github-actions
git config --global user.email [email protected]
git remote set-url origin https://${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY.git
- name: Set current commit hash environment variable
id: commit-hash
run: echo "CURRENT_COMMIT_HASH=$(cat CURRENT_COMMIT_HASH)" >> $GITHUB_ENV
- name: Fetch upstream
run: |
git remote add --mirror=fetch upstream https://${{ secrets.BITBUCKET_USERNAME }}:${{ secrets.BITBUCKET_APP_PASSWORD }}@bitbucket.org/terndatateam/docker-airflow.git
git fetch upstream
git checkout ${{ env.BRANCH_NAME }}
- name: Set upstream commit hash
run: |
echo "UPSTREAM_COMMIT_HASH=$(git rev-parse HEAD)" >> $GITHUB_ENV
echo "UPSTREAM_SHORT_COMMIT_HASH=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
- name: Echo current and upstream commit hash
run: |
echo '::echo::on'
echo "Current commit hash: $CURRENT_COMMIT_HASH Upstream commit hash: $UPSTREAM_COMMIT_HASH"
echo '::echo::off'
- name: Update commit hash
if: ${{ env.CURRENT_COMMIT_HASH != env.UPSTREAM_COMMIT_HASH }}
run: |
echo '::echo::on'
echo "Current commit hash: $CURRENT_COMMIT_HASH Upstream commit hash: $UPSTREAM_COMMIT_HASH"
git checkout main
rm CURRENT_COMMIT_HASH
echo $UPSTREAM_COMMIT_HASH >> CURRENT_COMMIT_HASH
git add CURRENT_COMMIT_HASH
git commit -m "Update CURRENT_COMMIT_HASH value"
git push
echo "CURRENT_COMMIT_HASH has been updated to $(cat CURRENT_COMMIT_HASH)"
echo '::echo::off'
- name: Change to upstream branch
if: ${{ env.CURRENT_COMMIT_HASH != env.UPSTREAM_COMMIT_HASH }}
run: git checkout ${{ env.BRANCH_NAME }}
- name: Build local image
if: ${{ env.CURRENT_COMMIT_HASH != env.UPSTREAM_COMMIT_HASH }}
run: docker build -t local-image .
- name: Get Airflow version
if: ${{ env.CURRENT_COMMIT_HASH != env.UPSTREAM_COMMIT_HASH }}
id: airflow-version
run: echo "VERSION=$(docker run --rm --entrypoint=/bin/bash local-image -c 'airflow version')" >> $GITHUB_OUTPUT
- name: Echo Airflow version
if: ${{ env.CURRENT_COMMIT_HASH != env.UPSTREAM_COMMIT_HASH }}
run: |
echo '::echo::on'
echo "Airflow version is ${{ steps.airflow-version.outputs.VERSION }}"
- name: Set up QEMU
if: ${{ env.CURRENT_COMMIT_HASH != env.UPSTREAM_COMMIT_HASH }}
uses: docker/setup-qemu-action@v2
- name: Set up and use Docker Buildx
if: ${{ env.CURRENT_COMMIT_HASH != env.UPSTREAM_COMMIT_HASH }}
uses: docker/setup-buildx-action@v2
- name: Log in to GitHub Container Registry
if: ${{ env.CURRENT_COMMIT_HASH != env.UPSTREAM_COMMIT_HASH }}
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build container image and push
if: ${{ env.CURRENT_COMMIT_HASH != env.UPSTREAM_COMMIT_HASH }}
uses: docker/build-push-action@v3
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ env.IMAGE_NAME }}:latest,${{ env.IMAGE_NAME }}:${{ steps.airflow-version.outputs.VERSION }},${{ env.IMAGE_NAME }}:${{ steps.airflow-version.outputs.VERSION }}-build.${{ env.UPSTREAM_SHORT_COMMIT_HASH }}
- name: Log in to Docker Hub Registry
if: ${{ env.CURRENT_COMMIT_HASH != env.UPSTREAM_COMMIT_HASH }}
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}
- name: Build container image and push
if: ${{ env.CURRENT_COMMIT_HASH != env.UPSTREAM_COMMIT_HASH }}
uses: docker/build-push-action@v3
with:
context: .
platforms: linux/arm64
push: true
tags: ${{ env.DOCKER_IMAGE_NAME }}:latest-arm64,${{ env.DOCKER_IMAGE_NAME }}:${{ steps.airflow-version.outputs.VERSION }}-arm64.${{ env.UPSTREAM_SHORT_COMMIT_HASH }}