diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..8f27d51 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,105 @@ +name: Release + +on: + push: + tags: + - "v*" + +jobs: + # Build first because some Dockerfiles depend on the builder image + build-and-push-builder: + name: Build and push container image (builder) + runs-on: ubuntu-latest + permissions: + contents: read + + steps: + - uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4 + with: + submodules: recursive + + - name: Set up QEMU + uses: docker/setup-qemu-action@68827325e0b33c7199eb31dd4e31fbe9023e06e3 # v3.0.0 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@d70bba72b1f3fd22344832f00baa16ece964efeb # v3.3.0 + + - name: Login to ghcr.io + uses: docker/login-action@e92390c5fb421da1463c202d546fed0ec5c39f20 # v3.1.0 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push + uses: docker/build-push-action@2cdde995de11925a030ce8070c3d77a52ffcf1c0 # v5.3.0 + with: + platforms: linux/amd64,linux/arm64 + file: build.Dockerfile + tags: | + ghcr.io/dena/unity-meta-check/unity-meta-check-builder:${{ github.ref_name }} + ghcr.io/dena/unity-meta-check/unity-meta-check-builder:latest + push: true + cache-from: type=gha + cache-to: type=gha,mode=max + + build-and-push: + name: Build and push container image + needs: build-and-push-builder + runs-on: ubuntu-latest + permissions: + contents: read + + strategy: + matrix: + images: + - dockerfile: ./Dockerfile + image_name: ghcr.io/dena/unity-meta-check/unity-meta-check + - dockerfile: ./.github/images/Dockerfile + image_name: ghcr.io/dena/unity-meta-check/unity-meta-check-gh-action + - dockerfile: ./.circleci/images/Dockerfile + image_name: ghcr.io/dena/unity-meta-check/unity-meta-check-circleci + + steps: + - uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4 + with: + submodules: recursive + + - uses: nowsprinting/check-version-format-action@98485692a883d962227b09f40f29a63de0771299 # v4.0.2 + id: version + with: + prefix: "v" + + - name: Set up QEMU + uses: docker/setup-qemu-action@68827325e0b33c7199eb31dd4e31fbe9023e06e3 # v3.0.0 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@d70bba72b1f3fd22344832f00baa16ece964efeb # v3.3.0 + + - name: Login to ghcr.io + uses: docker/login-action@e92390c5fb421da1463c202d546fed0ec5c39f20 # v3.1.0 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push + uses: docker/build-push-action@2cdde995de11925a030ce8070c3d77a52ffcf1c0 # v5.3.0 + with: + platforms: linux/amd64,linux/arm64 + file: ${{ matrix.images.dockerfile }} + tags: ${{ matrix.images.image_name }}:${{ github.ref_name }} + push: true + cache-from: type=gha + cache-to: type=gha,mode=max + + - name: Add latest tag + if: steps.version.outputs.is_stable == 'true' + uses: docker/build-push-action@2cdde995de11925a030ce8070c3d77a52ffcf1c0 # v5.3.0 + with: + platforms: linux/amd64,linux/arm64 + file: ${{ matrix.images.dockerfile }} + tags: ${{ matrix.images.image_name }}:latest + push: true + cache-from: type=gha + cache-to: type=gha,mode=max diff --git a/scripts/deploy b/scripts/deploy index af5b872..2b9617d 100755 --- a/scripts/deploy +++ b/scripts/deploy @@ -29,7 +29,6 @@ usage: deploy [] OPTIONS -h, --help print this usage - --latest also tag the docker image as the latest EOS } @@ -43,8 +42,6 @@ usage-error() { main() { - local arg="${1:-}" - has go || throw "'go' must be installed (see https://golang.org)" has gh || throw "'gh' must be installed (see https://cli.github.com)" has docker || throw "'docker' must be installed (see https://www.docker.com)" @@ -65,12 +62,6 @@ main() { (cd "$BASE_DIR" ./scripts/deploy-gh-release ./scripts/deploy-bins - - if [[ "$arg" == "--latest" ]]; then - ./scripts/deploy-images --latest - else - ./scripts/deploy-images - fi ) } diff --git a/scripts/deploy-images b/scripts/deploy-images deleted file mode 100755 index f8a6a80..0000000 --- a/scripts/deploy-images +++ /dev/null @@ -1,118 +0,0 @@ -#!/bin/bash -set -euox pipefail - -BASE_DIR="$(cd "$(dirname "$0")/.."; pwd)" -BUILDER_DOCKERFILE="${BASE_DIR}/build.Dockerfile" -DOCKERFILE="${BASE_DIR}/Dockerfile" -GH_ACTION_DOCKERFILE="${BASE_DIR}/.github/images/Dockerfile" -CIRCLECI_DOCKERFILE="${BASE_DIR}/.circleci/images/Dockerfile" - - -usage() { - cat - 1>&2 <<-EOS -usage: deploy-images [] - -OPTIONS - -h, --help print this usage - --latest also tag as latest -EOS -} - - -main() { - local arg="${1:-}" - - (cd "$BASE_DIR" - local version - version="$("$BASE_DIR/scripts/print-version")" - - local builder_image - builder_image="$("$BASE_DIR/scripts/print-image-name" < "$BUILDER_DOCKERFILE")" - - local circleci_image - circleci_image="$("$BASE_DIR/scripts/print-image-name" < "$CIRCLECI_DOCKERFILE")" - - local gh_action_image - gh_action_image="$("$BASE_DIR/scripts/print-image-name" < "$GH_ACTION_DOCKERFILE")" - - local image - image="$("$BASE_DIR/scripts/print-image-name" < "$DOCKERFILE")" - - # NOTE: Create a docker-container driver to avoid the following error: - # > ERROR: Multi-platform build is not supported for the docker driver. - # > Switch to a different driver, or turn on the containerd image store, and try again. - # > Learn more at https://docs.docker.com/go/build-multi-platform/ - if ! docker buildx inspect unity-meta-check-driver; then - docker run --privileged --rm tonistiigi/binfmt --install all - docker buildx create --name unity-meta-check-driver --driver docker-container --bootstrap - fi - - # NOTE: --push is necessary, because --load is not supported for multi-platform build yet. - docker buildx build \ - --builder unity-meta-check-driver \ - --platform linux/arm64,linux/amd64 \ - --push \ - -t "$builder_image:latest" \ - -f "$BUILDER_DOCKERFILE" . - - if [[ "$arg" == "--latest" ]]; then - docker buildx build \ - --builder unity-meta-check-driver \ - --platform linux/arm64,linux/amd64 \ - --push \ - -t "$image:$version" \ - -t "$image:latest" \ - -f "$DOCKERFILE" . - else - docker buildx build \ - --builder unity-meta-check-driver \ - --platform linux/arm64,linux/amd64 \ - --push \ - -t "$image:$version" \ - -f "$DOCKERFILE" . - fi - - if [[ "$arg" == "--latest" ]]; then - docker buildx build \ - --builder unity-meta-check-driver \ - --platform linux/arm64,linux/amd64 \ - --push \ - -t "$gh_action_image:$version" \ - -t "$gh_action_image:latest" \ - -f "$GH_ACTION_DOCKERFILE" . - else - docker buildx build \ - --builder unity-meta-check-driver \ - --platform linux/arm64,linux/amd64 \ - --push \ - -t "$gh_action_image:$version" \ - -f "$GH_ACTION_DOCKERFILE" . - fi - - if [[ "$arg" == "--latest" ]]; then - docker buildx build \ - --builder unity-meta-check-driver \ - --platform linux/arm64,linux/amd64 \ - --push \ - -t "$circleci_image:$version" \ - -t "$circleci_image:latest" \ - -f "$CIRCLECI_DOCKERFILE" . - else - docker buildx build \ - --builder unity-meta-check-driver \ - --platform linux/arm64,linux/amd64 \ - --push \ - -t "$circleci_image:$version" \ - -f "$CIRCLECI_DOCKERFILE" . - fi - ) -} - - -case "$*" in - --help | -h) - usage - false ;; - *) - main "$@" ;; -esac