diff --git a/.github/workflows/be-cd-dev.yml b/.github/workflows/be-cd-dev.yml index 99e5d6f40..768ee7554 100644 --- a/.github/workflows/be-cd-dev.yml +++ b/.github/workflows/be-cd-dev.yml @@ -10,10 +10,8 @@ on: jobs: build: - timeout-minutes: 3 + timeout-minutes: 2 runs-on: ubuntu-latest - env: - DOCKER_REPOSITORY_NAME: ddangkong/ddangkong-api-dev defaults: run: @@ -27,77 +25,38 @@ jobs: run: | echo "${{ secrets.APPLICATION_DEV_YML }}" > ./src/main/resources/application-dev.yml - - name: Setting SSL/TLS Key - run: | - mkdir -p ./src/main/resources/ssl - echo "${{ secrets.SSL_KEY_BASE64 }}" | base64 -d > ./src/main/resources/ssl/keystore.p12 - - name: Set up JDK 17 uses: actions/setup-java@v4 with: distribution: 'temurin' java-version: '17' - - name: Grant execute permission for gradlew - run: chmod +x gradlew - - - name: Build with Gradle + - name: bootJar with Gradle run: ./gradlew bootJar -PcreateRestDocs - - name: Log in to Docker Hub - uses: docker/login-action@v3 - with: - username: ${{ secrets.DOCKER_GMAIL }} - password: ${{ secrets.DOCKER_TOKEN }} - - - name: Build Docker image - run: | - docker compose -f deploy/docker-compose-dev.yml build - docker tag deploy-ddangkong-api-dev:latest $DOCKER_REPOSITORY_NAME:latest + - name: Change artifact file name + run: mv build/libs/*.jar build/libs/app.jar - - name: Push Docker image - run: docker push $DOCKER_REPOSITORY_NAME:latest + - name: Upload artifact file + uses: actions/upload-artifact@v4 + with: + name: app-artifact + path: ./backend/build/libs/app.jar deploy: needs: build timeout-minutes: 2 - runs-on: [ self-hosted, linux, ARM64, dev ] # Self hosted runner 사용 - env: - DOCKER_REPOSITORY_NAME: ddangkong/ddangkong-api-dev - CONTAINER_NAME: ddangkong-api-dev + runs-on: [ self-hosted, linux, ARM64, dev ] steps: - - name: Log in to Docker Hub - uses: docker/login-action@v3 + - name: Download artifact file + uses: actions/download-artifact@v4 with: - username: ${{ secrets.DOCKER_GMAIL }} - password: ${{ secrets.DOCKER_TOKEN }} - - - name: Stop and Remove previous Docker container - run: | - CONTAINER_ID=$(sudo docker ps -aqf name=$CONTAINER_NAME) - if [ -n "${CONTAINER_ID}" ]; then - sudo docker rm -f ${CONTAINER_ID} - echo "Container ${CONTAINER_ID} is stopped and removed." - else - echo "No previous container found with name. Skipping removal." - fi - - - name: Remove previous Docker image - run: | - IMAGE_ID=$(sudo docker images --filter=reference=ddangkong/ddangkong-api-dev --format "{{.ID}}") - if [ -n "${IMAGE_ID}" ]; then - sudo docker rmi ${IMAGE_ID} - echo "Image ${IMAGE_ID} is removed." - else - echo "No previous image found with repository name. Skipping removal." - fi + name: app-artifact + path: ~/app - - name: Pull docker image - run: sudo docker pull $DOCKER_REPOSITORY_NAME:latest + - name: Replace application to latest + run: sudo sh ~/scripts/replace-new-version.sh - - name: Run new Docker container - run: | - docker run -d -p 443:8080 --name $CONTAINER_NAME \ - -v /home/ubuntu/app-logs:/logs \ - $DOCKER_REPOSITORY_NAME:latest + - name: Health check latest application + run: sudo sh ~/scripts/health-check.sh diff --git a/backend/Dockerfile b/backend/Dockerfile deleted file mode 100644 index c84213aac..000000000 --- a/backend/Dockerfile +++ /dev/null @@ -1,7 +0,0 @@ -FROM openjdk:17-jdk-slim - -ARG JAR_FILE=build/libs/*.jar - -COPY ${JAR_FILE} app.jar - -ENTRYPOINT [ "java", "-jar", "-Duser.timezone=Asia/Seoul", "-Dspring.profiles.active=dev", "app.jar" ] diff --git a/backend/deploy/docker-compose-dev.yml b/backend/deploy/docker-compose-dev.yml deleted file mode 100644 index e907798fb..000000000 --- a/backend/deploy/docker-compose-dev.yml +++ /dev/null @@ -1,14 +0,0 @@ -version: "3.8" - -services: - ddangkong-api-dev: - platform: linux/arm64/v8 - build: - context: ../ - dockerfile: Dockerfile - args: - SPRING_PROFILE: dev - environment: - - SPRING_PROFILE=dev - ports: - - "80:8080"