Skip to content

Commit 13c57b9

Browse files
committed
Chore: 도커 이미지 태그 (dev, staging)으로 변경/분기 처리 및 배포 분기 처리
1 parent 6f25d5c commit 13c57b9

File tree

2 files changed

+33
-12
lines changed

2 files changed

+33
-12
lines changed

.github/workflows/ci-cd.yml

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ name: CI/CD — Backend (Build → Push → Deploy)
22

33
on:
44
push:
5-
branches: [ dev ]
5+
branches: [ dev, staging ]
66
pull_request:
7-
branches: [ dev ]
7+
branches: [ dev, staging ]
88
workflow_dispatch:
99
inputs:
1010
tag:
1111
description: "배포할 이미지 태그 (ex. release or <GIT_SHA>)"
1212
required: false
13-
default: "release"
13+
default: "dev"
1414

1515
concurrency:
1616
group: cicd-${{ github.ref_name }}
@@ -81,17 +81,32 @@ jobs:
8181
username: ${{ github.actor }}
8282
password: ${{ secrets.GITHUB_TOKEN }}
8383

84-
- name: Build & Push image
84+
- name: Decide tags by branch
85+
if: github.event_name == 'push'
86+
id: tags
87+
shell: bash
88+
run: |
89+
REF="${{ github.ref_name }}" # dev / staging
90+
SHORT_SHA="${GITHUB_SHA::7}"
91+
SAFE_REF=$(echo "$REF" | tr '[:upper:]' '[:lower:]' | sed -E 's#[^a-z0-9._-]+#-#g')
92+
echo "channel=$SAFE_REF" >> $GITHUB_OUTPUT # ex) dev, staging
93+
echo "version=${SAFE_REF}-${SHORT_SHA}" >> $GITHUB_OUTPUT # ex) dev-abc1234
94+
95+
- name: Build & Push (branch-tagged)
8596
if: github.event_name == 'push'
8697
run: |
87-
GIT_SHA=${{ github.sha }}
88-
docker build -f "${{ steps.df.outputs.path }}" -t $IMAGE:release -t $IMAGE:$GIT_SHA "${{ steps.df.outputs.ctx }}"
89-
docker push $IMAGE:release
90-
docker push $IMAGE:$GIT_SHA
98+
CHAN=${{ steps.tags.outputs.channel }} # dev | staging
99+
VER=${{ steps.tags.outputs.version }} # dev-<sha> | staging-<sha>
100+
docker build -f "${{ steps.df.outputs.path }}" \
101+
-t $IMAGE:$CHAN \
102+
-t $IMAGE:$VER \
103+
"${{ steps.df.outputs.ctx }}"
104+
docker push $IMAGE:$CHAN
105+
docker push $IMAGE:$VER
91106
92107
deploy:
93108
needs: build-and-push
94-
if: github.event_name == 'push' && (github.ref == 'refs/heads/dev') &&
109+
if: github.event_name == 'push' && (github.ref == 'refs/heads/dev' || github.ref == 'refs/heads/staging') &&
95110
(needs.build-and-push.result == 'success')
96111
|| (github.event_name == 'workflow_dispatch')
97112
runs-on: ubuntu-latest
@@ -103,7 +118,7 @@ jobs:
103118
if [ "${{ github.event_name }}" = "workflow_dispatch" ] && [ -n "${{ github.event.inputs.tag }}" ]; then
104119
echo "value=${{ github.event.inputs.tag }}" >> $GITHUB_OUTPUT
105120
else
106-
echo "value=release" >> $GITHUB_OUTPUT
121+
echo "value=${{ github.ref_name }}" >> $GITHUB_OUTPUT
107122
fi
108123
109124
- name: Deploy
@@ -115,4 +130,10 @@ jobs:
115130
port: ${{ secrets.CD_PORT }}
116131
script: |
117132
export DEPLOY_TAG='${{ steps.tag.outputs.value }}'
118-
bash -lc '/srv/docsa/infra/deploy.sh'
133+
if [ "${{ github.ref_name }}" = "staging" ]; then
134+
bash -lc '/srv/docsa-stg/infra/deploy.sh'
135+
else
136+
bash -lc '/srv/docsa/infra/deploy.sh'
137+
fi
138+
139+

infra/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: docsa-stg
22

33
services:
44
app:
5-
image: ghcr.io/prgrms-web-devcourse-final-project/docsa-backend:release
5+
image: ghcr.io/prgrms-web-devcourse-final-project/docsa-backend:dev
66
container_name: docsa-app-stg
77
restart: unless-stopped
88
env_file: .env

0 commit comments

Comments
 (0)