-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Weekly/10/Deploy/CICD] CI/CD 관련 스크립트 추가 (#74)
- Loading branch information
Showing
4 changed files
with
84 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
name: CI/CD Github Action | ||
|
||
on: | ||
push: | ||
branches: [ "Master", "Weekly/*" ] | ||
pull_request: | ||
branches: [ "Master", "Weekly/*" ] | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
CI-CD: | ||
runs-on: ubuntu-22.04 | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Set up JDK 21 | ||
uses: actions/setup-java@v4 | ||
with: | ||
java-version: '21' | ||
distribution: 'corretto' | ||
|
||
- name: Gradle Caching (for faster build) | ||
uses: actions/cache@v3 | ||
with: | ||
path: | | ||
~/.gradle/caches | ||
~/.gradle/wrapper | ||
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} | ||
restore-keys: | | ||
${{ runner.os }}-gradle- | ||
# 테스트까지 포함해 빌드하려면 -x test를 제거하기 | ||
- name: Build With Gradle (exclude test) | ||
run: | | ||
chmod +x gradlew | ||
./gradlew clean build -x test | ||
- name: Docker Hub Login | ||
uses: docker/login-action@v3 | ||
with: | ||
username: ${{ secrets.DOCKER_USERNAME }} | ||
password: ${{ secrets.DOCKER_TOKEN }} | ||
|
||
- name: Docker Build & Push | ||
run: | | ||
docker build -f Dockerfile --build-arg DEPENDENCY=build/dependency --platform linux/amd64 -t ${{ secrets.DOCKER_REPO_FULLNAME }} . | ||
docker push ${{ secrets.DOCKER_REPO_FULLNAME }} | ||
- name: Deploy to Server | ||
uses: appleboy/ssh-action@master | ||
with: | ||
host: ${{ secrets.SSH_HOST }} # EC2 퍼블릭 IPv4 DNS | ||
username: ${{ secrets.SSH_USERNAME }} | ||
key: ${{ secrets.SSH_PRIVATE_KEY }} | ||
port: ${{ secrets.SSH_PORT }} | ||
envs: GITHUB_SHA | ||
script: | | ||
echo "[script] docker pull" | ||
sudo docker pull ${{ secrets.DOCKER_REPO_FULLNAME }} | ||
echo "[script] docker stop" | ||
sudo docker stop would-you-in | ||
echo "[script] docker run" | ||
sudo docker run --rm -d -p 80:8080 --env-file ~/.env --name would-you-in ${{ secrets.DOCKER_REPO_FULLNAME }} | ||
echo "[script] docker image clean-up" | ||
sudo docker image prune -f |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,3 +38,6 @@ out/ | |
|
||
### static images | ||
/src/main/resources/staticimages/ | ||
|
||
### env file | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# open jdk 21 버전의 환경을 구성한다. | ||
FROM openjdk:21-jdk-slim | ||
|
||
# build가 될 때 JAR_FILE이라는 변수 명에 build/libs/*.jar 선언 | ||
# build/libs - gradle로 빌드했을 때 jar 파일이 생성되는 경로임 | ||
ARG JAR_FILE=build/libs/*.jar | ||
|
||
# JAR_FILE을 agaproject.jar로 복사 (이 부분(.jar)은 개발환경에 따라 다름) | ||
COPY ${JAR_FILE} wouldyouin.jar | ||
|
||
# 운영 및 개발에서 사용되는 환경 설정을 분리한다. | ||
ENTRYPOINT ["java", "-jar", "-Dspring.profiles.active=deploy", "/wouldyouin.jar"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters