Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BE-INFRA] 개발 서버 배포 #30

Merged
merged 32 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
9eac54a
chore: db 서버 url 설정
jongmee Jul 15, 2024
251dad6
build: dev용 h2 db 설정
jongmee Jul 15, 2024
edcc26b
chore: dev 서버 db를 mysql로 변경
jongmee Jul 16, 2024
8b7f44a
chore: local mysql 설정 파일 추가
jongmee Jul 16, 2024
f15c2bf
ci: ci script 작성
jongmee Jul 17, 2024
89acd8a
ci: ci script에 working-directory 설정
jongmee Jul 17, 2024
1ed7ff7
chore: Nginx 설정 파일 작성
jongmee Jul 17, 2024
c4c1d0f
chore: 서버 & nginx Dockerfile 작성
jongmee Jul 17, 2024
d275960
chore: 배포 스크립트 작성
jongmee Jul 17, 2024
3ab1649
chore: 개발 서버 mysql 설정 추가
jongmee Jul 17, 2024
4d03232
chore: 스크립트에서 jar 파일 위치 변경
jongmee Jul 17, 2024
1e01719
chore: jar 파일 경로 절대 경로로 수정
jongmee Jul 17, 2024
0e25e6d
chore: 빌드 컨텍스트에 맞게 dockerfile 경로 수정
jongmee Jul 17, 2024
a28260c
chore: nginx 도커 빌드 컨텍스트 수정
jongmee Jul 17, 2024
86c225f
chore: self hosted runner 도입
jongmee Jul 18, 2024
ef6e1f3
chore: mysql 서버 ip 변경
jongmee Jul 18, 2024
4492c73
chore: appleboy 버전 변경
jongmee Jul 18, 2024
805ab4c
chore: 배포 스크립트에서 host 제거
jongmee Jul 18, 2024
6033dee
chore: 배포 스크립트에서 appleboy 제거
jongmee Jul 18, 2024
5ee563d
chore: 배포 스크립트 도커 커맨드 변경
jongmee Jul 18, 2024
823c4cc
chore: 하위 도메인 설정 제거
jongmee Jul 18, 2024
39f0302
chore: ipv6 제외
jongmee Jul 18, 2024
1f9fb52
chore: localhost ip 주소 명시
jongmee Jul 18, 2024
9882b1f
chore: proxy_pass 주소 변경
jongmee Jul 18, 2024
26f0043
chore: dev db용 ddl-auto 설정 변경
jongmee Jul 19, 2024
51ea3b2
chore: ci, cd 스크립트 분리
jongmee Jul 19, 2024
cc3c227
chore: ci 테스트시 h2 사용
jongmee Jul 19, 2024
e457321
chore: cd 스크립트 트리거 임시 변경
jongmee Jul 19, 2024
1838038
chore: cd 스크립트 job 순서 고정
jongmee Jul 19, 2024
7263a77
chore: 멀티 플랫폼 지정하여 도커 이미지 빌드
jongmee Jul 19, 2024
f9aa387
chore: 플랫폼을 linux/arm64(단일)로 지정하여 도커 이미지 빌드
jongmee Jul 19, 2024
e5620f0
chore: 빌드 환경을 self hosted runner로 변경
jongmee Jul 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions .github/workflows/Backend-CD.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: Backend CD

on:
pull_request:
branches: [ "be/develop" ]
push:
branches: [ "be/develop" ]

permissions:
contents: read

jobs:
build:
runs-on: self-hosted
steps:

- name: Checkout
uses: actions/checkout@v3
with:
token: ${{ secrets.ACTION_TOKEN }}
submodules: true

- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'

- name: Build with Gradle
run: ./gradlew bootJar
working-directory: ./backend/pokerogue

- name: Docker build and push
run: |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}

docker build -t ${{ secrets.DOCKER_SERVER_IMAGE }} -f ./backend/pokerogue/docker/Dockerfile ./backend/pokerogue
docker push ${{ secrets.DOCKER_SERVER_IMAGE }}

docker build -t ${{ secrets.DOCKER_NGINX_IMAGE }} -f ./backend/pokerogue/docker/Dockerfile-nginx ./backend/pokerogue/docker
docker push ${{ secrets.DOCKER_NGINX_IMAGE }}

deploy:
needs: build
runs-on: self-hosted
steps:

- name: Change permission
run: |
sudo chown -R ubuntu:ubuntu /home/ubuntu/actions-runner/_work/2024-pokerogue-helper

- name: Deploy
run: |
cd /home/ubuntu

sudo touch docker-compose.yml
echo "${{ vars.DOCKER_COMPOSE }}" | sudo tee docker-compose.yml > /dev/null

sudo chmod 666 /var/run/docker.sock

if [ "$(docker ps -qa)" ]; then
sudo docker rm -f $(docker ps -qa)
else
echo "No containers to remove."
fi

sudo docker pull ${{ secrets.DOCKER_SERVER_IMAGE }}
sudo docker pull ${{ secrets.DOCKER_NGINX_IMAGE }}

docker-compose -f docker-compose.yml up -d
docker image prune -f
31 changes: 31 additions & 0 deletions .github/workflows/Backend-CI.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Backend CI

on:
pull_request:
branches: [ "be/develop" ]
push:
branches: [ "be/develop" ]

permissions:
contents: read

jobs:
build:
runs-on: ubuntu-latest
steps:

- name: Checkout
uses: actions/checkout@v3
with:
token: ${{ secrets.ACTION_TOKEN }}
submodules: true

- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'

- name: Run Test
run: SPRING_PROFILES_ACTIVE=h2 ./gradlew clean test
working-directory: ./backend/pokerogue
3 changes: 3 additions & 0 deletions backend/pokerogue/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ dependencies {
// mySql
runtimeOnly 'com.mysql:mysql-connector-j'

// H2
runtimeOnly 'com.h2database:h2'

// JPA
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'

Expand Down
4 changes: 4 additions & 0 deletions backend/pokerogue/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM openjdk:17
ARG JAR_FILE=/build/libs/*.jar
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java","-jar", "/app.jar"]
4 changes: 4 additions & 0 deletions backend/pokerogue/docker/Dockerfile-nginx
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM nginx
RUN rm -rf /etc/nginx/conf.d/default.conf
COPY ./nginx/conf.d/nginx.conf /etc/nginx/conf.d
CMD ["nginx", "-g", "daemon off;"]
44 changes: 44 additions & 0 deletions backend/pokerogue/docker/nginx/conf.d/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
server {
listen [::]:80 default_server;
root /var/www/html;
server_name _;

location / {
resolver 8.8.8.8 ipv6=off;
proxy_pass http://server:8080;
proxy_set_header X-Real_IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
}
}

server {
root /var/www/html;
server_name pokerogue-helper.com;

location / {
resolver 8.8.8.8 ipv6=off;
proxy_pass http://server:8080;
proxy_set_header X-Real_IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
}

listen [::]:443 ssl ipv6only=on;
listen 443 ssl;
ssl_certificate /etc/letsencrypt/live/pokerogue-helper.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/pokerogue-helper.com/privkey.pem;
include /etc/letsencrypt/options-ssl-nginx.conf;
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
}

server {
if ($host = pokerogue-helper.com) {
return 301 https://$host$request_uri;
}

listen 80 ;
listen [::]:80 ;
server_name pokerogue-helper.com;
return 404;
}
2 changes: 1 addition & 1 deletion backend/pokerogue/src/main/resources
Loading