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 / 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 }}