-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: CI/CD 워크플로 작성 * chore: 도커 컴포즈 파일 작성 * chore: 도커파일 작성 * chore: 테스트 옵션 활성화 * fix: 오타 수정 * chore: 도커 액션에 디렉토리 컨텍스트 추가 * fix: JDK 벤더 변경 테스트 * chore: 도커 빌드엑스 세팅 추가 * refactor: gitkeep 삭제 * refactor: jdk 벤더 원복 * fix: gradle 빌드 액션 인자 수정 및 롤백 * fix: 빌드 액션 버전 변경 * fix: ssh-action 접속정보 추가 * fix: 도커 컴포즈 실행 명령어 변경 * fix: 명령어 인자 바인딩 방식 변경 * fix: 컴포즈 파일에 할당할 환경변수 추가 * chore: 컴포즈 파일에 타임존 추가 * chore: 디스코드로 빌드 스캔 결과 전송하는 워크플로 작성 * chore: 테스트 트리거 활성화 * docs: 주석 제거 * fix: 빌드 스텝 식별자 추가 * docs: 조금 더 비둘기스럽게 변경 * chore: 테스트 트리거 롤백 --------- Co-authored-by: [email protected] <[email protected]>
- Loading branch information
1 parent
3f67584
commit d0e1bf8
Showing
4 changed files
with
120 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
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,104 @@ | ||
name: Build and Deploy to Develop | ||
|
||
on: | ||
push: | ||
branches: [ "develop" ] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
environment: develop | ||
strategy: | ||
matrix: | ||
java-version: [ 17 ] | ||
distribution: [ 'temurin' ] | ||
outputs: | ||
image-tag: ${{ steps.image-tag.outputs.value }} | ||
steps: | ||
# 체크아웃 | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
# Docker 이미지 태그 세팅 | ||
- name: Set up image-tag by GITHUB_SHA | ||
id: image-tag | ||
run: echo "value=$(echo ${GITHUB_SHA::7})" >> $GITHUB_OUTPUT | ||
|
||
# JDK 17 버전으로 세팅 | ||
- name: Set up JDK 17 | ||
uses: actions/setup-java@v4 | ||
with: | ||
java-version: ${{ matrix.java-version }} | ||
distribution: ${{ matrix.distribution }} | ||
|
||
# Gradlew 실행 허용 | ||
- name: Run chmod to make gradlew executable | ||
run: chmod +x ./gradlew | ||
|
||
# Gradle 빌드 | ||
- name: Build with Gradle | ||
id: gradle | ||
uses: gradle/gradle-build-action@v2 | ||
with: | ||
arguments: | | ||
build | ||
--scan | ||
cache-read-only: ${{ github.ref != 'refs/heads/main' && github.ref != 'refs/heads/develop' }} # feature 브랜치는 캐시를 읽기 전용으로 설정 | ||
|
||
# Dockerhub 로그인 | ||
- name: Login to Dockerhub | ||
uses: docker/login-action@v3 | ||
with: | ||
username: ${{ secrets.DOCKERHUB_USERNAME }} | ||
password: ${{ secrets.DOCKERHUB_TOKEN }} | ||
|
||
# 이미지 빌드 및 Dockerhub에 푸시 | ||
- name: Docker Build and Push | ||
uses: docker/build-push-action@v5 | ||
with: | ||
context: . | ||
push: true | ||
tags: ${{ secrets.DOCKERHUB_USERNAME }}/gdsc-server:${{ steps.image-tag.outputs.value }} | ||
|
||
# docker-compose.yml 파일을 EC2 서버로 전송 | ||
- name: Copy docker-compose.yml to EC2 server | ||
uses: appleboy/[email protected] | ||
with: | ||
host: ${{ secrets.EC2_HOST }} | ||
username: ${{ secrets.EC2_USERNAME }} | ||
key: ${{ secrets.EC2_PRIVATE_KEY }} | ||
source: docker-compose.yml | ||
target: /home/ubuntu/ | ||
|
||
# 디스코드 둘기봇으로 gradle build scan 결과 발송 | ||
- name: Send Gradle Build Scan Result to Discord | ||
uses: Ilshidur/action-discord@master | ||
env: | ||
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }} | ||
DISCORD_EMBEDS: '[ | ||
{ | ||
"title": "푸드덕푸드덕푸드덕", | ||
"description": "구구구구국 구구...: ${{ steps.gradle.outputs.build-scan-url }}" | ||
} | ||
]' | ||
|
||
deploy: | ||
runs-on: ubuntu-latest | ||
environment: develop | ||
needs: build | ||
steps: | ||
- name: Deploy to EC2 Server | ||
uses: appleboy/ssh-action@master | ||
env: | ||
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} | ||
DOCKERHUB_IMAGE_TAG: ${{ needs.build.outputs.image-tag }} | ||
with: | ||
host: ${{ secrets.EC2_HOST }} | ||
username: ${{ secrets.EC2_USERNAME }} | ||
key: ${{ secrets.EC2_PRIVATE_KEY }} | ||
envs: DOCKERHUB_USERNAME,DOCKERHUB_IMAGE_TAG # docker-compose.yml 에서 사용할 환경 변수 | ||
script: | | ||
echo "${{ secrets.DOCKERHUB_TOKEN }}" | docker login -u "${{ secrets.DOCKERHUB_USERNAME }}" --password-stdin | ||
docker pull ${{ env.DOCKERHUB_USERNAME }}/gdsc-server:${{ env.DOCKERHUB_IMAGE_TAG }} | ||
docker compose -f /home/ubuntu/docker-compose.yml up -d | ||
docker image prune -a -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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
FROM amazoncorretto:17 | ||
ARG JAR_FILE=build/libs/*.jar | ||
COPY ${JAR_FILE} app.jar | ||
ENTRYPOINT ["java","-jar","/app.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
version: "3.8" | ||
|
||
services: | ||
backend: | ||
image: ${DOCKERHUB_USERNAME}/gdsc-server:${DOCKERHUB_IMAGE_TAG} | ||
container_name: gdsc-server | ||
restart: always | ||
network_mode: host | ||
env_file: | ||
- .env | ||
environment: | ||
- TZ=Asia/Seoul |