|
| 1 | +name: Build and Push Docker Image |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - '**' |
| 7 | + paths: |
| 8 | + - 'superset/**' |
| 9 | + workflow_dispatch: |
| 10 | + |
| 11 | +jobs: |
| 12 | + build-and-push: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + |
| 15 | + steps: |
| 16 | + - name: Checkout repository |
| 17 | + uses: actions/checkout@v4 |
| 18 | + |
| 19 | + - name: Set up Docker Buildx |
| 20 | + uses: docker/setup-buildx-action@v3 |
| 21 | + |
| 22 | + - name: Docker meta |
| 23 | + id: meta |
| 24 | + uses: docker/metadata-action@v5 |
| 25 | + with: |
| 26 | + images: | |
| 27 | + nauedu/nau-analytics-superset |
| 28 | + tags: | |
| 29 | + type=sha |
| 30 | +
|
| 31 | + - name: Build Docker image (no push yet) |
| 32 | + uses: docker/build-push-action@v6 |
| 33 | + with: |
| 34 | + context: ./ |
| 35 | + file: ./spark-shell/Dockerfile |
| 36 | + load: true |
| 37 | + tags: ${{ steps.meta.outputs.tags }} |
| 38 | + labels: ${{ steps.meta.outputs.labels }} |
| 39 | + |
| 40 | + - name: Login to DockerHub |
| 41 | + if: ${{ github.event_name != 'pull_request' }} |
| 42 | + uses: docker/login-action@v3 |
| 43 | + with: |
| 44 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 45 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 46 | + |
| 47 | + - name: Push Docker image (branch-specific) |
| 48 | + if: ${{ github.event_name != 'pull_request' }} |
| 49 | + run: | |
| 50 | + set -eux |
| 51 | + IMAGE_NAME="nauedu/nau-analytics-superset" |
| 52 | + SHA_TAG=$(echo "${GITHUB_SHA}" | head -c7) |
| 53 | +
|
| 54 | + if [ "${GITHUB_REF_NAME}" = "main" ]; then |
| 55 | + # Tag and push with 'latest' and SHA |
| 56 | + docker tag $IMAGE_NAME:sha-$SHA_TAG $IMAGE_NAME:latest |
| 57 | + docker tag $IMAGE_NAME:sha-$SHA_TAG $IMAGE_NAME:$SHA_TAG |
| 58 | +
|
| 59 | + docker push $IMAGE_NAME:latest |
| 60 | + docker push $IMAGE_NAME:$SHA_TAG |
| 61 | +
|
| 62 | + echo "✅ Pushed tags 'latest' and '$SHA_TAG' for main branch to https://hub.docker.com/r/$IMAGE_NAME/tags" |
| 63 | + else |
| 64 | + # Tag and push with branch name |
| 65 | + BRANCH_TAG=$(echo "${GITHUB_REF_NAME}" | tr '/' '-') |
| 66 | + docker tag $IMAGE_NAME:sha-$SHA_TAG $IMAGE_NAME:$BRANCH_TAG |
| 67 | + docker push $IMAGE_NAME:$BRANCH_TAG |
| 68 | +
|
| 69 | + echo "✅ Pushed branch tag '$BRANCH_TAG' to https://hub.docker.com/r/$IMAGE_NAME/tags" |
| 70 | + fi |
0 commit comments