Skip to content

Build Docker Image

Build Docker Image #23

Workflow file for this run

name: Build Docker Image
on:
workflow_dispatch:
inputs:
image_path:
description: 'Full image path (e.g., docker.io/test/xxx:0.1.0)'
required: true
platform:
description: 'Platform for the Docker image (e.g., linux/amd64, linux/arm64)'
required: true
build_context:
description: 'Directory path for Docker build context'
required: true
jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Login to docker.io
uses: docker/login-action@v2
with:
registry: docker.io
username: ${{ secrets.DOCKER_ACCOUNT }}
password: ${{ secrets.DOCKER_PWD }}
- name: Build Docker Image
run: |
BUILD_CONTEXT="${{ github.event.inputs.build_context }}"
ORIGINAL_IMAGE="${{ github.event.inputs.image_path }}"
PLATFORM="${{ github.event.inputs.platform }}"
# Build the Docker image
docker build --platform $PLATFORM -t $ORIGINAL_IMAGE $BUILD_CONTEXT
echo "Docker image built with context $BUILD_CONTEXT and tagged as $ORIGINAL_IMAGE"
- name: Push Docker Image to GHCR
run: |
ORIGINAL_IMAGE="${{ github.event.inputs.image_path }}"
IMAGE_NAME=$(basename $ORIGINAL_IMAGE)
# Retag for GHCR
NEW_IMAGE="ghcr.io/${{ github.repository_owner }}/${IMAGE_NAME}"
docker tag $ORIGINAL_IMAGE $NEW_IMAGE
echo "Image retagged from $ORIGINAL_IMAGE to $NEW_IMAGE"
# Push to GHCR
docker push $NEW_IMAGE
- name: Push Docker Image to DOCKER
run: |
ORIGINAL_IMAGE="${{ github.event.inputs.image_path }}"
# Push to Docker.io
docker push $ORIGINAL_IMAGE
echo "Docker image pushed to $ORIGINAL_IMAGE"