Added DockerHub action

This commit is contained in:
parra 2022-03-04 11:04:38 +01:00 committed by Parra
parent daf8c8fd55
commit 805caaad24
1 changed files with 65 additions and 0 deletions

65
.github/workflows/docker-registry.yml vendored Normal file
View File

@ -0,0 +1,65 @@
name: Build and Publish
on:
# run it on push to the default repository branch
push:
branches: [master, develop]
# Publish semver tags as releases.
tags: [ 'v*.*.*' ]
# run it during pull request
pull_request:
env:
# github.repository as <account>/<repo>
IMAGE_NAME: ${{ github.repository }}
PLATFORMS: linux/amd64,linux/arm64,linux/arm/v7
jobs:
# define job to build and publish docker image
build-and-push-docker-image:
name: Build Docker image and push to repositories
# run only when code is compiling and tests are passing
runs-on: ubuntu-latest
# steps to perform in job
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up QEMU
id: qemu
uses: docker/setup-qemu-action@v1
with:
image: tonistiigi/binfmt:latest
platforms: ${{ env.PLATFORMS }}
# setup Docker buld action
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
with:
images: ${{ env.IMAGE_NAME }}
- name: Build image and push to Docker Hub and GitHub Container Registry
uses: docker/build-push-action@v2
with:
context: .
platforms: ${{ env.PLATFORMS }}
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}