-
Notifications
You must be signed in to change notification settings - Fork 2
80 lines (64 loc) · 2.8 KB
/
Copy pathsub-deloy.yml
File metadata and controls
80 lines (64 loc) · 2.8 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
name: Docker Deploy (Dev/Stg)
on:
push:
branches:
- dev
- stg
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Get short commit SHA and branch
id: vars
run: |
echo "SHORT_SHA=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
echo "BRANCH=${{ github.ref_name }}" >> $GITHUB_OUTPUT
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/bannote-studyroom-service:${{ steps.vars.outputs.BRANCH }}-${{ steps.vars.outputs.SHORT_SHA }}
cache-from: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/bannote-studyroom-service:buildcache
cache-to: type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/bannote-studyroom-service:buildcache,mode=max
- name: Image deployed
run: |
echo "🚀 Docker image pushed to Docker Hub!"
echo "📦 Image: ${{ secrets.DOCKERHUB_USERNAME }}/bannote-studyroom-service:${{ steps.vars.outputs.BRANCH }}-${{ steps.vars.outputs.SHORT_SHA }}"
- name: Checkout infra repository
uses: actions/checkout@v4
with:
repository: gsc-lab/cs25-1-bannote-infra
token: ${{ secrets.GH_PAT }}
path: infra
- name: Update Helm values.yaml
run: |
cd infra
BRANCH="${{ steps.vars.outputs.BRANCH }}"
VALUES_FILE="helm/service/studyroom-service/values/${BRANCH}/values.yaml"
NEW_TAG="${BRANCH}-${{ steps.vars.outputs.SHORT_SHA }}"
# Install yq for YAML manipulation
sudo wget -qO /usr/local/bin/yq https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64
sudo chmod +x /usr/local/bin/yq
# Update tag in values.yaml
yq eval ".image.tag = \"$NEW_TAG\"" -i "$VALUES_FILE"
echo "✅ Updated tag to: $NEW_TAG"
- name: Commit and push changes
run: |
cd infra
BRANCH="${{ steps.vars.outputs.BRANCH }}"
git config user.name "github-actions[studyroom-service]"
git config user.email "github-actions[studyroom-service]@users.noreply.github.com"
git add helm/service/studyroom-service/values/${BRANCH}/values.yaml
git commit -m "chore: update studyroom-service ${BRANCH} image tag to ${BRANCH}-${{ steps.vars.outputs.SHORT_SHA }}"
git push
echo "🚀 Infra repository updated successfully!"