-
Notifications
You must be signed in to change notification settings - Fork 0
58 lines (46 loc) · 1.9 KB
/
CICD.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
name: CICD
on: #어느 상황에서 실행되는지 설정
pull_request:
branches: [ "deploy" ]
permissions:
contents: read # 읽기 전용으로 생성
jobs:
build:
runs-on: ubuntu-latest # ubuntu 최신 버전에서 실행됨
steps:
- uses: actions/checkout@v3
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'temurin'
# github에 있는 secretKey를 이용해서 application-dev.yml 생성
- uses: actions/checkout@v3
- name: Make application-dev.yml
run: |
mkdir -p src/main/resources
echo "${{ secrets.PROPERTIES }}" > src/main/resources/application-dev.yml
find src
- name: Grant execute permission for gradlew
run: chmod +x ./gradlew
shell: bash
- name: Build with Gradle
run: ./gradlew build
shell: bash
- name: Docker build
run: |
docker login -u ${{ secrets.DOCKER_ID }} -p ${{ secrets.DOCKER_PW }}
docker build --progress plain -t ${{ secrets.DOCKER_ID }}/${{ secrets.DOCKER_IMAGE_NAME }} .
docker push ${{ secrets.DOCKER_ID }}/${{ secrets.DOCKER_IMAGE_NAME }}
# 도커 이미지를 빌드하고, 로그인 한 후 푸시합니다.
- name: EC2 Deploy
uses: appleboy/[email protected]
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USERNAME }}
key: ${{ secrets.EC2_KEY }}
script: |
docker pull ${{ secrets.DOCKER_ID }}/${{ secrets.DOCKER_IMAGE_NAME }}
docker stop codingfriends_server-container
docker run -d --rm --name codingfriends-container -p 8080:8080 ${{ secrets.DOCKER_ID }}/${{ secrets.DOCKER_IMAGE_NAME }}
# EC2 인스턴스로 SSH 연결하여 도커 이미지를 풀링하고 컨테이너를 생성합니다.