docker.yaml
1 name: Docker Build 2 3 on: 4 push: 5 # Publish `v1.2.3` tags as releases. 6 tags: 7 - v* 8 branches: [ master ] 9 paths-ignore: [ '**.md' ] 10 workflow_dispatch: 11 12 env: 13 DOCKER_PLATFORMS: linux/amd64 #,linux/arm/v7,linux/arm64/v8 #linux/s390x,linux/ppc64le 14 15 jobs: 16 build: 17 runs-on: ubuntu-latest 18 19 steps: 20 - uses: actions/checkout@v2 21 22 - name: Set up QEMU 23 uses: docker/setup-qemu-action@v1 24 25 - name: Set up Docker Buildx 26 uses: docker/setup-buildx-action@v1 27 28 - name: Cache Docker layers 29 uses: actions/cache@v2 30 with: 31 path: /tmp/.buildx-cache 32 key: ${{ runner.os }}-buildx-${{ github.sha }} 33 restore-keys: ${{ runner.os }}-buildx- 34 35 - name: Create Version 36 id: prepare 37 run: | 38 set -x 39 VERSION=edge 40 IMAGE_NAME=defelo/corona-telegram-bot 41 if [[ $GITHUB_REF == refs/tags/* ]]; then 42 VERSION=${GITHUB_REF#refs/tags/v} 43 fi 44 TAGS="$IMAGE_NAME:${VERSION}" 45 if [[ $VERSION =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then 46 TAGS="$TAGS,$IMAGE_NAME:latest" 47 fi 48 echo ::set-output name=image::${TAGS} 49 50 - name: Build 51 uses: docker/build-push-action@v2 52 with: 53 push: false 54 tags: ${{ steps.prepare.outputs.image }} 55 platforms: ${{ env.DOCKER_PLATFORMS }} 56 file: Dockerfile 57 context: . 58 cache-from: type=local,src=/tmp/.buildx-cache 59 cache-to: type=local,dest=/tmp/.buildx-cache,mode=max 60 61 - name: Login to DockerHub 62 uses: docker/login-action@v1 63 with: 64 username: ${{ secrets.DOCKERHUB_USERNAME }} 65 password: ${{ secrets.DOCKERHUB_PASSWORD }} 66 67 - name: Push 68 uses: docker/build-push-action@v2 69 with: 70 push: true 71 tags: ${{ steps.prepare.outputs.image }} 72 platforms: ${{ env.DOCKER_PLATFORMS }} 73 file: Dockerfile 74 context: . 75 cache-from: type=local,src=/tmp/.buildx-cache 76 cache-to: type=local,dest=/tmp/.buildx-cache,mode=max 77 78 - name: Clear 79 if: always() 80 run: rm -f ${HOME}/.docker/config.json