Merge pull request #14 from rtcode337/claude/build-number #3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # mainへのpushで本番用Dockerイメージ(Dockerfileのprodステージ)をビルドし、 | |
| # GHCR(ghcr.io/rtcode337/travel-log)へ公開する。本番環境の更新はこのイメージを | |
| # pullするだけでよい(docker-compose.ymlのappサービスが参照。README「本番運用」参照) | |
| name: docker-publish | |
| on: | |
| push: | |
| branches: [main] | |
| workflow_dispatch: | |
| permissions: | |
| contents: read | |
| packages: write | |
| jobs: | |
| build-and-push: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| # 管理画面に表示するビルド番号(JSTの日時 + 短縮コミットハッシュ)。 | |
| # 本番で動いているイメージがいつのどのコミットのものかを画面から確認できるようにする | |
| - id: build_number | |
| run: | | |
| echo "value=$(TZ=Asia/Tokyo date +'%Y%m%d-%H%M')-$(git rev-parse --short HEAD)" >> "$GITHUB_OUTPUT" | |
| # arm64イメージをamd64ランナー上でビルドするためのQEMUエミュレーション | |
| - uses: docker/setup-qemu-action@v3 | |
| - uses: docker/setup-buildx-action@v3 | |
| - uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ghcr.io/${{ github.repository }} | |
| # latest(既定ブランチのみ)+ コミットSHA(sha-xxxxxxx)の2タグ。 | |
| # 障害時はSHAタグを指定してpullすれば任意の時点に戻せる | |
| tags: | | |
| type=raw,value=latest,enable={{is_default_branch}} | |
| type=sha | |
| - uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| target: prod | |
| push: true | |
| # 本番ホスト(arm64)とローカル検証用(amd64)のマルチアーキビルド。 | |
| # arm64側はQEMUエミュレーションのためビルド時間が長い | |
| platforms: linux/amd64,linux/arm64 | |
| build-args: | | |
| BUILD_NUMBER=${{ steps.build_number.outputs.value }} | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max |