diff --git a/.github/workflows/develop_build_deploy.yml b/.github/workflows/develop_build_deploy.yml new file mode 100644 index 0000000..288ed3f --- /dev/null +++ b/.github/workflows/develop_build_deploy.yml @@ -0,0 +1,79 @@ +name: develop push Build and deploy + +on: + push: + branches: [ "develop" ] + +env: + DOCKERHUB_USERNAME: ject4tserver + DOCKERHUB_IMAGE_NAME: studytrip-server + +jobs: + build-deploy: + runs-on: ubuntu-latest + environment: DEV + + strategy: + matrix: + java-version: [ 17 ] + distribution: [ 'temurin' ] + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up JDK + uses: actions/setup-java@v4 + with: + java-version: ${{ matrix.java-version }} + distribution: ${{ matrix.distribution }} + + - name: Grant Execute Permission for Gradlew + run: chmod +x ./gradlew + + - name: Build with Gradle + id: gradle + uses: gradle/gradle-build-action@v2 + with: + arguments: | + bootJar + --scan + + - name: Login to Dockerhub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_ACCESS_KEY }} + + - name: Extract Docker metadata + id: metadata + uses: docker/metadata-action@v5.5.0 + env: + DOCKERHUB_IMAGE_FULL_NAME: ${{ env.DOCKERHUB_USERNAME }}/${{ env.DOCKERHUB_IMAGE_NAME }} + with: + images: ${{ env.DOCKERHUB_IMAGE_FULL_NAME }} + tags: | + type=sha,prefix= + + - name: Build and Push Docker image + uses: docker/build-push-action@v3 + with: + context: . + push: true + tags: ${{ steps.metadata.outputs.tags }} + + - name: Deploy to EC2 Server + uses: appleboy/ssh-action@1.0.3 + env: + DOCKERHUB_IMAGE_FULL_PATH: ${{ steps.metadata.outputs.tags }} + DOCKERHUB_IMAGE_NAME: ${{ env.DOCKERHUB_IMAGE_NAME }} + with: + host: ${{ secrets.EC2_HOST }} + username: ${{ secrets.EC2_USER }} + key: ${{ secrets.SSH_PRIVATE_KEY }} + envs: DOCKERHUB_IMAGE_FULL_PATH, DOCKERHUB_IMAGE_NAME + debug: true + script: | + echo "${{ secrets.DOCKERHUB_ACCESS_TOKEN }}" | docker login -u "${DOCKERHUB_USERNAME}" --password-stdin + docker compose up -d + docker image prune -a -f diff --git a/.github/workflows/develop_deploy.yml b/.github/workflows/develop_deploy.yml new file mode 100644 index 0000000..92d6497 --- /dev/null +++ b/.github/workflows/develop_deploy.yml @@ -0,0 +1,35 @@ +name: develop Deploy + +on: + # 워크플로우를 수동으로 트리거, 수동 배포 + workflow_dispatch: + inputs: + commit_hash: + description: "commit hash" + required: true + +env: + DOCKERHUB_USERNAME: ject4tserver + DOCKERHUB_IMAGE_NAME: studytrip-server + +jobs: + deploy: + runs-on: ubuntu-latest + environment: DEV + + steps: + - name: Deploy to EC2 Server + uses: appleboy/ssh-action@1.0.3 + env: + DOCKERHUB_IMAGE_FULL_PATH: ${{ env.DOCKERHUB_USERNAME }}/${{ env.DOCKERHUB_IMAGE_NAME }}:${{ github.event.inputs.commit_hash }} + DOCKERHUB_IMAGE_NAME: ${{ env.DOCKERHUB_IMAGE_NAME }} + with: + host: ${{ secrets.EC2_HOST }} + username: ${{ secrets.EC2_USER }} + key: ${{ secrets.SSH_PRIVATE_KEY }} + envs: DOCKERHUB_IMAGE_FULL_PATH, DOCKERHUB_IMAGE_NAME + debug: true + script: | + echo "${{ secrets.DOCKERHUB_ACCESS_TOKEN }}" | docker login -u "${DOCKERHUB_USERNAME}" --password-stdin + docker compose up -d + docker image prune -a -f \ No newline at end of file diff --git a/.gitignore b/.gitignore index c93ca88..57fc8b1 100644 --- a/.gitignore +++ b/.gitignore @@ -37,7 +37,7 @@ out/ .vscode/ ### -.DS_Store +**/.DS_Store ### ENV *.env \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..f036759 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,4 @@ +FROM amazoncorretto:17-alpine-jdk +ARG JAR_FILE=build/libs/*.jar +COPY ${JAR_FILE} app.jar +ENTRYPOINT ["java", "-jar", "/app.jar"] \ No newline at end of file diff --git a/build.gradle b/build.gradle index 13a8a26..2acb55c 100644 --- a/build.gradle +++ b/build.gradle @@ -66,6 +66,8 @@ dependencies { testImplementation 'org.mockito:mockito-junit-jupiter' } +jar.enabled = false // 일반 JAR 파일 생성 비활성화 + tasks.named('test') { useJUnitPlatform() }