Skip to content

Commit 387babe

Browse files
committed
go release 코드 통합
1 parent 7bf6c68 commit 387babe

File tree

4 files changed

+52
-161
lines changed

4 files changed

+52
-161
lines changed

.github/workflows/release.yml

Lines changed: 33 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
name: Deploy Services
22
on:
33
push:
4-
branches:
5-
- release
6-
paths:
7-
- "src/backend/**"
8-
- "src/go/**"
4+
branches: [release]
5+
paths: ["src/backend/**", "src/go/**"]
96
workflow_dispatch:
107

118
jobs:
@@ -135,12 +132,22 @@ jobs:
135132
script: |
136133
docker exec backend-service npx prisma migrate deploy --schema=/app/prisma/schema.prisma
137134
138-
deploy-market-item-stat-scraper:
139-
name: Build and Deploy Market Item Stat Scraper
135+
deploy-go-services:
136+
strategy:
137+
matrix:
138+
include:
139+
- name: market-item-stat-scraper
140+
app-path: src/go/apps/market-item-stat-scraper
141+
host-secret: MISS_EC2_HOST
142+
ssh-key-secret: MISS_EC2_SSH_KEY
143+
- name: auction-item-stat-scraper
144+
app-path: src/go/apps/auction-item-stat-scraper
145+
host-secret: AISS_EC2_HOST
146+
ssh-key-secret: AISS_EC2_SSH_KEY
147+
name: Build and Deploy ${{ matrix.name }}
140148
runs-on: ubuntu-latest
141149
steps:
142-
- name: Checkout code
143-
uses: actions/checkout@v3
150+
- uses: actions/checkout@v3
144151

