|
| 1 | +name: Build and Push Docker Image for Airflow |
| 2 | + |
| 3 | +on: |
| 4 | + release: |
| 5 | + type: [published] |
| 6 | + #trigger on each commit of each branch and push with latest tag |
| 7 | + push : |
| 8 | + pull_request: |
| 9 | + paths: |
| 10 | + - 'pyproject.toml' |
| 11 | + - './docker/**' |
| 12 | + - '.github/workflows/**' |
| 13 | + |
| 14 | +env: |
| 15 | + REGISTRY: ghcr.io |
| 16 | + |
| 17 | +jobs: |
| 18 | + build-image: |
| 19 | + runs-on: ubuntu-latest |
| 20 | + #if: github.ref != 'refs/heads/main' |
| 21 | + permissions: |
| 22 | + contents: read |
| 23 | + packages: write |
| 24 | + |
| 25 | + steps: |
| 26 | + # https://github.com/actions/checkout |
| 27 | + - name: checkout repository |
| 28 | + uses: actions/checkout@v4 |
| 29 | + |
| 30 | + - name: lowercase image name |
| 31 | + run: | |
| 32 | + echo "IMAGE_NAME=${GITHUB_REPOSITORY,,}-airflow" >> ${GITHUB_ENV} |
| 33 | +
|
| 34 | + # https://github.com/docker/setup-qemu-action |
| 35 | + - name: Set up QEMU |
| 36 | + uses: docker/setup-qemu-action@v3.0.0 |
| 37 | + |
| 38 | + # https://github.com/docker/setup-buildx-action |
| 39 | + - name: Set up Docker Buildx |
| 40 | + id: buildx |
| 41 | + uses: docker/setup-buildx-action@v3.0.0 |
| 42 | + |
| 43 | + - name: Get current release version |
| 44 | + id: release-version |
| 45 | + run: | |
| 46 | + version=$(grep -E '^version += +' pyproject.toml | sed -E 's/.*= +//' | sed "s/['\"]//g") |
| 47 | + echo "version=${version}" >> $GITHUB_OUTPUT |
| 48 | + echo "version_build=${version}_"$(git rev-parse --short "$GITHUB_SHA") >> $GITHUB_OUTPUT |
| 49 | +
|
| 50 | + # https://github.com/docker/build-push-action |
| 51 | + - name: Build Docker image |
| 52 | + uses: docker/build-push-action@v5.0.0 |
| 53 | + with: |
| 54 | + context: . |
| 55 | + platforms: linux/amd64 |
| 56 | + file: tools/images/Dockerfile-airflow |
| 57 | + push: false |
| 58 | + tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.release-version.outputs.version_build }} |
| 59 | + build-args: PLATFORM=cu124 |
| 60 | + outputs: type=image,annotation-index.org.opencontainers.image.description=Run a Graph Neural Network. |
| 61 | + |
| 62 | + push-image: |
| 63 | + runs-on: ubuntu-latest |
| 64 | + #if: github.ref == 'refs/heads/main' |
| 65 | + permissions: |
| 66 | + contents: read |
| 67 | + packages: write |
| 68 | + |
| 69 | + steps: |
| 70 | + # https://github.com/actions/checkout |
| 71 | + - name: checkout repository |
| 72 | + uses: actions/checkout@v4 |
| 73 | + |
| 74 | + - name: lowercase image name |
| 75 | + run: | |
| 76 | + echo "IMAGE_NAME=${GITHUB_REPOSITORY,,}-airflow" >> ${GITHUB_ENV} |
| 77 | +
|
| 78 | + # https://github.com/docker/setup-qemu-action |
| 79 | + - name: Set up QEMU |
| 80 | + uses: docker/setup-qemu-action@v3.0.0 |
| 81 | + |
| 82 | + # https://github.com/docker/setup-buildx-action |
| 83 | + - name: Set up Docker Buildx |
| 84 | + id: buildx |
| 85 | + uses: docker/setup-buildx-action@v3.0.0 |
| 86 | + |
| 87 | + - name: Get current release version |
| 88 | + id: release-version |
| 89 | + run: | |
| 90 | + version=$(grep -E '^version += +' pyproject.toml | sed -E 's/.*= +//' | sed "s/['\"]//g") |
| 91 | + echo "version=${version}" >> $GITHUB_OUTPUT |
| 92 | + echo "version_build=${version}_"$(git rev-parse --short "$GITHUB_SHA") >> $GITHUB_OUTPUT |
| 93 | +
|
| 94 | + # https://github.com/docker/login-action |
| 95 | + - name: Log in to the Container registry |
| 96 | + uses: docker/login-action@v3.0.0 |
| 97 | + with: |
| 98 | + registry: ${{ env.REGISTRY }} |
| 99 | + username: ${{ github.actor }} |
| 100 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 101 | + |
| 102 | + # https://github.com/docker/metadata-action |
| 103 | + - name: Extract metadata (tags, labels) for Docker |
| 104 | + id: meta |
| 105 | + uses: docker/metadata-action@v5.0.0 |
| 106 | + with: |
| 107 | + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 108 | + tags: | |
| 109 | + type=raw,value=latest,enable=${{ github.event_name == 'push' }} |
| 110 | + type=raw,value=${{ needs.build-image.outputs.version }},enable=${{ github.event_name == 'release' }} |
| 111 | + # for future: |
| 112 | + # type=raw,value=${{ needs.build-image.outputs.version_build }},enable=${{ github.event_name == 'push' }} |
| 113 | + |
| 114 | + # https://github.com/docker/build-push-action |
| 115 | + - name: Push Docker image |
| 116 | + uses: docker/build-push-action@v5.0.0 |
| 117 | + with: |
| 118 | + context: . |
| 119 | + platforms: linux/amd64 |
| 120 | + file: tools/images/Dockerfile-airflow |
| 121 | + push: true |
| 122 | + tags: ${{ steps.meta.outputs.tags }} |
| 123 | + labels: ${{ steps.meta.outputs.labels }} |
| 124 | + build-args: PLATFORM=cu124 |
| 125 | + outputs: type=image,annotation-index.org.opencontainers.image.description=Run a Graph Neural Network. |
0 commit comments