feat: add GitHub Actions workflow for building and publishing Docker image
- Add Docker login step - Set up QEMU - Set up Docker Buildx - Build and push Docker image This feature allows for automated building and publishing of Docker images to Docker Hub. It includes proper setup of QEMU and Docker Buildx for cross-platform compatibility and efficient image building.
This commit is contained in:
parent
c11d10c86a
commit
54133b2f87
46
.github/workflows/docker.yml
vendored
Normal file
46
.github/workflows/docker.yml
vendored
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
name: Build and Publish Docker Image
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
|
||||||
|
env:
|
||||||
|
# Use docker.io for Docker Hub if empty
|
||||||
|
REGISTRY: docker.io
|
||||||
|
IMAGE_NAME: ${{ github.event.repository.name }}
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
docker:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Get version
|
||||||
|
id: get_version
|
||||||
|
run: |
|
||||||
|
GIT_VERSION=$(git describe --dirty --always --long --abbrev=7 --tags)
|
||||||
|
VERSION="v${GIT_VERSION}"
|
||||||
|
echo "VERSION=${VERSION}" >> $GITHUB_ENV
|
||||||
|
echo "GIT_VERSION=${GIT_VERSION}" >> $GITHUB_ENV
|
||||||
|
echo "LATEST_TAG=${{ env.REGISTRY }}/${{ vars.DOCKERHUB_USER }}/${{ env.IMAGE_NAME }}:latest" >> $GITHUB_OUTPUT"
|
||||||
|
echo "VERSION_TAG=${{ env.REGISTRY }}/${{ vars.DOCKERHUB_USER }}/${{ env.IMAGE_NAME }}:${VERSION}" >> $GITHUB_OUTPUT"
|
||||||
|
-
|
||||||
|
name: Login to ${{ env.REGISTRY }}
|
||||||
|
if: github.event_name != 'pull_request'
|
||||||
|
uses: docker/login-action@v3
|
||||||
|
with:
|
||||||
|
registry: ${{ env.REGISTRY }}
|
||||||
|
username: ${{ vars.DOCKERHUB_USER }}
|
||||||
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||||
|
-
|
||||||
|
name: Set up QEMU
|
||||||
|
uses: docker/setup-qemu-action@v3
|
||||||
|
-
|
||||||
|
name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v3
|
||||||
|
-
|
||||||
|
name: Build and push
|
||||||
|
uses: docker/build-push-action@v6
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
push: ${{ github.event_name != 'pull_request' }}
|
||||||
|
tags: ${{ env.LATEST_TAG }},${{ env.VERSION_TAG }}
|
Loading…
Reference in New Issue
Block a user