|
| 1 | +name: docker build |
| 2 | +on: |
| 3 | + push: |
| 4 | + tags: |
| 5 | + - '*' |
| 6 | + paths: |
| 7 | + - "Dockerfile" |
| 8 | + - ".github/workflows/docker-push.yml" |
| 9 | + |
| 10 | +jobs: |
| 11 | + build: |
| 12 | + runs-on: ubuntu-latest |
| 13 | + steps: |
| 14 | + - name: Checkout codebase |
| 15 | + uses: actions/checkout@v2 |
| 16 | + |
| 17 | + - name: Setup QEMU |
| 18 | + uses: docker/setup-qemu-action@v1 |
| 19 | + |
| 20 | + - name: Setup Docker Buildx |
| 21 | + uses: docker/setup-buildx-action@v1 |
| 22 | + |
| 23 | + - name: Login to DockerHub |
| 24 | + uses: docker/login-action@v1 |
| 25 | + with: |
| 26 | + username: ${{ secrets.DOCKER_USERNAME }} |
| 27 | + password: ${{ secrets.DOCKER_PASSWORD }} |
| 28 | + |
| 29 | + - name: Get tag to build |
| 30 | + id: tag |
| 31 | + run: | |
| 32 | + echo "Use tag: ${{ github.event.inputs.tag }}" |
| 33 | + echo ::set-output name=tag::${{ github.event.inputs.tag }} |
| 34 | +
|
| 35 | + - name: Determine whether to push to DockerHub |
| 36 | + if: github.event_name == 'workflow_dispatch' |
| 37 | + run: | |
| 38 | + echo "PUSH=true" >> $GITHUB_ENV |
| 39 | +
|
| 40 | + - name: Prepare environment variables |
| 41 | + id: prepare |
| 42 | + run: | |
| 43 | + echo ::set-output name=docker_platforms::linux/386,linux/amd64,linux/arm64 |
| 44 | + echo ::set-output name=docker_image::boypt/cloud-torrent |
| 45 | + echo ::set-output name=docker_tag::${{ steps.tag.outputs.tag }} |
| 46 | + echo ::set-output name=docker_is_push::${PUSH:-false} |
| 47 | +
|
| 48 | + - name: Build tag & latest release |
| 49 | + run: | |
| 50 | + docker buildx build --platform ${{ steps.prepare.outputs.docker_platforms }} \ |
| 51 | + --output "type=image,push=${{ steps.prepare.outputs.docker_is_push }}" \ |
| 52 | + --tag "${{ steps.prepare.outputs.docker_image }}:${{ steps.prepare.outputs.docker_tag }}" \ |
| 53 | + --tag "${{ steps.prepare.outputs.docker_image }}:latest" \ |
| 54 | + --build-arg TAG=${{ steps.prepare.outputs.docker_tag }} \ |
| 55 | + --file Dockerfile . |
0 commit comments