|
| 1 | +name: Docker Image CI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ master ] |
| 6 | + pull_request: |
| 7 | + branches: [ master ] |
| 8 | + repository_dispatch: |
| 9 | + types: [alpine-update] |
| 10 | + workflow_dispatch: |
| 11 | + |
| 12 | +jobs: |
| 13 | + |
| 14 | + build: |
| 15 | + |
| 16 | + runs-on: ubuntu-latest |
| 17 | + env: |
| 18 | + DOCKER_REGISTRY: ${{ secrets.DOCKER_REGISTRY }} |
| 19 | + DOCKER_IMAGE: ${{ secrets.DOCKER_IMAGE }} |
| 20 | + DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} |
| 21 | + DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} |
| 22 | + DOCKER_TARGET_PLATFORMS: linux/amd64,linux/arm/v7,linux/arm64 |
| 23 | + steps: |
| 24 | + - name: Checkout the code |
| 25 | + uses: actions/checkout@v1 |
| 26 | + |
| 27 | + # https://github.com/docker/setup-qemu-action |
| 28 | + - name: Set up QEMU |
| 29 | + uses: docker/setup-qemu-action@v1 |
| 30 | + |
| 31 | + # https://github.com/docker/setup-buildx-action |
| 32 | + - name: Set up Docker Buildx |
| 33 | + uses: docker/setup-buildx-action@v1 |
| 34 | + with: |
| 35 | + buildx-version: latest |
| 36 | + |
| 37 | + - name: Prepare |
| 38 | + if: success() |
| 39 | + id: prepare |
| 40 | + run: | |
| 41 | + echo ::set-output name=docker_platform::${DOCKER_TARGET_PLATFORMS} |
| 42 | + echo ::set-output name=docker_image::${DOCKER_REGISTRY}/${DOCKER_IMAGE} |
| 43 | + echo ::set-output name=version::0.1.${GITHUB_RUN_NUMBER} |
| 44 | + |
| 45 | + - name: Inspect builder |
| 46 | + run: | |
| 47 | + echo "Name: ${{ steps.buildx.outputs.name }}" |
| 48 | + echo "Endpoint: ${{ steps.buildx.outputs.endpoint }}" |
| 49 | + echo "Status: ${{ steps.buildx.outputs.status }}" |
| 50 | + echo "Flags: ${{ steps.buildx.outputs.flags }}" |
| 51 | + echo "Platforms: ${{ steps.buildx.outputs.platforms }}" |
| 52 | + |
| 53 | + - name: Docker Login |
| 54 | + if: success() |
| 55 | + run: | |
| 56 | + echo "${DOCKER_PASSWORD}" | docker login ${DOCKER_REGISTRY} --username "${DOCKER_USERNAME}" --password-stdin |
| 57 | + |
| 58 | + - name: Run Buildx (push image) |
| 59 | + if: success() |
| 60 | + run: | |
| 61 | + docker buildx build \ |
| 62 | + --platform ${{ steps.prepare.outputs.docker_platform }} \ |
| 63 | + --tag ${{ steps.prepare.outputs.docker_image }}:${{ steps.prepare.outputs.version }} \ |
| 64 | + --tag ${{ steps.prepare.outputs.docker_image }}:latest \ |
| 65 | + --file ./Dockerfile \ |
| 66 | + --output type=image,push=true . |
0 commit comments