Build and Push Docker Image #12
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 | |
| # Make sure to add DockerHub credentials as secrets in your GitHub repository settings (DOCKER_USERNAME and DOCKER_PASSWORD) | |
| on: | |
| push: | |
| branches: | |
| - main | |
| workflow_dispatch: # Allows manual triggering of the workflow | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v2 # Checks out your repository | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v2 # Sets up QEMU for multi-platform builds | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v2 # Sets up Docker Buildx | |
| - name: Log in to DockerHub | |
| uses: docker/login-action@v2 | |
| with: | |
| username: ${{ secrets.DOCKER_USERNAME }} # DockerHub username read from secret | |
| password: ${{ secrets.DOCKER_PASSWORD }} # DockerHub password read from secret | |
| - name: Build and push Docker images | |
| uses: docker/build-push-action@v6.11.0 | |
| with: | |
| context: . # Build context | |
| file: ./Dockerfile # Path to the Dockerfile | |
| platforms: linux/amd64,linux/arm/v7,linux/arm64 # Target platforms | |
| push: true # Push the image to DockerHub | |
| tags: carbon2029/dockweb:latest # Docker image tag | |
| cache-from: type=gha # Use GitHub Actions cache to speed-up future builds | |
| cache-to: type=gha,mode=max # Store cache in GitHub Actions to speed-up future builds |