adding the base image to improve the build time #36
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build and Push Docker Image | |
| on: | |
| push: | |
| branches: | |
| - '**' | |
| paths: | |
| - 'src/**' | |
| - 'Docker/**' | |
| workflow_dispatch: | |
| jobs: | |
| build-and-push: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Docker meta | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: | | |
| nauedu/nau-analytics-external-data-product | |
| tags: | | |
| type=sha | |
| - name: Build Docker image (no push yet) | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: ./ | |
| file: ./Docker/Dockerfile | |
| load: true | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| - name: Login to DockerHub | |
| if: ${{ github.event_name != 'pull_request' }} | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Push Docker image (branch-specific) | |
| if: ${{ github.event_name != 'pull_request' }} | |
| run: | | |
| set -eux | |
| IMAGE_NAME="nauedu/nau-analytics-external-data-product" | |
| SHA_TAG=$(echo "${GITHUB_SHA}" | head -c7) | |
| if [ "${GITHUB_REF_NAME}" = "main" ]; then | |
| # Tag and push with 'latest' and SHA | |
| docker tag $IMAGE_NAME:sha-$SHA_TAG $IMAGE_NAME:latest | |
| docker tag $IMAGE_NAME:sha-$SHA_TAG $IMAGE_NAME:$SHA_TAG | |
| docker push $IMAGE_NAME:latest | |
| docker push $IMAGE_NAME:$SHA_TAG | |
| echo "✅ Pushed tags 'latest' and '$SHA_TAG' for main branch to https://hub.docker.com/r/$IMAGE_NAME/tags" | |
| else | |
| # Tag and push with branch name | |
| BRANCH_TAG=$(echo "${GITHUB_REF_NAME}" | tr '/' '-') | |
| docker tag $IMAGE_NAME:sha-$SHA_TAG $IMAGE_NAME:$BRANCH_TAG | |
| docker push $IMAGE_NAME:$BRANCH_TAG | |
| echo "✅ Pushed branch tag '$BRANCH_TAG' to https://hub.docker.com/r/$IMAGE_NAME/tags" | |
| fi |