Skip to content

Commit fd27c8d

Browse files
Y-RyuZUclaude
andcommitted
feat: イメージタグを SHA ベースにして ArgoCD 自動デプロイを実現
- values.yaml: container.image を repository + tag に分離 - deployment.yaml: 分離後の形式でイメージ参照 - deploy.yaml: SHA タグでビルド・push + values.yaml 自動更新 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 90b448b commit fd27c8d

3 files changed

Lines changed: 22 additions & 5 deletions

File tree

.github/workflows/deploy.yaml

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff 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

infra/k8s/templates/deployment.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ spec:
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:

infra/k8s/values.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ source:
44
repoURL: 'git@github.com:Y-RyuZU/ReactPortfolio.git'
55
targetRevision: main
66
container:
7-
image: ghcr.io/y-ryuzu/react-portfolio:latest
7+
repository: ghcr.io/y-ryuzu/react-portfolio
8+
tag: latest
89
port: 3000
910
resources:
1011
limits:

0 commit comments

Comments
 (0)