|
| 1 | +name: buildx_github |
| 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@v3 |
| 15 | + - |
| 16 | + name: Prepare |
| 17 | + id: prepare |
| 18 | + run: | |
| 19 | + DOCKER_IMAGE=ghcr.io/windoc/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 | + VERSION=$(echo $VERSION | sed 's/^v//g') |
| 26 | + fi |
| 27 | +
|
| 28 | + TAGS="--tag ${DOCKER_IMAGE}:${VERSION}" |
| 29 | + if [[ $VERSION =~ ^[0-9]{1,3} ]]; then |
| 30 | + TAGS="$TAGS --tag ${DOCKER_IMAGE}:latest" |
| 31 | + fi |
| 32 | +
|
| 33 | + echo "docker_image=${DOCKER_IMAGE}" >> $GITHUB_OUTPUT |
| 34 | + echo "version=${VERSION}" >> $GITHUB_OUTPUT |
| 35 | + echo "buildx_args=--platform ${DOCKER_PLATFORMS} --build-arg VERSION=${VERSION} --build-arg BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ') --build-arg VCS_REF=${GITHUB_SHA::8} ${TAGS} --file ./Dockerfile ." >> $GITHUB_OUTPUT |
| 36 | + # https://github.com/docker/setup-qemu-action |
| 37 | + - |
| 38 | + name: Set up QEMU |
| 39 | + uses: docker/setup-qemu-action@v2 |
| 40 | + # https://github.com/docker/setup-buildx-action |
| 41 | + - |
| 42 | + name: Set up Docker Buildx |
| 43 | + uses: docker/setup-buildx-action@v2 |
| 44 | + # with: |
| 45 | + # cache-from: type=gha |
| 46 | + # cache-to: type=gha,mode=max |
| 47 | + - |
| 48 | + name: Docker Buildx (build) |
| 49 | + run: | |
| 50 | + docker buildx build --output "type=image,push=false" ${{ steps.prepare.outputs.buildx_args }} |
| 51 | + - |
| 52 | + name: Login to ghcr.io |
| 53 | + if: success() && github.event_name != 'pull_request' |
| 54 | + uses: docker/login-action@v2 |
| 55 | + with: |
| 56 | + registry: ghcr.io |
| 57 | + username: ${{ github.actor }} |
| 58 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 59 | + - |
| 60 | + name: Docker Buildx (push to ghcr.io) |
| 61 | + if: success() && github.event_name != 'pull_request' |
| 62 | + run: | |
| 63 | + docker buildx build --output "type=image,push=true" ${{ steps.prepare.outputs.buildx_args }} |
| 64 | + - |
| 65 | + name: Inspect image |
| 66 | + if: always() && github.event_name != 'pull_request' |
| 67 | + run: | |
| 68 | + docker buildx imagetools inspect ${{ steps.prepare.outputs.docker_image }}:${{ steps.prepare.outputs.version }} |
0 commit comments