Repository navigation
90 lines (76 loc) · 3.37 KB
/
Copy pathdocker-bump-push-react.yml
File metadata and controls
90 lines (76 loc) · 3.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
name: Docker Bump & Push - React
on:
push:
branches: [main]
paths:
- "client/**"
workflow_dispatch:
env:
DOCKERHUB_NAMESPACE: ${{ secrets.DOCKERHUB_USERNAME }}
GHCR_NAMESPACE: ghcr.io/hanmoonsub
jobs:
bump-and-push:
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
pull-requests: write
steps:
- name: Checkout
uses: actions/checkout@v7
- name: Set up QEMU
uses: docker/setup-qemu-action@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Log in to Docker Hub
uses: docker/login-action@v4
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Log in to GHCR
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Compute new tag from Docker Hub
id: bump
run: |
set -euo pipefail
get_latest_tag() {
local repo="$1"
local token tags_json
token=$(curl -s "https://auth.docker.io/token?service=registry.docker.io&scope=repository:${DOCKERHUB_NAMESPACE}/${repo}:pull" | python3 -c "import json,sys;print(json.load(sys.stdin).get('token',''))")
tags_json=$(curl -s -H "Authorization: Bearer ${token}" "https://registry-1.docker.io/v2/${DOCKERHUB_NAMESPACE}/${repo}/tags/list")
echo "$tags_json" | python3 -c "import json,sys; d=json.load(sys.stdin); v=sorted(tuple(int(p) for p in t.split('.')) for t in (d.get('tags') or []) if len(t.split('.'))==3 and all(p.isdigit() for p in t.split('.'))); print('%d.%d.%d'%v[-1] if v else '1.0.0')"
}
current=$(get_latest_tag "deepguard-react")
IFS='.' read -r major minor patch <<< "$current"
new_tag="${major}.${minor}.$((patch + 1))"
echo "react: 현재 최댓값 ${current} -> ${new_tag}"
echo "new_tag=${new_tag}" >> "$GITHUB_OUTPUT"
- name: Build & push react
uses: docker/build-push-action@v7
with:
context: client
file: client/Dockerfile
platforms: linux/amd64,linux/arm64
tags: |
${{ env.DOCKERHUB_NAMESPACE }}/deepguard-react:${{ steps.bump.outputs.new_tag }}
${{ env.GHCR_NAMESPACE }}/deepguard-react:${{ steps.bump.outputs.new_tag }}
push: true
cache-from: type=gha,scope=react
cache-to: type=gha,mode=max,scope=react
- name: Update docker-compose.yml image tag
run: |
sed -i -E "s#(image: ${DOCKERHUB_NAMESPACE}/deepguard-react:)[0-9]+\.[0-9]+\.[0-9]+#\1${{ steps.bump.outputs.new_tag }}#" docker-compose.yml
- name: Open PR to bump docker-compose.yml
uses: peter-evans/create-pull-request@v8
with:
commit-message: "🐳 Bump react image tag to ${{ steps.bump.outputs.new_tag }} in docker-compose.yml"
title: "🐳 Bump react image tag to ${{ steps.bump.outputs.new_tag }}"
body: |
Docker Bump & Push - React 워크플로우가 새로 push한 이미지 태그를 `docker-compose.yml`에 반영합니다.
- `${{ env.DOCKERHUB_NAMESPACE }}/deepguard-react:${{ steps.bump.outputs.new_tag }}`
branch: bump/docker-compose-react
delete-branch: true