Skip to content

Commit 00816d4

Browse files
committed
feat: ci/cd 설정
1 parent cee301c commit 00816d4

File tree

2 files changed

+99
-0
lines changed

2 files changed

+99
-0
lines changed

.github/workflows/cicd.yml

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# This workflow uses actions that are not certified by GitHub.
2+
# They are provided by a third-party and are governed by
3+
# separate terms of service, privacy policy, and support
4+
# documentation.
5+
# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time
6+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle
7+
8+
name: CI/CD
9+
10+
#event trigger
11+
on:
12+
push:
13+
branches: [ "main" ]
14+
15+
permissions:
16+
contents: read
17+
18+
jobs:
19+
build:
20+
runs-on: ubuntu-latest
21+
steps:
22+
- uses: actions/checkout@v3
23+
24+
# JDK 17 설정
25+
- name: Set up JDK 17
26+
uses: actions/setup-java@v3
27+
with:
28+
java-version: '17'
29+
distribution: 'oracle'
30+
31+
# Gradle 설정
32+
- name: Setup Gradle
33+
uses: gradle/gradle-build-action@v2
34+
35+
# Docker Hub 로그인
36+
- name: Login to Docker Hub
37+
uses: docker/login-action@v1
38+
with:
39+
username: ${{ secrets.DOCKER_USERNAME }}
40+
password: ${{ secrets.DOCKER_PASSWORD }}
41+
42+
# gradlew 파일 권한 지정
43+
- name: Grant execute permission for gradlew
44+
run: chmod +x gradlew
45+
46+
# gradle Jib를 이용해 이미지를 만들고 원격 저장소에 Push
47+
- name: Setup Jib with Gradle
48+
run: ./gradlew jib
49+
50+
# GET GitHub IP
51+
- name: Get Github Actions IP
52+
id: ip
53+
uses: haythem/[email protected]
54+
55+
# AWS 접근 권한 취득(IAM)
56+
- name: Configure AWS Credentials
57+
uses: aws-actions/configure-aws-credentials@v1
58+
with:
59+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
60+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
61+
aws-region: ap-northeast-2
62+
63+
# github ip AWS 보안 그룹에 추가
64+
- name: Add Github Actions IP to Security group
65+
run: |
66+
aws ec2 authorize-security-group-ingress --group-id ${{ secrets.AWS_SG_ID }} --protocol tcp --port 22 --cidr ${{ steps.ip.outputs.ipv4 }}/32
67+
68+
# ssh로 접속해 재배포
69+
- name: Deploy
70+
uses: appleboy/ssh-action@master
71+
with:
72+
host: ${{ secrets.REMOTE_IP }}
73+
username: ${{ secrets.REMOTE_SSH_ID }}
74+
key: ${{ secrets.REMOTE_SSH_KEY }}
75+
port: ${{ secrets.REMOTE_SSH_PORT }}
76+
script: |
77+
cd docker
78+
docker-compose pull
79+
docker-compose up -d
80+
81+
# 배포 후 보안 그룹에서 github ip 삭제
82+
- name: Remove Github Actions IP From Security Group
83+
run: |
84+
aws ec2 revoke-security-group-ingress --group-id ${{ secrets.AWS_SG_ID }} --protocol tcp --port 22 --cidr ${{ steps.ip.outputs.ipv4 }}/32

build.gradle

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,21 @@ plugins {
22
id 'java'
33
id 'org.springframework.boot' version '3.3.1'
44
id 'io.spring.dependency-management' version '1.1.5'
5+
id 'com.google.cloud.tools.jib' version '3.4.2'
6+
}
7+
8+
jib {
9+
from {
10+
image = "openjdk:17-jdk-alpine"
11+
}
12+
to {
13+
image = "kikingki/itit"
14+
tags = ['latest']
15+
}
16+
container {
17+
environment = [TZ: "Asia/Seoul"]
18+
jvmFlags = ['-XX:+UseContainerSupport', '-Dfile.encoding=UTF-8', '-Duser.timezone="Asia/Seoul"']
19+
}
520
}
621

722
group = 'com.dissonance'

0 commit comments

Comments
 (0)