File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -47,13 +47,29 @@ jobs:
4747 username : ${{ env.NORMALIZED_OWNER_NAME }}
4848 password : ${{ secrets.GITHUB_TOKEN }}
4949
50- # 5. Docker イメージをビルド
50+ # 5. Docker イメージをビルド(latest + SHA タグ)
5151 - name : Build Docker Image
5252 run : |
53+ IMAGE=ghcr.io/${{ env.NORMALIZED_OWNER_NAME }}/${{ env.NORMALIZED_REPOSITORY_NAME }}
54+ SHORT_SHA=${GITHUB_SHA::7}
5355 docker build -f infra/docker/Dockerfile . \
54- -t ghcr.io/${{ env.NORMALIZED_OWNER_NAME }}/${{ env.NORMALIZED_REPOSITORY_NAME }}:latest
56+ -t ${IMAGE}:latest \
57+ -t ${IMAGE}:${SHORT_SHA}
58+ echo "SHORT_SHA=${SHORT_SHA}" >> $GITHUB_ENV
5559
5660 # 6. Docker イメージをプッシュ
5761 - name : Push Docker Image
5862 run : |
59- docker push ghcr.io/${{ env.NORMALIZED_OWNER_NAME }}/${{ env.NORMALIZED_REPOSITORY_NAME }}:latest
63+ IMAGE=ghcr.io/${{ env.NORMALIZED_OWNER_NAME }}/${{ env.NORMALIZED_REPOSITORY_NAME }}
64+ docker push ${IMAGE}:latest
65+ docker push ${IMAGE}:${{ env.SHORT_SHA }}
66+
67+ # 7. values.yaml のイメージタグを更新して push
68+ - name : Update image tag in values.yaml
69+ run : |
70+ sed -i "s/^ tag: .*/ tag: ${{ env.SHORT_SHA }}/" infra/k8s/values.yaml
71+ git config user.name "github-actions[bot]"
72+ git config user.email "github-actions[bot]@users.noreply.github.com"
73+ git add infra/k8s/values.yaml
74+ git diff --staged --quiet || git commit -m "ci: update image tag to ${{ env.SHORT_SHA }}"
75+ git push
Original file line number Diff line number Diff line change 1717 spec :
1818 containers :
1919 - name : {{ .Values.appName }}-container
20- image : {{ .Values.container.image }}
20+ image : {{ .Values.container.repository }}:{{ .Values.container.tag }}
2121 ports :
2222 - containerPort : {{ .Values.container.port }}
2323 resources :
Original file line number Diff line number Diff line change 44 repoURL : ' git@github.com:Y-RyuZU/ReactPortfolio.git'
55 targetRevision : main
66container :
7- image : ghcr.io/y-ryuzu/react-portfolio:latest
7+ repository : ghcr.io/y-ryuzu/react-portfolio
8+ tag : latest
89 port : 3000
910resources :
1011 limits :
You can’t perform that action at this time.
0 commit comments