diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 4c01f49e2..440c038b7 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -6,27 +6,74 @@ on: env: go-version: 1.17 jobs: - image: + build-moco: name: Push Container Image runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v3 - - name: Build images - run: | - docker build -t moco:dev --target controller . - docker build -t moco-backup:dev . - - name: Login to ghcr.io - run: echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u $GITHUB_ACTOR --password-stdin - - name: Push images - run: | - TAG=${GITHUB_REF#refs/tags/v} - docker tag moco:dev ghcr.io/cybozu-go/moco:$TAG - docker push ghcr.io/cybozu-go/moco:$TAG - docker tag moco-backup:dev ghcr.io/cybozu-go/moco-backup:$TAG - docker push ghcr.io/cybozu-go/moco-backup:$TAG + - name: Set up Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v1 + - name: Login to GitHub Container Registry + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Docker meta + id: meta + uses: docker/metadata-action@v4 + with: + images: ghcr.io/cybozu-go/moco + # ref. https://github.com/docker/metadata-action#typesemver + tags: | + type=semver,pattern={{version}} + - name: Build (and push if on main) + id: docker_build + uses: docker/build-push-action@v2 + with: + builder: ${{ steps.buildx.outputs.name }} + push: true + tags: ${{ steps.meta.outputs.tags }} + target: controller + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max + build-moco-backup: + name: Push Container Image + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v3 + - name: Set up Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v1 + - name: Login to GitHub Container Registry + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Docker meta + id: meta + uses: docker/metadata-action@v4 + with: + images: ghcr.io/cybozu-go/moco-backup + # ref. https://github.com/docker/metadata-action#typesemver + tags: | + type=semver,pattern={{version}} + - name: Build (and push if on main) + id: docker_build + uses: docker/build-push-action@v2 + with: + builder: ${{ steps.buildx.outputs.name }} + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max release: name: Release on GitHub - needs: image + needs: [build-moco, build-moco-backup] runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v3