-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[merge]: 7~8주차 진행사항 develop에 머지 (#77)
- Loading branch information
Showing
51 changed files
with
1,874 additions
and
74 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,81 @@ | ||
name: CD (자동배포) | ||
|
||
on: | ||
push: | ||
branches: | ||
- develop | ||
jobs: | ||
deploy: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up Java 21 | ||
uses: actions/setup-java@v3 | ||
with: | ||
distribution: 'temurin' | ||
java-version: '21' | ||
|
||
- name: Set up Docker | ||
uses: docker/setup-buildx-action@v2 | ||
|
||
- name: Log in to Docker Hub | ||
run: echo "${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}" | docker login -u "${{ secrets.DOCKER_HUB_USERNAME }}" --password-stdin | ||
|
||
- name: Set Image Tag | ||
id: image_tag | ||
run: echo "IMAGE_TAG=$(date +'%Y-%m-%d_%H-%M-%S')-$(echo ${{ github.sha }} | cut -c1-8)" >> $GITHUB_ENV | ||
|
||
- name: Decode env.properties from GitHub Secrets | ||
run: | | ||
echo "${{ secrets.ENV_FILE }}" | base64 --decode > ./env.properties | ||
- name: Transfer env.properties to EC2 | ||
uses: appleboy/[email protected] | ||
with: | ||
host: ${{ secrets.EC2_HOST }} | ||
username: ubuntu | ||
key: ${{ secrets.EC2_SSH_KEY }} | ||
source: "./env.properties" | ||
target: "/home/ubuntu/" | ||
|
||
- name: Build and Push Docker image | ||
run: docker buildx build --push --platform linux/amd64 -t kimsongmok/splanet:${{ env.IMAGE_TAG }} . | ||
|
||
- name: Deploy to EC2 | ||
uses: appleboy/[email protected] | ||
with: | ||
host: ${{ secrets.EC2_HOST }} | ||
username: ubuntu | ||
key: ${{ secrets.EC2_SSH_KEY }} | ||
script: | | ||
sudo docker pull kimsongmok/splanet:${{ env.IMAGE_TAG }} | ||
sudo docker stop splanet || true | ||
sudo docker rm splanet || true | ||
sudo docker network inspect splanet >/dev/null 2>&1 || sudo docker network create splanet | ||
sudo docker run -d --name splanet \ | ||
--network splanet \ | ||
--env-file /home/ubuntu/env.properties \ | ||
-p 80:8080 --restart unless-stopped kimsongmok/splanet:${{ env.IMAGE_TAG }} | ||
- name: Check Docker container status | ||
uses: appleboy/[email protected] | ||
with: | ||
host: ${{ secrets.EC2_HOST }} | ||
username: ubuntu | ||
key: ${{ secrets.EC2_SSH_KEY }} | ||
script: | | ||
sudo docker ps -a | ||
sudo docker logs splanet | ||
- name: Clean up old Docker images | ||
uses: appleboy/[email protected] | ||
with: | ||
host: ${{ secrets.EC2_HOST }} | ||
username: ubuntu | ||
key: ${{ secrets.EC2_SSH_KEY }} | ||
script: | | ||
docker image ls --format "{{.ID}} {{.Repository}}:{{.Tag}}" | grep 'kimsongmok/splanet' | tail -n +4 | awk '{print $1}' | xargs docker rmi -f | ||
sudo docker system prune -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,85 @@ | ||
name: CI (빌드 및 테스트) | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- master | ||
- develop | ||
- 'weekly/**' | ||
|
||
jobs: | ||
build-and-test: | ||
runs-on: ubuntu-22.04 | ||
|
||
services: | ||
mysql: | ||
image: mysql:8.0 | ||
env: | ||
MYSQL_DATABASE: ${{ secrets.MYSQL_DATABASE }} | ||
MYSQL_USER: ${{ secrets.MYSQL_USER }} | ||
MYSQL_PASSWORD: ${{ secrets.MYSQL_PASSWORD }} | ||
MYSQL_ROOT_PASSWORD: ${{ secrets.MYSQL_ROOT_PASSWORD }} | ||
ports: | ||
- 3306:3306 | ||
options: >- | ||
--health-cmd="mysqladmin ping -h localhost" | ||
--health-interval=10s | ||
--health-timeout=5s | ||
--health-retries=5 | ||
redis: | ||
image: redis | ||
ports: | ||
- 6379:6379 | ||
|
||
steps: | ||
- name: Checkout Repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Cache Gradle dependencies | ||
uses: actions/cache@v3 | ||
with: | ||
path: | | ||
~/.gradle/caches | ||
~/.gradle/wrapper | ||
key: gradle-${{ runner.os }}-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} | ||
restore-keys: | | ||
gradle-${{ runner.os }}- | ||
- name: Decode env.properties from GitHub Secrets | ||
run: | | ||
echo "${{ secrets.ENV_FILE }}" | base64 --decode > ./src/main/resources/env.properties | ||
- name: Set environment variables from env.properties | ||
run: | | ||
set -o allexport | ||
source ./src/main/resources/env.properties | ||
set +o allexport | ||
- name: Set up JDK 21 | ||
uses: actions/setup-java@v2 | ||
with: | ||
java-version: '21' | ||
distribution: 'temurin' | ||
|
||
- name: Wait for MySQL to be ready | ||
run: | | ||
for i in {30..0}; do | ||
if docker exec $(docker ps -q --filter name=mysql) mysqladmin ping -h localhost; then | ||
echo "MySQL is ready" | ||
break | ||
fi | ||
echo "Waiting for MySQL..." | ||
sleep 1 | ||
done | ||
if [ $i -eq 0 ]; then | ||
echo "MySQL did not become ready in time" | ||
docker logs $(docker ps -q --filter name=mysql) | ||
exit 1 | ||
fi | ||
- name: Build with Gradle | ||
run: ./gradlew build | ||
|
||
- name: Run Tests | ||
run: ./gradlew test |
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 |
---|---|---|
@@ -1,50 +1,50 @@ | ||
version: '3' | ||
|
||
services: | ||
mysql: | ||
container_name: mysql | ||
image: mysql:8.0 | ||
restart: always | ||
environment: | ||
MYSQL_USER: ${MYSQL_USER} | ||
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD} | ||
MYSQL_PASSWORD: ${MYSQL_PASSWORD} | ||
MYSQL_DATABASE: ${MYSQL_DATABASE} | ||
volumes: | ||
- ./splanet-db/mysql:/var/lib/mysql | ||
ports: | ||
- 3306:3306 | ||
networks: | ||
- splanet | ||
|
||
redis: | ||
container_name: redis | ||
image: redis | ||
ports: | ||
- 6379:6379 | ||
networks: | ||
- splanet | ||
|
||
|
||
# 개발할때는 주석처리하여 로컬로 개발합니다. | ||
# springboot: | ||
# container_name: springboot_splanet | ||
# build: | ||
# context: . | ||
# dockerfile: Dockerfile | ||
# mysql: | ||
# container_name: mysql | ||
# image: mysql:8.0 | ||
# restart: always | ||
# depends_on: | ||
# - mysql | ||
# ports: | ||
# - 8080:8080 | ||
# environment: | ||
# SPRING_DATASOURCE_URL: ${SPRING_DATASOURCE_URL} | ||
# SPRING_DATASOURCE_USERNAME: ${SPRING_DATASOURCE_USERNAME} | ||
# SPRING_DATASOURCE_PASSWORD: ${SPRING_DATASOURCE_PASSWORD} | ||
# SPRING_PROFILES_ACTIVE: ${SPRING_PROFILES_ACTIVE} | ||
# MYSQL_USER: ${MYSQL_USER} | ||
# MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD} | ||
# MYSQL_PASSWORD: ${MYSQL_PASSWORD} | ||
# MYSQL_DATABASE: ${MYSQL_DATABASE} | ||
# volumes: | ||
# - ./splanet-db/mysql:/var/lib/mysql | ||
# ports: | ||
# - 3306:3306 | ||
# networks: | ||
# - splanet | ||
# | ||
# redis: | ||
# container_name: redis | ||
# image: redis | ||
# ports: | ||
# - 6379:6379 | ||
# networks: | ||
# - splanet | ||
|
||
|
||
# 개발할때는 주석처리하여 로컬로 개발합니다. | ||
springboot: | ||
container_name: springboot_splanet | ||
build: | ||
context: . | ||
dockerfile: Dockerfile | ||
restart: always | ||
depends_on: | ||
- mysql | ||
ports: | ||
- 8080:8080 | ||
environment: | ||
SPRING_DATASOURCE_URL: ${SPRING_DATASOURCE_URL} | ||
SPRING_DATASOURCE_USERNAME: ${SPRING_DATASOURCE_USERNAME} | ||
SPRING_DATASOURCE_PASSWORD: ${SPRING_DATASOURCE_PASSWORD} | ||
SPRING_PROFILES_ACTIVE: ${SPRING_PROFILES_ACTIVE} | ||
networks: | ||
- splanet | ||
|
||
networks: | ||
splanet: | ||
driver: bridge |
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,16 @@ | ||
package com.splanet.splanet.config; | ||
|
||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.web.servlet.config.annotation.CorsRegistry; | ||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | ||
|
||
@Configuration | ||
public class WebConfig implements WebMvcConfigurer { | ||
|
||
@Override | ||
public void addCorsMappings(CorsRegistry registry) { //인터페이스 WebMvcConfigurer 상속 | ||
registry.addMapping("/**") //모든 경로를 허용해줄것이므로 | ||
.allowedOrigins("*") //리소스 공유 허락할 origin 지정 | ||
.allowedMethods("*"); //모든 메소드를 허용 | ||
} | ||
} |
Oops, something went wrong.