Skip to content

feature/github-action #3

feature/github-action

feature/github-action #3

Workflow file for this run

name: Build and Push Docker Image
on:
push:
branches:
- main # Trigger on push to the 'main' branch
- master
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
# Checkout the repository
- name: Checkout code
uses: actions/checkout@v3
# Set up Docker Buildx (optional if you want to use Buildx features like multi-platform builds)
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
# Log in to GitHub Container Registry
- name: Log in to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# Build and push the Docker image to GitHub Container Registry
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64,linux/arm64 # Optional: multi-architecture support
push: true # Ensure the image is pushed
tags: |
ghcr.io/${{ github.repository_owner }}/abc:${{ github.sha }}
ghcr.io/${{ github.repository_owner }}/abc:latest
cache-from: type=gha
cache-to: type=gha,mode=max
# Optionally, list the images after pushing
- name: Verify pushed images
run: |
docker pull ghcr.io/${{ github.repository_owner }}/abc
docker images ghcr.io/${{ github.repository_owner }}/abc