Skip to content

Commit

Permalink
[All] release: 리뷰미 v1.1.0 배포
Browse files Browse the repository at this point in the history
[All] release: 리뷰미 v1.1.0 배포
  • Loading branch information
donghoony authored Sep 26, 2024
2 parents 7b442c9 + b08c5e4 commit 00c11b9
Show file tree
Hide file tree
Showing 418 changed files with 8,666 additions and 5,394 deletions.
69 changes: 29 additions & 40 deletions .github/workflows/backend-dev-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ on:
env:
ARTIFACT_NAME: review-me-dev
ARTIFACT_DIRECTORY: ./backend/build/libs
APPLICATION_DIRECTORY: ~/review-me-app
APPLICATION_DIRECTORY: /home/ubuntu/review-me

jobs:
build:
name: Build Jar file and upload artifact
name: Build Dockerfile and push to DockerHub
runs-on: ubuntu-latest

steps:
Expand All @@ -39,15 +39,22 @@ jobs:
cd ./backend
./gradlew clean bootJar
- name: Rename artifact file
run: |
mv ${{ env.ARTIFACT_DIRECTORY }}/*.jar ${{ env.ARTIFACT_DIRECTORY }}/${{ env.ARTIFACT_NAME }}.jar
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_ID }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Upload created artifact
uses: actions/upload-artifact@v4
- name: Build and push
uses: docker/build-push-action@v6
with:
name: ${{ env.ARTIFACT_NAME }}
path: ${{ env.ARTIFACT_DIRECTORY }}/${{ env.ARTIFACT_NAME }}.jar
context: ./backend
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ secrets.DOCKERHUB_ID }}/review-me-app:develop

deploy:
name: Deploy via self-hosted runner
Expand All @@ -61,38 +68,20 @@ jobs:
repository: ${{ secrets.PRIVATE_REPOSITORY_URL }}
token: ${{ secrets.PRIVATE_REPOSITORY_TOKEN }}

- name: Download uploaded artifact
uses: actions/download-artifact@v4
with:
name: ${{ env.ARTIFACT_NAME }}

- name: Copy application related files to other directory
- name: Move application-related files to local
run: |
sudo mv * ${{ env.APPLICATION_DIRECTORY }}
mkdir -p ${{ env.APPLICATION_DIRECTORY }}/app
mv ./app/* ./app/.* ${{ env.APPLICATION_DIRECTORY }}/app
- name: Find ${{ env.ARTIFACT_NAME }} process
run: |
echo "Checking processes..."
PID=$(pgrep -f ${{ env.ARTIFACT_NAME }}.jar -d " " || true)
if [ -n "$PID" ]; then
echo "Found processes: $PID"
echo "server_running=true" >> "$GITHUB_ENV"
echo "PID=$PID" >> "$GITHUB_ENV"
else
echo "Process not found!"
echo "server_running=false" >> "$GITHUB_ENV"
fi
- name: Stop server if available (gracefully)
if: env.server_running == 'true'
run: |
echo "Gracefully shutting down process ${{ env.PID }}"
for PID in ${{ env.PID }}; do
sudo kill -15 $PID | true
tail --pid=$PID -f /dev/null | true
done
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_ID }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Start server
- name: Pull from DockerHub
run: |
cd ${{ env.APPLICATION_DIRECTORY }}
sudo nohup java -jar ${{ env.ARTIFACT_NAME }}.jar --server.port=8080 --spring.config.location=application-dev.yml &
sudo docker-compose --env-file .env.dev down || true
sudo docker pull ${{ secrets.DOCKERHUB_ID }}/review-me-app:develop
sudo docker-compose --env-file .env.dev up -d
working-directory: ${{ env.APPLICATION_DIRECTORY }}/app
74 changes: 33 additions & 41 deletions .github/workflows/backend-prod-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ on:
env:
ARTIFACT_NAME: review-me-prod
ARTIFACT_DIRECTORY: ./backend/build/libs
APPLICATION_DIRECTORY: ~/review-me-app
APPLICATION_DIRECTORY: /home/ubuntu/review-me

jobs:
build:
name: Build Jar file and upload artifact
name: Build Dockerfile and push to DockerHub
runs-on: ubuntu-latest

steps:
Expand All @@ -39,20 +39,30 @@ jobs:
cd ./backend
./gradlew clean bootJar
- name: Rename artifact file
run: |
mv ${{ env.ARTIFACT_DIRECTORY }}/*.jar ${{ env.ARTIFACT_DIRECTORY }}/${{ env.ARTIFACT_NAME }}.jar
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_ID }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Upload created artifact
uses: actions/upload-artifact@v4
- name: Build and push
uses: docker/build-push-action@v6
with:
name: ${{ env.ARTIFACT_NAME }}
path: ${{ env.ARTIFACT_DIRECTORY }}/${{ env.ARTIFACT_NAME }}.jar
context: ./backend
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ secrets.DOCKERHUB_ID }}/review-me-app:release

deploy:
name: Deploy via self-hosted runner
needs: build
runs-on: [self-hosted, prod]
strategy:
matrix:
runner: [prod-a, prod-b]
runs-on: [ self-hosted, "${{ matrix.runner }}" ]

steps:
- name: Checkout to secret repository
Expand All @@ -61,38 +71,20 @@ jobs:
repository: ${{ secrets.PRIVATE_REPOSITORY_URL }}
token: ${{ secrets.PRIVATE_REPOSITORY_TOKEN }}

- name: Download uploaded artifact
uses: actions/download-artifact@v4
with:
name: ${{ env.ARTIFACT_NAME }}

- name: Copy application related files to other directory
- name: Move application-related files to local
run: |
sudo mv * ${{ env.APPLICATION_DIRECTORY }}
mkdir -p ${{ env.APPLICATION_DIRECTORY }}/app
mv ./app/* ./app/.* ${{ env.APPLICATION_DIRECTORY }}/app
- name: Find ${{ env.ARTIFACT_NAME }} process
run: |
echo "Checking processes..."
PID=$(pgrep -f ${{ env.ARTIFACT_NAME }}.jar -d " " || true)
if [ -n "$PID" ]; then
echo "Found processes: $PID"
echo "server_running=true" >> "$GITHUB_ENV"
echo "PID=$PID" >> "$GITHUB_ENV"
else
echo "Process not found!"
echo "server_running=false" >> "$GITHUB_ENV"
fi
- name: Stop server if available (gracefully)
if: env.server_running == 'true'
run: |
echo "Gracefully shutting down process ${{ env.PID }}"
for PID in ${{ env.PID }}; do
sudo kill -15 $PID | true
tail --pid=$PID -f /dev/null | true
done
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_ID }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Start server
- name: Pull from DockerHub
run: |
cd ${{ env.APPLICATION_DIRECTORY }}
sudo nohup java -jar ${{ env.ARTIFACT_NAME }}.jar --server.port=8080 --spring.config.location=application-prod.yml &
sudo docker-compose --env-file .env.prod down || true
sudo docker pull ${{ secrets.DOCKERHUB_ID }}/review-me-app:release
sudo docker-compose --env-file .env.prod up -d
working-directory: ${{ env.APPLICATION_DIRECTORY }}/app
6 changes: 6 additions & 0 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM amazoncorretto:17-alpine-jdk

ARG JAR_FILE=./build/libs/backend-0.0.1-SNAPSHOT.jar
COPY ${JAR_FILE} review-me-app.jar

ENTRYPOINT ["java", "-jar", "/review-me-app.jar", "-Dspring.config.location=/application.yml"]
2 changes: 2 additions & 0 deletions backend/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ dependencies {
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.5.0'
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'io.micrometer:micrometer-registry-prometheus'
implementation 'org.flywaydb:flyway-core'
implementation 'org.flywaydb:flyway-mysql'

runtimeOnly 'com.h2database:h2'
runtimeOnly 'com.mysql:mysql-connector-j'
Expand Down
4 changes: 2 additions & 2 deletions backend/src/docs/asciidoc/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ include::create-review.adoc[]

=== 리뷰 단건 조회

include::review-list.adoc[]
include::review-detail.adoc[]

=== 리뷰 목록 조회

include::review-detail.adoc[]
include::review-list.adoc[]
6 changes: 1 addition & 5 deletions backend/src/docs/asciidoc/review-detail.adoc
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
==== 리뷰 단건 조회

operation::review-detail[snippets="curl-request,request-headers,path-parameters,http-response,response-fields"]

==== 접근 코드가 올바르지 않은 경우

operation::review-detail-invalid-group-access-code[snippets="http-response"]
operation::review-detail-with-session[snippets="curl-request,request-cookies,path-parameters,http-response,response-fields"]
6 changes: 1 addition & 5 deletions backend/src/docs/asciidoc/review-list.adoc
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
==== 자신이 받은 리뷰 목록 조회

operation::received-reviews[snippets="curl-request,request-headers,http-response,response-fields"]

==== 접근 코드가 올바르지 않은 경우

operation::received-reviews-invalid-group-access-code[snippets="http-response"]
operation::received-review-list-with-pagination[snippets="curl-request,request-cookies,query-parameters,http-response,response-fields"]
4 changes: 2 additions & 2 deletions backend/src/docs/asciidoc/reviewgroup.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ operation::review-group-create[snippets="curl-request,request-fields,http-respon

==== 리뷰 그룹 간단 정보 조회

operation::review-group-summary[snippets="curl-request,request-headers,http-response,response-fields"]
operation::review-group-summary[snippets="curl-request,http-response,response-fields"]

==== 리뷰 요청 코드, 확인 코드 일치 여부

operation::review-group-check-access[snippets="curl-request,request-fields,http-response,response-fields"]
operation::review-group-check-access[snippets="curl-request,request-fields,http-response,response-cookies"]
Loading

0 comments on commit 00c11b9

Please sign in to comment.