145152
- name: Configure AWS credentials for ECR
146153
uses: aws-actions/configure-aws-credentials@v1
@@ -158,108 +165,22 @@ jobs:
158165
ECR_REGISTRY: ${{ secrets.ECR_REGISTRY }}
159166
IMAGE_TAG: ${{ github.sha }}
160167
run: |
161-
docker build -t $ECR_REGISTRY/loa-life:market-item-stat-scraper-$IMAGE_TAG -f src/go/apps/market-item-stat-scraper/Dockerfile .
162-
docker push $ECR_REGISTRY/loa-life:market-item-stat-scraper-$IMAGE_TAG
163-
docker tag $ECR_REGISTRY/loa-life:market-item-stat-scraper-$IMAGE_TAG $ECR_REGISTRY/loa-life:market-item-stat-scraper-latest
164-
docker push $ECR_REGISTRY/loa-life:market-item-stat-scraper-latest
165-
166-
- name: Install AWS CLI on EC2
167-
uses: appleboy/ssh-action@master
168-
with:
169-
host: ${{ secrets.MISS_EC2_HOST }}
170-
username: ubuntu
171-
key: ${{ secrets.MISS_EC2_SSH_KEY }}
172-
script: |
173-
if ! command -v aws &> /dev/null; then
174-
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
175-
sudo apt install -y unzip
176-
unzip awscliv2.zip
177-
sudo ./aws/install
178-
rm -rf aws awscliv2.zip
179-
fi
180-
181-
if ! command -v docker &> /dev/null; then
182-
sudo apt-get update
183-
sudo apt-get install -y ca-certificates curl gnupg
184-
sudo install -m 0755 -d /etc/apt/keyrings
185-
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
186-
sudo chmod a+r /etc/apt/keyrings/docker.gpg
187-
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
188-
sudo apt-get update
189-
sudo apt-get install -y docker-ce docker-ce-cli containerd.io
190-
sudo usermod -aG docker ubuntu
191-
fi
192-
193-
# Configure AWS CLI
194-
mkdir -p ~/.aws
195-
cat > ~/.aws/credentials << EOF
196-
[default]
197-
aws_access_key_id = ${{ secrets.AWS_ACCESS_KEY_ID }}
198-
aws_secret_access_key = ${{ secrets.AWS_SECRET_ACCESS_KEY }}
199-
EOF
200-
201-
cat > ~/.aws/config << EOF
202-
[default]
203-
region = ap-northeast-2
204-
output = json
205-
EOF
168+
docker build \
169+
--build-arg APP_PATH=${{ matrix.app-path }} \
170+
-t $ECR_REGISTRY/loa-life:${{ matrix.name }}-$IMAGE_TAG \
171+
-f src/go/Dockerfile .
172+
docker push $ECR_REGISTRY/loa-life:${{ matrix.name }}-$IMAGE_TAG
173+
docker tag $ECR_REGISTRY/loa-life:${{ matrix.name }}-$IMAGE_TAG $ECR_REGISTRY/loa-life:${{ matrix.name }}-latest
174+
docker push $ECR_REGISTRY/loa-life:${{ matrix.name }}-latest
206175
207176
- name: Deploy to EC2
208177
uses: appleboy/ssh-action@master
209178
with:
210-
host: ${{ secrets.MISS_EC2_HOST }}
179+
host: ${{ secrets[matrix.host-secret] }}
211180
username: ubuntu
212-
key: ${{ secrets.MISS_EC2_SSH_KEY }}
213-
script: |
214-
aws ecr get-login-password --region ap-northeast-2 | docker login --username AWS --password-stdin ${{ secrets.ECR_REGISTRY }}
215-
docker pull ${{ secrets.ECR_REGISTRY }}/loa-life:market-item-stat-scraper-latest
216-
217-
docker stop market-item-stat-scraper || true
218-
docker rm market-item-stat-scraper || true
219-
220-
docker run -d \
221-
--name market-item-stat-scraper \
222-
-e DATABASE_URL="${{ secrets.DATABASE_URL }}" \
223-
-e LOA_API_BASE_URL="${{ secrets.LOA_API_BASE_URL }}" \
224-
-e LOA_API_TOKEN="${{ secrets.LOA_API_TOKEN }}" \
225-
--restart always \
226-
${{ secrets.ECR_REGISTRY }}/loa-life:market-item-stat-scraper-latest
227-
228-
deploy-auction-item-stat-scraper:
229-
name: Build and Deploy Auction Item Stat Scraper
230-
runs-on: ubuntu-latest
231-
steps:
232-
- name: Checkout code
233-
uses: actions/checkout@v3
234-
235-
- name: Configure AWS credentials for ECR
236-
uses: aws-actions/configure-aws-credentials@v1
237-
with:
238-
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
239-
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
240-
aws-region: ap-northeast-2
241-
242-
- name: Login to Amazon ECR
243-
id: login-ecr
244-
uses: aws-actions/amazon-ecr-login@v1
245-
246-
- name: Build and Push Docker image
247-
env:
248-
ECR_REGISTRY: ${{ secrets.ECR_REGISTRY }}
249-
IMAGE_TAG: ${{ github.sha }}
250-
run: |
251-
docker build -t $ECR_REGISTRY/loa-life:auction-item-stat-scraper-$IMAGE_TAG -f src/go/apps/auction-item-stat-scraper/Dockerfile .
252-
docker push $ECR_REGISTRY/loa-life:auction-item-stat-scraper-$IMAGE_TAG
253-
docker tag $ECR_REGISTRY/loa-life:auction-item-stat-scraper-$IMAGE_TAG $ECR_REGISTRY/loa-life:auction-item-stat-scraper-latest
254-
docker push $ECR_REGISTRY/loa-life:auction-item-stat-scraper-latest
255-
256-
- name: Install AWS CLI on EC2
257-
uses: appleboy/ssh-action@master
258-
with:
259-
host: ${{ secrets.AISS_EC2_HOST }}
260-
username: ubuntu
261-
key: ${{ secrets.AISS_EC2_SSH_KEY }}
181+
key: ${{ secrets[matrix.ssh-key-secret] }}
262182
script: |
183+
# Install AWS CLI if not exists
263184
if ! command -v aws &> /dev/null; then
264185
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
265186
sudo apt install -y unzip
@@ -268,6 +189,7 @@ jobs:
268189
rm -rf aws awscliv2.zip
269190
fi
270191
192+
# Install Docker if not exists
271193
if ! command -v docker &> /dev/null; then
272194
sudo apt-get update
273195
sudo apt-get install -y ca-certificates curl gnupg
@@ -294,23 +216,17 @@ jobs:
294216
output = json
295217
EOF
296218
297-
- name: Deploy to EC2
298-
uses: appleboy/ssh-action@master
299-
with:
300-
host: ${{ secrets.AISS_EC2_HOST }}
301-
username: ubuntu
302-
key: ${{ secrets.AISS_EC2_SSH_KEY }}
303-
script: |
219+
# Deploy container
304220
aws ecr get-login-password --region ap-northeast-2 | docker login --username AWS --password-stdin ${{ secrets.ECR_REGISTRY }}
305-
docker pull ${{ secrets.ECR_REGISTRY }}/loa-life:auction-item-stat-scraper-latest
221+
docker pull ${{ secrets.ECR_REGISTRY }}/loa-life:${{ matrix.name }}-latest
306222
307-
docker stop auction-item-stat-scraper || true
308-
docker rm auction-item-stat-scraper || true
223+
docker stop ${{ matrix.name }} || true
224+
docker rm ${{ matrix.name }} || true
309225
310226
docker run -d \
311-
--name auction-item-stat-scraper \
227+
--name ${{ matrix.name }} \
312228
-e DATABASE_URL="${{ secrets.DATABASE_URL }}" \
313229
-e LOA_API_BASE_URL="${{ secrets.LOA_API_BASE_URL }}" \
314230
-e LOA_API_TOKEN="${{ secrets.LOA_API_TOKEN }}" \
315231
--restart always \
316-
${{ secrets.ECR_REGISTRY }}/loa-life:auction-item-stat-scraper-latest
232+
${{ secrets.ECR_REGISTRY }}/loa-life:${{ matrix.name }}-latest

src/go/Dockerfile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
FROM golang:1.23-alpine AS builder
2+
3+
ARG APP_PATH
4+
WORKDIR /app
5+
6+
COPY . .
7+
WORKDIR /app/${APP_PATH}
8+
9+
RUN go mod download
10+
RUN CGO_ENABLED=0 GOOS=linux go build -o app .
11+
12+
FROM alpine:latest
13+
WORKDIR /app
14+
15+
RUN apk --no-cache add tzdata
16+
ENV TZ=Asia/Seoul
17+
18+
COPY --from=builder /app/${APP_PATH}/app /app/app
19+
CMD ["/app/app"]

src/go/apps/auction-item-stat-scraper/Dockerfile

Lines changed: 0 additions & 22 deletions
This file was deleted.

src/go/apps/market-item-stat-scraper/Dockerfile

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)