-
Notifications
You must be signed in to change notification settings - Fork 1
92 lines (79 loc) · 2.77 KB
/
CI_CD.yml
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
91
92
name: CI/CD
# Action Trigger
on:
push:
branches:
- 'main'
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
# JAVA 17 설정(corretto 배포)
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'corretto'
# Gradlew 실행 권한 부여
- name: Grant execute permission for gradlew
run: chmod +x gradlew
# Gradlew 빌드 실행(test 생략)
- name: Build with Gradle
run: ./gradlew build -x test
# 다중 아키텍쳐 배포를 위한 설정
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
# Buildx를 사용 설정
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
# Docker 로그인
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_PASSWORD }}
# DockerHub에 push
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: geumyeon/calendar:latest
platforms: linux/amd64,linux/arm64
# AWS 로그인
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ap-northeast-2
# AWS 세션 매니저 접속
- name: Start Session Manager session
run: aws ssm start-session --target i-0d06e891326522e28
# 배포
- name: Deploy to Server
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: ap-northeast-2
run: |
aws ssm send-command \
--instance-ids i-0d06e891326522e28 \
--document-name "AWS-RunShellScript" \
--parameters "commands=[
'if sudo docker ps -a --format \\'{{.Names}}\\' | grep -q \'^calendar$\\'; then',
' sudo docker stop calendar',
' sudo docker rm calendar',
'fi',
'if sudo docker ps -a --format \\'{{.Names}}\\' | grep -q \'^redis$\\'; then',
' sudo docker stop redis',
' sudo docker rm redis',
'fi',
'sudo docker rmi geumyeon/calendar:latest',
'sudo docker rmi calendar:latest',
'sudo docker pull geumyeon/calendar:latest',
'sudo docker tag geumyeon/calendar:latest calendar',
'sudo docker compose up -d'
]" \
--output text