-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[CHORE] CI/CD 세팅, Swagger 제목, 설명 변경
- Loading branch information
Showing
7 changed files
with
159 additions
and
7 deletions.
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
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
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,84 @@ | ||
name: Docker Hub Dev Deploy | ||
|
||
run-name: ${{ github.head_ref }} 브랜치 작업 내용 병합 후 배포 | ||
|
||
on: | ||
push: | ||
branches: | ||
- develop | ||
|
||
jobs: | ||
deploy: | ||
runs-on: ubuntu-latest | ||
steps: | ||
# develop 브랜치 체크아웃 | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
# application.yml 파일 생성 | ||
- name: make application.yml | ||
run: | | ||
# create application.yml | ||
cd ./src/main | ||
cd .resources | ||
touch ./application.yml | ||
echo "${{ secrets.APPLICATION_DEV_YML }}" >> ./application.yml | ||
# 빌드 권한 부여 | ||
- name: Grant execute permission for gradlew | ||
run: chmod +x ./gradlew | ||
|
||
# docker image 빌드 | ||
- name: Build | ||
run: docker build --no-cache -t ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_IMAGE_NAME }}:${{ secrets.DOCKERHUB_IMAGE_TAG }} . | ||
|
||
# docker hub 로그인 | ||
- name: Docker Hub login | ||
uses: docker/login-action@v3 | ||
with: | ||
username: ${{ secretes.DOCKERHUB_USERNAME }} | ||
password: ${{ secretes.DOCKERHUB_TOKEN_READ_WRITE }} | ||
|
||
# docker hub에 image push | ||
- name: docker image push | ||
run: docker push ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_IMAGE_NAME}}:${{secrets.DOCKERHUB_IMAGE_TAG }} | ||
|
||
# docker compose에 사용될 환경 변수들이 담긴 env 파일 세팅 | ||
- name: Set up environment variables | ||
run: | | ||
echo "DOCKER_USERNAME=${{ secrets.DOCKERHUB_USERNAME }}" >> dev.env | ||
echo "DOCKER_IMAGE_NAME=${{ secrets.DOCKERHUB_IMAGE_NAME }}" >> dev.env | ||
echo "DOCKER_IMAGE_TAG=${{ secrets.DOCKERHUB_IMAGE_TAG }}" >> dev.env | ||
echo "SPRING_OUTER_PORT=${{ secrets.SPRING_OUTER_PORT }}" >> dev.env | ||
echo "SPRING_INNER_PORT=${{ secrets.SPRING_INNER_PORT }}" >> dev.env | ||
# compose.yml, dev.env 파일 서버로 복사 | ||
- name: Copy compose.yml, dev.env | ||
uses: appleboy/scp-action@master | ||
with: | ||
host: ${{ secrets.SSH_HOST }} | ||
port: ${{ secrets.SSH_PORT }} | ||
username: ${{ secrets.SSH_USERNAME }} | ||
key: ${{ secrets.SSH_PRIVATE_KEY }} | ||
source: "compose.yml, dev.env" | ||
target: /home/ubuntu | ||
|
||
# EC2에서 docker compose up | ||
- name: Deploy to Server | ||
uses: appleboy/ssh-action@master | ||
with: | ||
host: ${{ secrets.SSH_HOST }} | ||
port: ${{ secrets.SSH_PORT }} | ||
username: ${{ secrets.SSH_USERNAME }} | ||
key: ${{ secrets.SSH_PRIVATE_KEY }} | ||
script: | | ||
cd /home/ubuntu | ||
sudo docker login -u ${{ secrets.DOCKERHUB_USERNAME }} -p ${{ secrets.DOCKERHUB_TOKEN_READ_ONLY }} | ||
sudo docker container stop naoman-dev | ||
sudo docker container rm naoman-dev | ||
sudo docker image rm ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_IMAGE_NAME}}:${{secrets.DOCKERHUB_IMAGE_TAG }} | ||
sudo docker compose --env-file dev.env -f compose.yml up -d | ||
sudo docker container prune -f | ||
sudo 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,32 @@ | ||
# base 이미지 가져오기 | ||
# 최신 버전의 alpine 사용 | ||
# 빌드 스테이지를 builder라고 명명 | ||
FROM amazoncorretto:17-alpine-jdk AS builder | ||
|
||
# 작업 디렉토리 /app 으로 설정 | ||
WORKDIR /app | ||
|
||
# gradlew, build.gradle, settings.gradle, gradle, src 복사 | ||
COPY gradlew build.gradle settings.gradle ./ | ||
COPY gradle ./gradle | ||
COPY src ./src | ||
|
||
# jar 파일 생성을 위한 bootJar 실행 | ||
RUN ./gradlew bootJar | ||
|
||
# 2번째 빌드 스테이지 | ||
# base 이미지 가져오기 | ||
FROM amazoncorretto:17-alpine-jdk | ||
|
||
# 작업 디렉토리 설정 | ||
WORKDIR /app | ||
|
||
# jar 파일 가져오기 | ||
# 이전 빌드 스테이지 'builder'에서 생성된 jar 파일을 복사 | ||
COPY --from=builder /app/build/libs/*.jar /app/naoman.jar | ||
|
||
# 8080 포트를 사용함을 명시 | ||
EXPOSE 8080 | ||
|
||
# 컨테이너 실행 시 naoman.jar 파일 실행 | ||
ENTRYPOINT java -jar /app/naoman.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
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,29 @@ | ||
services: | ||
spring-application: | ||
container_name: naoman-dev | ||
image: ${DOCKER_USERNAME}/${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_TAG} | ||
ports: | ||
- ${SPRING_OUTER_PORT}:${SPRING_INNER_PORT} | ||
|
||
nginx: | ||
container_name: nginx-dev | ||
image: nginx:latest | ||
volumes: | ||
- ./naoman/default.conf:/etc/nginx/conf.d/efault/conf | ||
restart: always | ||
ports: | ||
- 80:80 | ||
|
||
# 설정을 6시간마다 다시 로드하여 최신 상태를 유지한다. | ||
# 포그라운드 실행을 통해 Nginx 서버를 계속 실행시킨다. | ||
command: [ | ||
"/bin/sh", | ||
"-c", | ||
"while :; do sleep 6h && wait $${!}; nginx -s reload; done & nginx -g 'daemon off;'" | ||
] | ||
|
||
redis: | ||
container_name: redis-dev | ||
image: redis:7.2.5 | ||
ports: | ||
- 6379:6379 |
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