|
| 1 | +name: buildx |
| 2 | + |
| 3 | +on: |
| 4 | + create: |
| 5 | + tags: |
| 6 | + - v* |
| 7 | + |
| 8 | +jobs: |
| 9 | + buildx: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + steps: |
| 12 | + - |
| 13 | + name: Checkout |
| 14 | + uses: actions/checkout@v2 |
| 15 | + - |
| 16 | + name: Prepare |
| 17 | + id: prepare |
| 18 | + run: | |
| 19 | + DOCKER_IMAGE=windoac/nginx-npm |
| 20 | + DOCKER_PLATFORMS=linux/amd64,linux/arm/v7,linux/arm64/v8 |
| 21 | + VERSION=edge |
| 22 | +
|
| 23 | + if [[ $GITHUB_REF == refs/tags/* ]]; then |
| 24 | + VERSION=${GITHUB_REF#refs/tags/} |
| 25 | + fi |
| 26 | +
|
| 27 | + TAGS="--tag ${DOCKER_IMAGE}:${VERSION}" |
| 28 | + if [[ $VERSION =~ ^[0-9]{1,3} ]]; then |
| 29 | + TAGS="$TAGS --tag ${DOCKER_IMAGE}:latest" |
| 30 | + fi |
| 31 | +
|
| 32 | + echo ::set-output name=docker_image::${DOCKER_IMAGE} |
| 33 | + echo ::set-output name=version::${VERSION} |
| 34 | + echo ::set-output name=buildx_args::--platform ${DOCKER_PLATFORMS} \ |
| 35 | + --build-arg VERSION=${VERSION} \ |
| 36 | + --build-arg BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ') \ |
| 37 | + --build-arg VCS_REF=${GITHUB_SHA::8} \ |
| 38 | + ${TAGS} --file ./Dockerfile . |
| 39 | + # https://github.com/docker/setup-qemu-action |
| 40 | + - |
| 41 | + name: Set up QEMU |
| 42 | + uses: docker/setup-qemu-action@v1 |
| 43 | + # https://github.com/docker/setup-buildx-action |
| 44 | + - |
| 45 | + name: Set up Docker Buildx |
| 46 | + uses: docker/setup-buildx-action@v1 |
| 47 | + with: |
| 48 | + cache-from: type=gha |
| 49 | + cache-to: type=gha,mode=max |
| 50 | + - |
| 51 | + name: Docker Buildx (build) |
| 52 | + run: | |
| 53 | + docker buildx build --output "type=image,push=false" ${{ steps.prepare.outputs.buildx_args }} |
| 54 | + - |
| 55 | + name: Login to DockerHub |
| 56 | + if: success() && github.event_name != 'pull_request' |
| 57 | + uses: docker/login-action@v1 |
| 58 | + with: |
| 59 | + username: ${{ secrets.DOCKER_USERNAME }} |
| 60 | + password: ${{ secrets.DOCKER_PASSWORD }} |
| 61 | + - |
| 62 | + name: Docker Buildx (push) |
| 63 | + if: success() && github.event_name != 'pull_request' |
| 64 | + run: | |
| 65 | + docker buildx build --output "type=image,push=true" ${{ steps.prepare.outputs.buildx_args }} |
| 66 | + - |
| 67 | + name: Inspect image |
| 68 | + if: always() && github.event_name != 'pull_request' |
| 69 | + run: | |
| 70 | + docker buildx imagetools inspect ${{ steps.prepare.outputs.docker_image }}:${{ steps.prepare.outputs.version }} |
0 commit comments