Skip to content

GitHub Container Registry へ push するようにしてみる #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
Feb 16, 2025

Conversation

rokuosan
Copy link
Collaborator

@rokuosan rokuosan commented Feb 16, 2025

Pull request

  • Issues:

❓ 背景 (Why)

本番デプロイを簡単にするために GitHub Container Registry にイメージがあると便利だったので公開したかった。

⛏️ 修正内容 (What)

  • コンテナイメージがビルドされるように CI を改修した
  • main にマージされたときに push されるようにした
  • ビルドされるイメージにはビルド日時とコミットハッシュがタグとして付与される
image

📸 キャプチャ

Before After
画像 画像

👀 懸案事項

🔍 チェック項目

このPRで変更が想定通りうまくいっているかを確認するには...

  • [ ]
  • [ ]
  • [ ]

@rokuosan rokuosan self-assigned this Feb 16, 2025
@taiseiue
Copy link
Collaborator

👀

Copy link
Collaborator

@taiseiue taiseiue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

みました。
一箇所書きましたが、よさそうです。

file: ./docker/akane-next/Dockerfile
platforms: linux/amd64
push: ${{ github.head_ref == 'main' }}
tags: ghcr.io/${{ github.repository_owner }}/2025_9/akene-next:latest
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[may] リポジトリ名をハードコードするのではなく、${{ github.repository }}コンテキストを使う方が良いかもしれません。

https://docs.github.com/ja/actions/writing-workflows/choosing-what-your-workflow-does/accessing-contextual-information-about-workflow-runs#github-context

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🦀

@rokuosan
Copy link
Collaborator Author

レビューありがとうございます。ただ出した後にメタデータもうすこしちゃんとできそうだったので後追いコミットします。
すみません

@taiseiue
Copy link
Collaborator

ひと段落したら再レビュー飛ばしてくれたらみます

@rokuosan
Copy link
Collaborator Author

イメージタグにそれぞれ固有の値を持たせるようにしました。(日付とコミットハッシュ)

コミットログが多くなっているのはラベルの日付に悪戦苦闘していたのですが、なんとびっくり空白にすると自動的に値が挿入されました
https://github.com/kc3hack/2025_9/actions/runs/13353379276/job/37292784382?pr=14#step:4:47

@rokuosan rokuosan requested a review from taiseiue February 16, 2025 08:48
@rokuosan
Copy link
Collaborator Author

@taiseiue
改めてレビューお願いします。すみません!

- uses: docker/metadata-action@v4
id: meta
with:
images: ghcr.io/${{ github.repository_owner }}/${{ github.repository }}/akane-next
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

akane-nextは後から別にもう一つこのリポジトリからアーティファクトが生まれるかもしれないのでつけています

@taiseiue
Copy link
Collaborator

👀

@rokuosan
Copy link
Collaborator Author

ちなみに PR ごとにイメージが Push されまくりますが、 public リポジトリ + ハッカソンで期間が短いので Limit になることはないでしょうと思って push させてます。
しなくてもいい感じもしますが、後で検証用に使えると便利そうかなと思ってます。

Copy link
Collaborator

@taiseiue taiseiue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

おつかれさまです!
一点だけ、${{ github.repository_owner }}/を削除してあげてマージしてあげるとよさそうです。

- uses: docker/metadata-action@v4
id: meta
with:
images: ghcr.io/${{ github.repository_owner }}/${{ github.repository }}/akane-next
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🦀 うっかりしてました

# ref:
# - https://github.com/opencontainers/image-spec/blob/fbb4662eb53b80bd38f7597406cf1211317768f0/annotations.md?plain=1#L18-L26
labels: |
org.opencontainers.image.authors="rokuosan, taiseiue, nenrinyear, Retasusan, ikotome"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[コメント] 外部の標準への準拠助かります。他の人がコードやイメージを見直したときに伝わりやすくなります😊

tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
push: true
provenance: false
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[メモ] GitHub Container Registryへの対応のため、暫定的にprovenance: falseを指定している

@rokuosan rokuosan requested a review from taiseiue February 16, 2025 09:09
@rokuosan
Copy link
Collaborator Author

@taiseiue
指摘箇所修正してます。
ついでに過去の検証でPushしたイメージたちは削除しておきました

Copy link
Collaborator

@taiseiue taiseiue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

修正ありがとうございます!
いかにもよさそう

@rokuosan
Copy link
Collaborator Author

dmdm

@rokuosan rokuosan merged commit 7028399 into main Feb 16, 2025
2 checks passed
@rokuosan rokuosan deleted the ci-next-build branch February 16, 2025 09:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants