-
Notifications
You must be signed in to change notification settings - Fork 0
121 lines (104 loc) · 3.67 KB
/
Copy pathdevelop_build_deploy.yml
File metadata and controls
121 lines (104 loc) · 3.67 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
name: Development Build & Deploy
on:
push:
branches:
- develop
workflow_dispatch:
# permission can be added at job level or workflow level
permissions:
id-token: write # This is required for requesting the JWT
contents: read # This is required for actions/checkout
jobs:
deploy:
name: CD
runs-on: ubuntu-latest
env:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_IMAGE_NAME: pida-dev
strategy:
matrix:
java-version: [ "21" ]
kotlin-version: [ "2.1.0" ]
distribution: [ "corretto" ]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up JDK ${{ matrix.java-version }}
uses: actions/setup-java@v3
with:
java-version: ${{ matrix.java-version }}
kotlin-version: ${{ matrix.kotlin-version }}
distribution: ${{ matrix.distribution }}
- name: Grant execute permission for gradlew
run: chmod +x ./gradlew
- name: Build with Gradle
id: gradle
uses: gradle/gradle-build-action@v3
with:
arguments: |
:pida-core:core-api:build
--scan
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: ap-northeast-2
role-to-assume: ${{ secrets.OIDC_ROLE_TO_ASSUME }}
role-session-name: pida-server
# Dockerhub 로그인
- name: Login to Dockerhub
uses: docker/login-action@v3
with:
username: ${{ env.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_ACCESS_TOKEN }}
# Docker 메타데이터 추출
- name: Extract Docker metadata
id: metadata
uses: docker/metadata-action@v5.5.0
env:
DOCKERHUB_IMAGE_FULL_NAME: ${{ env.DOCKERHUB_USERNAME }}/${{ env.DOCKERHUB_IMAGE_NAME }}
with:
images: ${{ env.DOCKERHUB_IMAGE_FULL_NAME }}
tags: |
type=sha,prefix=
# 멀티 아키텍처 지원을 위한 QEMU 설정
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
# 도커 확장 빌드를 위한 Buildx 설정
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
# Docker 이미지 빌드 및 도커허브로 푸시
- name: Docker Build and Push
uses: docker/build-push-action@v5
with:
context: .
file: ./docker/DockerfileDev
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.metadata.outputs.tags }}
# 서버로 docker-compose 파일 전송
- name: Copy docker-compose file to EC2
uses: burnett01/rsync-deployments@7.0.1
with:
switches: -avzr --delete
remote_host: ${{ secrets.EC2_HOST }}
remote_user: ${{ secrets.EC2_USERNAME }}
remote_key: ${{ secrets.EC2_PRIVATE_KEY }}
path: ./docker/docker-compose.yml
remote_path: /home/ec2-user/app
# EC2로 배포
- name: Deploy to EC2 Server
uses: appleboy/ssh-action@v1.0.3
env:
IMAGE_FULL_URL: ${{ steps.metadata.outputs.tags }}
DOCKERHUB_IMAGE_NAME: ${{ env.DOCKERHUB_IMAGE_NAME }}
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USERNAME }}
key: ${{ secrets.EC2_PRIVATE_KEY }}
envs: IMAGE_FULL_URL, DOCKERHUB_IMAGE_NAME
debug: true
script: |
echo "${{ secrets.DOCKERHUB_ACCESS_TOKEN }}" | docker login -u "${{ env.DOCKERHUB_USERNAME }}" --password-stdin
cd ~/app
docker compose up -d
docker image prune -a -f