-
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.
Merge pull request #405 from boostcampwm2023/server/feature/404
Spring 환경설정
- Loading branch information
Showing
86 changed files
with
717 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
name: Server Spring CD | ||
|
||
on: | ||
pull_request: | ||
branches: ["develop", "main"] | ||
paths: | ||
- "server/spring/**" | ||
types: | ||
- closed | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up JDK 17 | ||
uses: actions/setup-java@v4 | ||
with: | ||
java-version: "17" | ||
distribution: "adopt" | ||
|
||
- name: Run chmod to make gradlew executable | ||
run: | | ||
cd server/spring | ||
chmod +x ./gradlew | ||
|
||
- name: Build with Gradle | ||
run: | | ||
cd server/spring | ||
./gradlew clean build | ||
|
||
- name: Create application.yml | ||
env: | ||
DB_HOST_IP: ${{ secrets.SERVER_ENV_DB_HOST_IP }} | ||
DB_PORT: ${{ secrets.SERVER_ENV_DB_PORT }} | ||
DB_USER_NAME: ${{ secrets.SERVER_ENV_DB_USER_NAME }} | ||
DB_PASSWORD: ${{ secrets.SERVER_ENV_DB_PASSWORD }} | ||
DB_DATABASE_NAME: ${{ secrets.SERVER_ENV_DB_DATABASE_NAME }} | ||
ACCESS_ID: ${{ secrets.SERVER_ENV_ACCESS_ID }} | ||
SECRET_ACCESS_KEY: ${{ secrets.SERVER_ENV_SECRET_ACCESS_KEY }} | ||
JWT_SECRET_KEY: ${{ secrets.SERVER_ENV_JWT_SECRET_KEY }} | ||
GREEN_EYE_SECRET_KEY: ${{secrets.GREEN_EYE_SECRET_KEY}} | ||
GREEN_EYE_REQUEST_URL: ${{secrets.GREEN_EYE_REQUEST_URL}} | ||
CLOUD_FUNCTIONS_EXECUTE_URL: ${{secrets.CLOUD_FUNCTIONS_EXECUTE_URL}} | ||
CLOUD_FUNCTIONS_REQUEST_URL: ${{secrets.CLOUD_FUNCTIONS_REQUEST_URL}} | ||
API_GW_ACCESS_KEY: ${{secrets.API_GW_ACCESS_KEY}} | ||
REFRESH_SECRET_KEY: ${{secrets.REFRESH_SECRET_KEY}} | ||
REDIS_HOST_IP: ${{secrets.REDIS_HOST_IP}} | ||
REDIS_PASSWORD: ${{secrets.REDIS_PASSWORD}} | ||
REDIS_PORT: ${{secrets.REDIS_PORT}} | ||
REDIS_TTL: ${{secrets.REDIS_TTL}} | ||
run: | | ||
cd server | ||
touch ./application.yml | ||
echo "DB_HOST_IP=$DB_HOST_IP" >> application.yml | ||
echo "DB_PORT=$DB_PORT" >> application.yml | ||
echo "DB_USER_NAME=$DB_USER_NAME" >> application.yml | ||
echo "DB_PASSWORD=$DB_PASSWORD" >> application.yml | ||
echo "DB_DATABASE_NAME=$DB_DATABASE_NAME" >> application.yml | ||
echo "ACCESS_ID=$ACCESS_ID" >> application.yml | ||
echo "SECRET_ACCESS_KEY=$SECRET_ACCESS_KEY" >> application.yml | ||
echo "JWT_SECRET_KEY=$JWT_SECRET_KEY" >> application.yml | ||
echo "GREEN_EYE_SECRET_KEY=$GREEN_EYE_SECRET_KEY" >> application.yml | ||
echo "GREEN_EYE_REQUEST_URL=$GREEN_EYE_REQUEST_URL" >> application.yml | ||
echo "CLOUD_FUNCTIONS_EXECUTE_URL=$CLOUD_FUNCTIONS_EXECUTE_URL" >> application.yml | ||
echo "CLOUD_FUNCTIONS_REQUEST_URL=$CLOUD_FUNCTIONS_REQUEST_URL" >> application.yml | ||
echo "API_GW_ACCESS_KEY=$API_GW_ACCESS_KEY" >> application.yml | ||
echo "REFRESH_SECRET_KEY=$REFRESH_SECRET_KEY" >> application.yml | ||
echo "REDIS_HOST_IP=$REDIS_HOST_IP" >> application.yml | ||
echo "REDIS_PASSWORD=$REDIS_PASSWORD" >> application.yml | ||
echo "REDIS_PORT=$REDIS_PORT" >> application.yml | ||
echo "REDIS_TTL=$REDIS_TTL" >> application.yml | ||
- name: Build Docker image | ||
run: docker build --platform linux/amd64 ./server -t ${{ secrets.NCP_SPRING_REGISTRY }}/catchy-tape-sub:latest -f ./server/Dockerfile.spring | ||
|
||
- name: Login NCP container registry | ||
run: docker login ${{ secrets.NCP_SPRING_REGISTRY }} -u ${{ secrets.NCP_DOCKER_ACCESS_KEY_ID }} -p ${{ secrets.NCP_DOCKER_SECRET_KEY }} | ||
|
||
- name: Push Docker image to registry | ||
run: docker push ${{ secrets.NCP_SPRING_REGISTRY }}/catchy-tape-sub:latest | ||
|
||
- name: SSH into Server | ||
uses: appleboy/ssh-action@master | ||
with: | ||
host: ${{ secrets.SERVER_SSH_HOST }} | ||
username: ${{ secrets.SERVER_SSH_USER }} | ||
password: ${{ secrets.SERVER_SSH_PASSWORD }} | ||
port: ${{ secrets.SERVER_SSH_PORT }} | ||
script: | | ||
export NCP_SPRING_REGISTRY=${{ secrets.NCP_SPRING_REGISTRY }} | ||
export NCP_DOCKER_ACCESS_KEY_ID=${{ secrets.NCP_DOCKER_ACCESS_KEY_ID }} | ||
export NCP_DOCKER_SECRET_KEY=${{ secrets.NCP_DOCKER_SECRET_KEY }} | ||
sh server/deploy-spring.sh | ||
curl -X POST -H 'Content-type: application/json' --data '{"text":"스프링 서버 배포 성공!"}' ${{ secrets.SLACK_WEBHOOK_URL }} |
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,72 @@ | ||
name: Backend Spring CI | ||
|
||
on: | ||
pull_request: | ||
branches: [develop] | ||
paths: | ||
- "server/spring/**" | ||
|
||
defaults: | ||
run: | ||
working-directory: ./server/spring | ||
|
||
jobs: | ||
BACKEND-SPRING-CI: | ||
runs-on: ubuntu-20.04 | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up JDK 17 | ||
uses: actions/setup-java@v4 | ||
with: | ||
java-version: 17 | ||
distribution: "adopt" | ||
|
||
- name: Create application.yml | ||
env: | ||
DB_HOST_IP: ${{ secrets.SERVER_ENV_DB_HOST_IP }} | ||
DB_PORT: ${{ secrets.SERVER_ENV_DB_PORT }} | ||
DB_USER_NAME: ${{ secrets.SERVER_ENV_DB_USER_NAME }} | ||
DB_PASSWORD: ${{ secrets.SERVER_ENV_DB_PASSWORD }} | ||
DB_DATABASE_NAME: ${{ secrets.SERVER_ENV_DB_DATABASE_NAME }} | ||
ACCESS_ID: ${{ secrets.SERVER_ENV_ACCESS_ID }} | ||
SECRET_ACCESS_KEY: ${{ secrets.SERVER_ENV_SECRET_ACCESS_KEY }} | ||
JWT_SECRET_KEY: ${{ secrets.SERVER_ENV_JWT_SECRET_KEY }} | ||
GREEN_EYE_SECRET_KEY: ${{secrets.GREEN_EYE_SECRET_KEY}} | ||
GREEN_EYE_REQUEST_URL: ${{secrets.GREEN_EYE_REQUEST_URL}} | ||
CLOUD_FUNCTIONS_EXECUTE_URL: ${{secrets.CLOUD_FUNCTIONS_EXECUTE_URL}} | ||
CLOUD_FUNCTIONS_REQUEST_URL: ${{secrets.CLOUD_FUNCTIONS_REQUEST_URL}} | ||
API_GW_ACCESS_KEY: ${{secrets.API_GW_ACCESS_KEY}} | ||
REFRESH_SECRET_KEY: ${{secrets.REFRESH_SECRET_KEY}} | ||
REDIS_HOST_IP: ${{secrets.REDIS_HOST_IP}} | ||
REDIS_PASSWORD: ${{secrets.REDIS_PASSWORD}} | ||
REDIS_PORT: ${{secrets.REDIS_PORT}} | ||
REDIS_TTL: ${{secrets.REDIS_TTL}} | ||
run: | | ||
touch application.yml | ||
echo "DB_HOST_IP=$DB_HOST_IP" >> application.yml | ||
echo "DB_PORT=$DB_PORT" >> application.yml | ||
echo "DB_USER_NAME=$DB_USER_NAME" >> application.yml | ||
echo "DB_PASSWORD=$DB_PASSWORD" >> application.yml | ||
echo "DB_DATABASE_NAME=$DB_DATABASE_NAME" >> application.yml | ||
echo "ACCESS_ID=$ACCESS_ID" >> application.yml | ||
echo "SECRET_ACCESS_KEY=$SECRET_ACCESS_KEY" >> application.yml | ||
echo "JWT_SECRET_KEY=$JWT_SECRET_KEY" >> application.yml | ||
echo "GREEN_EYE_SECRET_KEY=$GREEN_EYE_SECRET_KEY" >> application.yml | ||
echo "GREEN_EYE_REQUEST_URL=$GREEN_EYE_REQUEST_URL" >> application.yml | ||
echo "CLOUD_FUNCTIONS_EXECUTE_URL=$CLOUD_FUNCTIONS_EXECUTE_URL" >> application.yml | ||
echo "CLOUD_FUNCTIONS_REQUEST_URL=$CLOUD_FUNCTIONS_REQUEST_URL" >> application.yml | ||
echo "API_GW_ACCESS_KEY=$API_GW_ACCESS_KEY" >> application.yml | ||
echo "REFRESH_SECRET_KEY=$REFRESH_SECRET_KEY" >> application.yml | ||
echo "REDIS_HOST_IP=$REDIS_HOST_IP" >> application.yml | ||
echo "REDIS_PASSWORD=$REDIS_PASSWORD" >> application.yml | ||
echo "REDIS_PORT=$REDIS_PORT" >> application.yml | ||
echo "REDIS_TTL=$REDIS_TTL" >> application.yml | ||
- name: Grant execute permission for gradlew | ||
run: chmod +x gradlew | ||
|
||
- name: Test with Gradle | ||
run: ./gradlew --info test |
6 changes: 3 additions & 3 deletions
6
.github/workflows/server-dev-ci.yml → .github/workflows/server-ci.yml
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
.git | ||
Dockerfile | ||
node_modules | ||
dist | ||
Dockerfile.nest | ||
Dockerfile.spring | ||
nest/node_modules | ||
nest/dist |
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 |
---|---|---|
|
@@ -4,7 +4,7 @@ ENV TZ=Asia/Seoul | |
|
||
WORKDIR /catchy-tape | ||
|
||
COPY . . | ||
COPY nest . | ||
|
||
RUN npm install | ||
RUN npm run build | ||
|
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,17 @@ | ||
FROM openjdk:17-alpine | ||
|
||
ENV TZ=Asia/Seoul | ||
|
||
WORKDIR /catchy-tape-spring | ||
|
||
# 인자 설정 - JAR_File | ||
ARG JAR_FILE=spring/build/libs/*.jar | ||
|
||
# jar 파일 복제 | ||
COPY ${JAR_FILE} app.jar | ||
|
||
# 해당 포트를 외부로 개방 | ||
EXPOSE 8080 | ||
|
||
# 실행 명령어 | ||
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,48 @@ | ||
#!/bin/sh | ||
|
||
|
||
# blue 컨테이너가 띄워져 있는지 확인 (8080 포트 == blue) | ||
EXIST_BLUE=$(netstat -lntp | grep 8080) | ||
|
||
if [ -n "$EXIST_BLUE" ]; then | ||
TARGET_COLOR="green" | ||
NOW_COLOR="blue" | ||
WEB_SERVER_TARGET_PORT=8081 | ||
WEB_SERVER_STOP_PORT=8080 | ||
TARGET_SERVER_NAME="catchy-tape-sub-green" | ||
NOW_SERVER_NAME="catchy-tape-sub-blue" | ||
else | ||
TARGET_COLOR="blue" | ||
NOW_COLOR="green" | ||
WEB_SERVER_TARGET_PORT=8080 | ||
WEB_SERVER_STOP_PORT=8081 | ||
TARGET_SERVER_NAME="catchy-tape-sub-blue" | ||
NOW_SERVER_NAME="catchy-tape-sub-green" | ||
fi | ||
|
||
# 1 새로운 서버를 띄운다 | ||
docker login $NCP_SPRING_REGISTRY -u $NCP_DOCKER_ACCESS_KEY_ID -p $NCP_DOCKER_SECRET_KEY | ||
docker pull $NCP_SPRING_REGISTRY/catchy-tape-sub:latest | ||
docker run -v /home/hyung/logs:/catchy-tape-sub/logs -d -p $WEB_SERVER_TARGET_PORT:8080 --name $TARGET_SERVER_NAME $NCP_SPRING_REGISTRY/catchy-tape-sub:latest | ||
|
||
# 2 nginx 포트 설정 변경 후 reload | ||
NGINX_CONFIG="/etc/nginx/nginx.conf" | ||
sed -i "s/$WEB_SERVER_STOP_PORT/$WEB_SERVER_TARGET_PORT/" $NGINX_CONFIG | ||
nginx -s reload | ||
|
||
# 3 원래 서버 종료 & 삭제 | ||
FIRST_DEPLOYED_SERVER="catchy-tape-sub" | ||
FIRST_DEPLOYED_SERVER_ID=$(docker ps --filter "name=$FIRST_DEPLOYED_SERVER" -q) | ||
if [ -n "$FIRST_DEPLOYED_SERVER_ID" ]; then | ||
docker stop $FIRST_DEPLOYED_SERVER | ||
docker rm $FIRST_DEPLOYED_SERVER | ||
fi | ||
|
||
STOP_SERVER_ID=$(docker ps --filter "name=$NOW_SERVER_NAME" -q) | ||
if [ -n "$STOP_SERVER_ID" ]; then | ||
docker stop $STOP_SERVER_ID | ||
docker rm $NOW_SERVER_NAME | ||
fi | ||
|
||
# 사용하지 않는 도커 이미지 정리 | ||
docker image prune -a -f |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
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 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"exclude": ["node_modules", "test", "dist", "**/*spec.ts"] | ||
} |
File renamed without changes.
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,37 @@ | ||
HELP.md | ||
.gradle | ||
build/ | ||
!gradle/wrapper/gradle-wrapper.jar | ||
!**/src/main/**/build/ | ||
!**/src/test/**/build/ | ||
|
||
### STS ### | ||
.apt_generated | ||
.classpath | ||
.factorypath | ||
.project | ||
.settings | ||
.springBeans | ||
.sts4-cache | ||
bin/ | ||
!**/src/main/**/bin/ | ||
!**/src/test/**/bin/ | ||
|
||
### IntelliJ IDEA ### | ||
.idea | ||
*.iws | ||
*.iml | ||
*.ipr | ||
out/ | ||
!**/src/main/**/out/ | ||
!**/src/test/**/out/ | ||
|
||
### NetBeans ### | ||
/nbproject/private/ | ||
/nbbuild/ | ||
/dist/ | ||
/nbdist/ | ||
/.nb-gradle/ | ||
|
||
### VS Code ### | ||
.vscode/ |
Oops, something went wrong.