diff --git a/.github/workflows/cd_template.yaml b/.github/workflows/cd_template.yaml index a6756d9..b952e80 100644 --- a/.github/workflows/cd_template.yaml +++ b/.github/workflows/cd_template.yaml @@ -1,33 +1,48 @@ -name: Deploy to cloudtype +name: Deploy EC2 + on: workflow_dispatch: push: branches: - dev + jobs: deploy: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v3 - - name: Connect deploy key - uses: cloudtype-github-actions/connect@v1 + uses: actions/checkout@v4 + + - name: Set up JDK 17 + uses: actions/setup-java@v4 with: - token: ${{ secrets.CLOUDTYPE_TOKEN }} - ghtoken: ${{ secrets.GHP_TOKEN }} - - name: Deploy - uses: cloudtype-github-actions/deploy@v1 + java-version: '17' + distribution: 'corretto' + + - name: Grant execute permission for gradlew + run: chmod +x ./gradlew + + - name: gradlew bootJar + run: ./gradlew bootJar + + - name: copy jar to server + uses: appleboy/scp-action@master with: - token: ${{ secrets.CLOUDTYPE_TOKEN }} - project: hyewon-0607/mse-project - stage: main - yaml: | - name: mse-project - app: java@17 - options: - ports: 8080 - context: - git: - url: git@github.com:${{ github.repository }}.git - ref: ${{ github.ref }} - preset: java-springboot \ No newline at end of file + host: ${{ secrets.SSH_HOST }} + username: ec2-user + key: ${{ secrets.SSH_KEY }} + port: 22 + source: "build/libs/*.jar" + target: "/home/ec2-user/app" + + - name: Deploy with Docker Compose + uses: appleboy/ssh-action@v0.1.6 + with: + host: ${{ secrets.SSH_HOST }} + username: ec2-user + key: ${{ secrets.SSH_KEY }} + port: 22 + script: | + cd /home/ec2-user/app + docker-compose down + docker-compose up -d --build \ No newline at end of file diff --git a/.github/workflows/ci_template.yaml b/.github/workflows/ci_template.yaml index cb086ca..c458f82 100644 --- a/.github/workflows/ci_template.yaml +++ b/.github/workflows/ci_template.yaml @@ -3,9 +3,8 @@ name: CI # Event Trigger 특정 액션 (Push, Pull_Request)등이 명시한 Branch에서 일어나면 동작을 수행한다. on: - push: - # 배열로 여러 브랜치를 넣을 수 있다. - branches: [ dev, feat/* ] +# push: +# branches: [ dev, feat/* ] # github pull request 생성시 pull_request: branches: @@ -26,9 +25,9 @@ jobs: # with은 plugin 파라미터 입니다. (java 17버전 셋업) - name: java setup - uses: actions/setup-java@v2 + uses: actions/setup-java@v4 with: - distribution: 'adopt' # See 'Supported distributions' for available options + distribution: 'corretto' # See 'Supported distributions' for available options java-version: '17' - name: make executable gradlew diff --git a/build.gradle b/build.gradle index 6069c1c..98b6b47 100644 --- a/build.gradle +++ b/build.gradle @@ -14,6 +14,14 @@ java { } } +bootJar { + archiveFileName = "mse-project.jar" +} + +jar { + enabled = false +} + configurations { compileOnly { extendsFrom annotationProcessor diff --git a/docker-compose.yaml b/docker-compose.yaml index 3cb96ad..fb23c27 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -1,7 +1,22 @@ -version: "3" +version: "3.8" + services: + app: + build: . + container_name: mse-app + ports: + - "8080:8080" + environment: + SPRING_PROFILES_ACTIVE: docker + MYSQL_USER: ${MYSQL_USER} + MYSQL_PASSWORD: ${MYSQL_PASSWORD} + depends_on: + - mysql + - redis + mysql: - image: mysql:latest + image: mysql:8.0 + container_name: mse-mysql ports: - "23306:3306" environment: @@ -9,14 +24,14 @@ services: MYSQL_DATABASE: ${MYSQL_DATABASE} MYSQL_USER: ${MYSQL_USER} MYSQL_PASSWORD: ${MYSQL_PASSWORD} + redis: - image: redis:latest + image: redis:7 + container_name: mse-redis ports: - "26379:6379" + nginx: image: nginx:latest ports: - "80:80" - depends_on: - - redis - - mysql \ No newline at end of file diff --git a/src/main/resources/application-docker.properties b/src/main/resources/application-docker.properties index f7bbd78..711a064 100644 --- a/src/main/resources/application-docker.properties +++ b/src/main/resources/application-docker.properties @@ -1,6 +1,6 @@ # MySQL spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver -spring.datasource.url=jdbc:mysql://mysql:23306/mse_db +spring.datasource.url=jdbc:mysql://mysql:3306/mse_db # DB certification spring.datasource.username=${MYSQL_USER} diff --git a/src/main/resources/application-local.properties b/src/main/resources/application-local.properties new file mode 100644 index 0000000..bd5b242 --- /dev/null +++ b/src/main/resources/application-local.properties @@ -0,0 +1,6 @@ +# certification +spring.config.import=optional:application-local-secret.properties + +# MySQL +spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver +spring.datasource.url=jdbc:mysql://localhost:3306/mse_db \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index af67a11..317f640 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,5 +1,5 @@ spring.application.name=mse_project -spring.profiles.active=local +#spring.profiles.active=local # Session server.servlet.session.timeout=60m @@ -10,4 +10,4 @@ spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQLDialect spring.jpa.properties.hibernate.format_sql=true spring.jpa.show-sql=true logging.level.org.hibernate.SQL=debug -logging.level.org.hibernate.type.descriptor.sql.BasicBinder=trace +logging.level.org.hibernate.type.descriptor.sql.BasicBinder=trace \ No newline at end of file diff --git a/src/test/java/com/mse_project/MseProjectApplicationTests.java b/src/test/java/com/mse_project/MseProjectApplicationTests.java index e45aa77..bbd4b1a 100644 --- a/src/test/java/com/mse_project/MseProjectApplicationTests.java +++ b/src/test/java/com/mse_project/MseProjectApplicationTests.java @@ -2,8 +2,10 @@ import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; @SpringBootTest +@ActiveProfiles("test") class MseProjectApplicationTests { @Test