diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6f94d5a7..17e57edd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,10 +21,6 @@ jobs: java-version: '17' distribution: 'corretto' - - name: environment 세팅 - run: | - cp src/main/resources/config/dev.env ./.env - - name: Gradle 캐싱 uses: actions/cache@v3 with: diff --git a/.github/workflows/develop-cd.yml b/.github/workflows/develop-cd.yml index bca6e32e..987b4b6a 100644 --- a/.github/workflows/develop-cd.yml +++ b/.github/workflows/develop-cd.yml @@ -30,41 +30,41 @@ jobs: - name: Github Actions IP 보안그룹 추가 run: | - aws ec2 authorize-security-group-ingress --group-id ${{ secrets.AWS_SG_ID }} --protocol tcp --port 22 --cidr ${{ steps.ip.outputs.ipv4 }}/32 + aws ec2 authorize-security-group-ingress --group-id ${{ secrets.AWS_DEV_SG_ID }} --protocol tcp --port 22 --cidr ${{ steps.ip.outputs.ipv4 }}/32 - name: 디렉토리 생성 uses: appleboy/ssh-action@master with: - host: ${{ secrets.EC2_INSTANCE_HOST }} + host: ${{ secrets.EC2_DEV_INSTANCE_HOST }} port: 22 - username: ubuntu - key: ${{ secrets.EC2_INSTANCE_PRIVATE_KEY }} + username: ${{ secrets.EC2_DEV_INSTANCE_USERNAME }} + key: ${{ secrets.EC2_DEV_INSTANCE_PRIVATE_KEY }} script: | mkdir -p /home/ubuntu/moabam/ - name: Docker env 파일 생성 run: - cp src/main/resources/config/dev.env ./.env + cp src/main/resources/config/dev.env ./infra/.env - name: 서버로 전송 기본 파일들 전송 uses: appleboy/scp-action@master with: - host: ${{ secrets.EC2_INSTANCE_HOST }} + host: ${{ secrets.EC2_DEV_INSTANCE_HOST }} port: 22 - username: ${{ secrets.EC2_INSTANCE_USERNAME }} - key: ${{ secrets.EC2_INSTANCE_PRIVATE_KEY }} - source: "./.env, ./docker-compose-dev.yml, ./scripts/*, ./nginx/*, ./mysql/*" + username: ${{ secrets.EC2_DEV_INSTANCE_USERNAME }} + key: ${{ secrets.EC2_DEV_INSTANCE_PRIVATE_KEY }} + source: "./infra/*" target: "/home/ubuntu/moabam" - name: 파일 세팅 uses: appleboy/ssh-action@master with: - host: ${{ secrets.EC2_INSTANCE_HOST }} + host: ${{ secrets.EC2_DEV_INSTANCE_HOST }} port: 22 - username: ubuntu - key: ${{ secrets.EC2_INSTANCE_PRIVATE_KEY }} + username: ${{ secrets.EC2_DEV_INSTANCE_USERNAME }} + key: ${{ secrets.EC2_DEV_INSTANCE_PRIVATE_KEY }} script: | - cd /home/ubuntu/moabam + cd /home/ubuntu/moabam/infra mv docker-compose-dev.yml docker-compose.yml chmod +x ./scripts/deploy-dev.sh chmod +x ./scripts/init-letsencrypt.sh @@ -75,7 +75,7 @@ jobs: - name: Github Actions IP 보안그룹에서 삭제 if: always() run: | - aws ec2 revoke-security-group-ingress --group-id ${{ secrets.AWS_SG_ID }} --protocol tcp --port 22 --cidr ${{ steps.ip.outputs.ipv4 }}/32 + aws ec2 revoke-security-group-ingress --group-id ${{ secrets.AWS_DEV_SG_ID }} --protocol tcp --port 22 --cidr ${{ steps.ip.outputs.ipv4 }}/32 deploy: name: deploy @@ -148,18 +148,18 @@ jobs: - name: Github Actions IP 보안그룹 추가 run: | - aws ec2 authorize-security-group-ingress --group-id ${{ secrets.AWS_SG_ID }} --protocol tcp --port 22 --cidr ${{ steps.ip.outputs.ipv4 }}/32 + aws ec2 authorize-security-group-ingress --group-id ${{ secrets.AWS_DEV_SG_ID }} --protocol tcp --port 22 --cidr ${{ steps.ip.outputs.ipv4 }}/32 - name: EC2 서버에 배포 uses: appleboy/ssh-action@master id: deploy-dev if: contains(github.ref, 'dev') with: - host: ${{ secrets.EC2_INSTANCE_HOST }} + host: ${{ secrets.EC2_DEV_INSTANCE_HOST }} port: 22 - username: ubuntu - key: ${{ secrets.EC2_INSTANCE_PRIVATE_KEY }} - source: "docker-compose-dev.yml" + username: ${{ secrets.EC2_DEV_INSTANCE_USERNAME }} + key: ${{ secrets.EC2_DEV_INSTANCE_PRIVATE_KEY }} + source: "./infra/docker-compose-dev.yml" script: | cd /home/ubuntu/moabam echo ${{ secrets.DOCKER_HUB_TOKEN }} | docker login -u ${{ secrets.DOCKER_HUB_USERNAME }} --password-stdin @@ -171,4 +171,4 @@ jobs: - name: Github Actions IP 보안그룹에서 삭제 if: always() run: | - aws ec2 revoke-security-group-ingress --group-id ${{ secrets.AWS_SG_ID }} --protocol tcp --port 22 --cidr ${{ steps.ip.outputs.ipv4 }}/32 + aws ec2 revoke-security-group-ingress --group-id ${{ secrets.AWS_DEV_SG_ID }} --protocol tcp --port 22 --cidr ${{ steps.ip.outputs.ipv4 }}/32 diff --git a/Dockerfile b/infra/Dockerfile similarity index 78% rename from Dockerfile rename to infra/Dockerfile index c7fb704b..8fb6a8a5 100644 --- a/Dockerfile +++ b/infra/Dockerfile @@ -3,6 +3,6 @@ FROM amazoncorretto:17 ARG SPRING_ACTIVE_PROFILES ENV SPRING_ACTIVE_PROFILES ${SPRING_ACTIVE_PROFILES} -COPY build/libs/moabam-server-0.0.1-SNAPSHOT.jar moabam.jar +COPY ../build/libs/moabam-server-0.0.1-SNAPSHOT.jar moabam.jar ENTRYPOINT ["java", "-jar", "-Duser.timezone=Asia/Seoul", "-Dspring.profiles.active=${SPRING_ACTIVE_PROFILES}", "/moabam.jar"] diff --git a/docker-compose-dev.yml b/infra/docker-compose-dev.yml similarity index 75% rename from docker-compose-dev.yml rename to infra/docker-compose-dev.yml index 5d953072..35acfe2e 100644 --- a/docker-compose-dev.yml +++ b/infra/docker-compose-dev.yml @@ -10,18 +10,18 @@ services: - "80:80" - "443:443" volumes: - - /home/ubuntu/moabam/nginx/nginx.conf:/etc/nginx/nginx.conf - - /home/ubuntu/moabam/nginx/conf.d:/etc/nginx/conf.d - - /home/ubuntu/moabam/nginx/certbot/conf:/etc/letsencrypt - - /home/ubuntu/moabam/nginx/certbot/www:/var/www/certbot + - ./nginx/nginx.conf:/etc/nginx/nginx.conf + - ./nginx/conf.d:/etc/nginx/conf.d + - ./nginx/certbot/conf:/etc/letsencrypt + - ./nginx/certbot/www:/var/www/certbot certbot: image: certbot/certbot:latest container_name: certbot platform: linux/arm64 restart: unless-stopped volumes: - - /home/ubuntu/moabam/nginx/certbot/conf:/etc/letsencrypt - - /home/ubuntu/moabam/nginx/certbot/www:/var/www/certbot + - ./nginx/certbot/conf:/etc/letsencrypt + - ./nginx/certbot/www:/var/www/certbot entrypoint: "/bin/sh -c 'trap exit TERM; while :; do certbot renew; sleep 12h & wait $${!}; done;'" moabam-blue: image: ${DOCKER_HUB_USERNAME}/${DOCKER_HUB_REPOSITORY}:${DOCKER_HUB_TAG} @@ -54,7 +54,7 @@ services: ports: - "6379:6379" volumes: - - /home/ubuntu/moabam/data/redis:/data + - ./data/redis:/data mysql: image: mysql:8.0.33 container_name: mysql @@ -72,5 +72,5 @@ services: - --collation-server=utf8mb4_unicode_ci - --skip-character-set-client-handshake volumes: - - /home/ubuntu/moabam/data/mysql:/var/lib/mysql - - /home/ubuntu/moabam/mysql/initdb.d:/docker-entrypoint-initdb.d + - ./data/mysql:/var/lib/mysql + - ./mysql/initdb.d:/docker-entrypoint-initdb.d diff --git a/mysql/initdb.d/init.sql b/infra/mysql/initdb.d/init.sql similarity index 100% rename from mysql/initdb.d/init.sql rename to infra/mysql/initdb.d/init.sql diff --git a/mysql/initdb.d/item-data.sql b/infra/mysql/initdb.d/item-data.sql similarity index 88% rename from mysql/initdb.d/item-data.sql rename to infra/mysql/initdb.d/item-data.sql index 28561b81..7243750c 100644 --- a/mysql/initdb.d/item-data.sql +++ b/infra/mysql/initdb.d/item-data.sql @@ -16,33 +16,33 @@ values ('NIGHT', 'SKIN', '부엉이', 'https://image.moabam.com/moabam/skins/owl insert into item (type, category, name, awake_image, sleep_image, bug_price, golden_bug_price, unlock_level, created_at) values ('MORNING', 'SKIN', '안경 오목눈이', 'https://image.moabam.com/moabam/skins/omok/glasses/eyes-opened.png', - 'https://image.moabam.com/moabam/skins/omok/glasses/eyes-closed', 10, 5, 5, current_time()); + 'https://image.moabam.com/moabam/skins/omok/glasses/eyes-closed.png', 10, 5, 5, current_time()); insert into item (type, category, name, awake_image, sleep_image, bug_price, golden_bug_price, unlock_level, created_at) values ('NIGHT', 'SKIN', '안경 부엉이', 'https://image.moabam.com/moabam/skins/owl/glasses/eyes-opened.png', - 'https://image.moabam.com/moabam/skins/owl/glasses/eyes-closed', 10, 5, 5, current_time()); + 'https://image.moabam.com/moabam/skins/owl/glasses/eyes-closed.png', 10, 5, 5, current_time()); insert into item (type, category, name, awake_image, sleep_image, bug_price, golden_bug_price, unlock_level, created_at) values ('MORNING', 'SKIN', '목도리 오목눈이', 'https://image.moabam.com/moabam/skins/omok/scarf/eyes-opened.png', - 'https://image.moabam.com/moabam/skins/omok/scarf/eyes-closed', 20, 10, 10, current_time()); + 'https://image.moabam.com/moabam/skins/omok/scarf/eyes-closed.png', 20, 10, 10, current_time()); insert into item (type, category, name, awake_image, sleep_image, bug_price, golden_bug_price, unlock_level, created_at) values ('NIGHT', 'SKIN', '목도리 부엉이', 'https://image.moabam.com/moabam/skins/owl/scarf/eyes-opened.png', - 'https://image.moabam.com/moabam/skins/owl/scarf/eyes-closed', 20, 10, 10, current_time()); + 'https://image.moabam.com/moabam/skins/owl/scarf/eyes-closed.png', 20, 10, 10, current_time()); insert into item (type, category, name, awake_image, sleep_image, bug_price, golden_bug_price, unlock_level, created_at) values ('MORNING', 'SKIN', '산타 오목눈이', 'https://image.moabam.com/moabam/skins/omok/santa/eyes-opened.png', - 'https://image.moabam.com/moabam/skins/omok/santa/eyes-closed', 30, 15, 15, current_time()); + 'https://image.moabam.com/moabam/skins/omok/santa/eyes-closed.png', 30, 15, 15, current_time()); insert into item (type, category, name, awake_image, sleep_image, bug_price, golden_bug_price, unlock_level, created_at) values ('NIGHT', 'SKIN', '산타 부엉이', 'https://image.moabam.com/moabam/skins/owl/santa/eyes-opened.png', - 'https://image.moabam.com/moabam/skins/owl/santa/eyes-closed', 30, 15, 15, current_time()); + 'https://image.moabam.com/moabam/skins/owl/santa/eyes-closed.png', 30, 15, 15, current_time()); insert into product (id, type, name, price, quantity, created_at, updated_at) -values (null, 'BUG', '황금벌레x5', 3300, 5, current_time(), null); +values (null, 'BUG', '황금벌레x5', 3000, 5, current_time(), null); insert into product (id, type, name, price, quantity, created_at, updated_at) -values (null, 'BUG', '황금벌레x10', 6600, 10, current_time(), null); +values (null, 'BUG', '황금벌레x10', 7000, 10, current_time(), null); insert into product (id, type, name, price, quantity, created_at, updated_at) -values (null, 'BUG', '황금벌레x15', 9900, 15, current_time(), null); +values (null, 'BUG', '황금벌레x25', 9900, 25, current_time(), null); diff --git a/nginx/conf.d/header.conf b/infra/nginx/conf.d/header.conf similarity index 100% rename from nginx/conf.d/header.conf rename to infra/nginx/conf.d/header.conf diff --git a/nginx/mime.types b/infra/nginx/mime.types similarity index 100% rename from nginx/mime.types rename to infra/nginx/mime.types diff --git a/nginx/nginx.conf b/infra/nginx/nginx.conf similarity index 100% rename from nginx/nginx.conf rename to infra/nginx/nginx.conf diff --git a/nginx/templates/http-server.template b/infra/nginx/templates/http-server.template similarity index 100% rename from nginx/templates/http-server.template rename to infra/nginx/templates/http-server.template diff --git a/nginx/templates/ssl-server.template b/infra/nginx/templates/ssl-server.template similarity index 100% rename from nginx/templates/ssl-server.template rename to infra/nginx/templates/ssl-server.template diff --git a/nginx/templates/upstream.template b/infra/nginx/templates/upstream.template similarity index 100% rename from nginx/templates/upstream.template rename to infra/nginx/templates/upstream.template diff --git a/scripts/deploy-dev.sh b/infra/scripts/deploy-dev.sh similarity index 100% rename from scripts/deploy-dev.sh rename to infra/scripts/deploy-dev.sh diff --git a/scripts/init-letsencrypt.sh b/infra/scripts/init-letsencrypt.sh similarity index 100% rename from scripts/init-letsencrypt.sh rename to infra/scripts/init-letsencrypt.sh diff --git a/scripts/init-nginx-converter.sh b/infra/scripts/init-nginx-converter.sh similarity index 100% rename from scripts/init-nginx-converter.sh rename to infra/scripts/init-nginx-converter.sh