diff --git a/.github/workflows/cogo_cicd_gradle.yml b/.github/workflows/cogo_cd.yml similarity index 77% rename from .github/workflows/cogo_cicd_gradle.yml rename to .github/workflows/cogo_cd.yml index 05d920d..d52533a 100644 --- a/.github/workflows/cogo_cicd_gradle.yml +++ b/.github/workflows/cogo_cd.yml @@ -1,55 +1,42 @@ -name: Build and Deploy +name: Deploy Docker Image on: push: branches: ["main"] - pull_request: - branches: ["main"] - -permissions: - contents: read jobs: build-docker-image: runs-on: ubuntu-latest steps: - # 리포지토리 체크아웃 - name: Checkout repository uses: actions/checkout@v3 - # JDK 17 설정 - name: Set up JDK 17 uses: actions/setup-java@v3 with: java-version: '17' distribution: 'temurin' - # 줄 끝 형식을 Unix 형식으로 변환 - name: Convert line endings to Unix run: | sudo apt-get install dos2unix dos2unix ./gradlew - # gradlew에 실행 권한 부여 - name: Grant execute permission for gradlew run: chmod +x ./gradlew - # Gradle을 사용하여 Spring Boot 애플리케이션 빌드 - name: Build with Gradle run: ./gradlew clean bootJar - # Docker 이미지를 빌드 - name: Docker image build run: docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/cogoserver . - # Docker Hub에 로그인 - name: Docker login uses: docker/login-action@v2 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_PASSWORD }} - # Docker 이미지를 Docker Hub에 푸시 - name: Docker Hub push run: docker push ${{ secrets.DOCKERHUB_USERNAME }}/cogoserver @@ -57,19 +44,15 @@ jobs: needs: build-docker-image runs-on: self-hosted steps: - # Docker 이미지를 EC2에서 pull - name: Docker pull run: sudo docker pull ${{ secrets.DOCKERHUB_USERNAME }}/cogoserver - # 기존 cogo 컨테이너 중지 - name: Docker stop container run: sudo docker stop cogo 2>/dev/null || true - # 기존 cogo 컨테이너 삭제 - name: Docker remove container run: sudo docker rm cogo 2>/dev/null || true - # 새 컨테이너 실행 - name: Docker run new container run: | sudo docker run --name cogo --rm -d -p 8080:8080 \ @@ -99,13 +82,11 @@ jobs: -e SMS_FROM=${{ secrets.SMS_FROM }} \ -e SQS_NAME=${{ secrets.SQS_NAME }} \ ${{ secrets.DOCKERHUB_USERNAME }}/cogoserver - sleep 5 # 컨테이너 실행 시간을 확보 - sudo docker ps -a # 모든 컨테이너 목록 출력 + sleep 5 + sudo docker ps -a - # 실행된 컨테이너의 로그 확인 - name: Check Docker logs - run: sudo docker logs cogo || true # 컨테이너 로그 출력 + run: sudo docker logs cogo || true - # 미사용 Docker 이미지 삭제 - name: Delete old docker image run: sudo docker system prune -f diff --git a/.github/workflows/cogo_ci.yml b/.github/workflows/cogo_ci.yml new file mode 100644 index 0000000..4f3eb80 --- /dev/null +++ b/.github/workflows/cogo_ci.yml @@ -0,0 +1,32 @@ +name: Build Docker Image + +on: + pull_request: + branches: ["main"] + +jobs: + build-docker-image: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'temurin' + + - name: Convert line endings to Unix + run: | + sudo apt-get install dos2unix + dos2unix ./gradlew + + - name: Grant execute permission for gradlew + run: chmod +x ./gradlew + + - name: Build with Gradle + run: ./gradlew clean bootJar + + - name: Docker image build + run: docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/cogoserver .