Build and Publish Multi-Platform Docker Image #1
This file contains 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 Publish Multi-Platform Docker Image | |
on: | |
pull_request: | |
branches: | |
- main # Trigger on pull requests to the main branch | |
workflow_dispatch: # Allow manual triggering of the workflow | |
env: | |
IMAGE_NAME: functionland/loyal-agent # Name of the Docker Hub repository | |
jobs: | |
build-and-push-image: | |
runs-on: ubuntu-latest | |
steps: | |
# Step 1: Checkout repository code | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
# Step 2: Set up Docker Buildx | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
# Step 3: Log in to Docker Hub | |
- name: Log in to Docker Hub | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} # Docker Hub username stored as a GitHub secret | |
password: ${{ secrets.DOCKER_PASSWORD }} # Docker Hub password or personal access token stored as a GitHub secret | |
# Step 4: Extract metadata for Docker image tags and labels | |
- name: Extract metadata for Docker image | |
id: meta | |
uses: docker/metadata-action@v4 | |
with: | |
images: ${{ env.IMAGE_NAME }} | |
# Step 5: Build and push multi-platform Docker image to Docker Hub | |
- name: Build and push multi-platform Docker image | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
push: true | |
platforms: linux/amd64,linux/arm64 # Specify target platforms for multi-platform support | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} |