Create docker-publish.yml #7
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 Push Docker Image to GHCR | |
on: | |
push: | |
branches: [ main, prod2 ] | |
pull_request: | |
branches: [ main, prod2 ] | |
workflow_dispatch: | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Log in to GitHub Container Registry | |
run: docker login ghcr.io -u ${{ secrets.USERNAME }} -p ${{ secrets.GITHUB_TOKEN }} | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Create Buildx builder | |
run: docker buildx create --use | |
- name: Inspect Buildx builder | |
run: docker buildx inspect --bootstrap | |
- name: Get short Git SHA | |
id: vars | |
run: | | |
REF_PART=${GITHUB_REF#*/} | |
INDEX=${REF_PART:0:8} | |
echo "INDEX=$INDEX" >> $GITHUB_ENV | |
- name: Build and Push Multi-Platform Docker Image | |
run: | | |
IMAGE_TAG=ghcr.io/${{ github.repository_owner }}/anokha-2024:${{ github.ref_name }}-${{ env.GIT_SHA }} | |
docker buildx build \ | |
--platform linux/amd64,linux/arm64 \ | |
--tag $IMAGE_TAG \ | |
--tag ghcr.io/${{ github.repository_owner }}/anokha-2024:latest \ | |
--push . | |
- name: Log out from Docker | |
run: docker logout ghcr.io |