From 9f781088d7cc1e7ecb2ba6f98d827f43cfc0db85 Mon Sep 17 00:00:00 2001 From: Gyehyun Park Date: Fri, 25 Oct 2024 02:04:44 +0900 Subject: [PATCH] test: deploy test --- .github/workflows/deploy.yml | 92 +++++++------------ Dockerfile | 5 +- docker-compose.yml | 32 +++++++ .../wap/cano_be/CanoBeApplicationTests.java | 13 --- 4 files changed, 67 insertions(+), 75 deletions(-) create mode 100644 docker-compose.yml delete mode 100644 src/test/java/com/wap/cano_be/CanoBeApplicationTests.java diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 8c6fef6..071686c 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,60 +1,32 @@ -name: Deploy To EC2 - -on: - push: - branches: - - main - -jobs: - deploy: - runs-on: ubuntu-latest - steps: - - name: Github Repository 파일 불러오기 - uses: actions/checkout@v4 - - - name: JDK 17버전 설치 - uses: actions/setup-java@v4 - with: - distribution: temurin - java-version: 17 - - - name: application.yml 파일 만들기 - run: echo "${{ secrets.APPLICATION_PROPERTIES }}" > ./src/main/resources/application.yml - - - name: 테스트 및 빌드하기 - run: | - chmod +x ./gradlew - ./gradlew clean build -x test - - - name: AWS Resource에 접근할 수 있게 AWS credentials 설정 - uses: aws-actions/configure-aws-credentials@v4 - with: - aws-region: ap-northeast-2 - aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} - aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - - - name: ECR에 로그인하기 - id: login-ecr - uses: aws-actions/amazon-ecr-login@v2 - - - name: Docker 이미지 생성 - run: docker build -t cano-server . - - - name: Docker 이미지에 Tag 붙이기 - run: docker tag cano-server ${{ steps.login-ecr.outputs.registry }}/cano-server:latest - - - name: ECR에 Docker 이미지 Push하기 - run: docker push ${{ steps.login-ecr.outputs.registry }}/cano-server:latest - - - name: SSH로 EC2에 접속하기 - uses: appleboy/ssh-action@v1.0.3 - with: - host: ${{ secrets.EC2_HOST }} - username: ${{ secrets.EC2_USERNAME }} - key: ${{ secrets.EC2_PRIVATE_KEY }} - script_stop: true - script: | - docker stop cano-server || true - docker rm cano-server || true - docker pull ${{ steps.login-ecr.outputs.registry }}/cano-server:latest - docker run -d --name cano-server --network cano-network -p 8080:8080 ${{ steps.login-ecr.outputs.registry }}/cano-server:latest \ No newline at end of file +version: '3.8' + +services: + mysql: + image: mysql:5.7 + restart: always + environment: + MYSQL_ROOT_PASSWORD: password123 # root 비밀번호 설정 + MYSQL_DATABASE: cano + MYSQL_USER: root # MySQL 유저 설정 + MYSQL_PASSWORD: password123 # root 비밀번호 설정 + ports: + - "3306:3306" + volumes: + - mysql-data:/var/lib/mysql # Docker Volume 사용 + + springboot-app: + build: + context: . + dockerfile: Dockerfile + restart: always + environment: + SPRING_DATASOURCE_URL: jdbc:mysql://mysql:3306/cano + SPRING_DATASOURCE_USERNAME: root # root 유저로 연결 + SPRING_DATASOURCE_PASSWORD: password123 # 비밀번호 설정 + ports: + - "8080:8080" + depends_on: + - mysql + +volumes: + mysql-data: # Docker Volume 정의 diff --git a/Dockerfile b/Dockerfile index c57f141..d876304 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,3 +1,4 @@ FROM eclipse-temurin:17-jdk-alpine -COPY ./build/libs/*SNAPSHOT.jar project.jar -ENTRYPOINT ["java", "-jar", "project.jar"] \ No newline at end of file +COPY ./build/libs/*SNAPSHOT.jar app.jar +EXPOSE 8080 +ENTRYPOINT ["java", "-jar", "app.jar"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..513267f --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,32 @@ +version: '3.8' + +services: + mysql: + image: mysql:5.7 + restart: always + environment: + MYSQL_ROOT_PASSWORD: password123 + MYSQL_DATABASE: cano + MYSQL_USER: root + MYSQL_PASSWORD: password123 + ports: + - "3306:3306" + volumes: + - mysql-data:/var/lib/mysql + + springboot-app: + build: + context: . + dockerfile: Dockerfile + restart: always + environment: + SPRING_DATASOURCE_URL: jdbc:mysql://mysql:3306/cano + SPRING_DATASOURCE_USERNAME: root + SPRING_DATASOURCE_PASSWORD: password123 + ports: + - "8080:8080" + depends_on: + - mysql + +volumes: + mysql-data: diff --git a/src/test/java/com/wap/cano_be/CanoBeApplicationTests.java b/src/test/java/com/wap/cano_be/CanoBeApplicationTests.java deleted file mode 100644 index 1725631..0000000 --- a/src/test/java/com/wap/cano_be/CanoBeApplicationTests.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.wap.cano_be; - -import org.junit.jupiter.api.Test; -import org.springframework.boot.test.context.SpringBootTest; - -@SpringBootTest -class CanoBeApplicationTests { - - @Test - void contextLoads() { - } - -}