diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index 32d3a6de..0e8f49ea 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -1,6 +1,9 @@ name: Main Branch CI Pipeline on: + pull_request: + branches: + - main push: branches: - main @@ -46,65 +49,37 @@ jobs: java-version: 17 distribution: temurin - - name: Gradle 의존성 캐싱 - uses: actions/cache@v4 - with: - path: | - ~/.gradle/caches - ~/.gradle/caches/build-cache - key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} - restore-keys: | - ${{ runner.os }}-gradle- - - - name: Gradle 권한 부여 - run: chmod +x ./gradlew - shell: bash - - - name: Gradle 테스트 - run: ./gradlew clean build - - - name: AWS Resource에 접근할 수 있게 AWS credentials 설정 - uses: aws-actions/configure-aws-credentials@v4 - with: - aws-region: ${{ secrets.AWS_REGION }} - aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} - aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + - name: Build with Gradle + uses: gradle/gradle-build-action@v2.6.0 + - name: Execute Gradle build + run: | + cd backend/bottler # 프로젝트 위치에 맞게 추후 수정 + ./gradlew build - - name: Docker 이미지 빌드 - run: docker build -t bottler-backend:${{ github.sha }} . + - name: Login to Docker Hub + uses: docker/login-action@v2.2.0 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} - - name: Docker 이미지 태그 - run: docker tag bottler-backend:${{ github.sha }} ${{ secrets.ECR_URI }}/bottler-backend:${{ github.sha }} + - name: Docker Image Build + run: | + cd backend/bottler + docker build --platform linux/arm64/v8 -t l2yupa/bottler -f Dockerfile-dev . - - name: AWS ECR 로그인 - uses: aws-actions/amazon-ecr-login@v2 + - name: Docker Hub Push + run: docker push l2yupa/bottler - - name: Docker 이미지 Push - run: docker push ${{ secrets.ECR_URI }}/bottler-backend:${{ github.sha }} + deploy: + runs-on: [self-hosted, Linux, 64] + needs: build - - name: .env 파일 작성 - run: | - echo "DB_URL=${{ secrets.DB_URL }}" >> docker-compose/.env - echo "DB_USERNAME=${{ secrets.DB_USERNAME }}" >> docker-compose/.env - echo "DB_PASSWORD=${{ secrets.DB_PASSWORD }}" >> docker-compose/.env - echo "AWS_ACCESS_KEY=${{ secrets.AWS_ACCESS_KEY_ID }}" >> docker-compose/.env - echo "AWS_SECRET_KEY=${{ secrets.AWS_SECRET_ACCESS_KEY }}" >> docker-compose/.env - echo "AWS_REGION=${{ secrets.AWS_REGION }}" >> docker-compose/.env - echo "BUCKET_NAME=${{ secrets.BUCKET_NAME }}" >> docker-compose/.env - echo "BASE_URL=${{ secrets.BASE_URL }}" >> docker-compose/.env - echo "ECR_URI=${{ secrets.ECR_URI }}" >> docker-compose/.env - echo "OPENAI_API_KEY=${{ secrets.OPENAI_API_KEY }}" >> docker-compose/.env - echo "TAG=${{ github.sha }}" >> docker-compose/.env - - - name: .env 파일 EC2로 복사 + steps: + - name: Pull Latest Docker Image run: | - scp -i ${{ secrets.EC2_SSH_KEY }} .env ubuntu@${{ secrets.EC2_PUBLIC_IP }}:~/docker-compose/.env + sudo docker login --username ${{ secrets.DOCKER_USERNAME }} --password ${{ secrets.DOCKER_PASSWORD }} + sudo docker pull l2yupa/bottler - - name: EC2로 Docker Compose 배포 + - name: Docker Compose run: | - ssh -i ${{ secrets.EC2_SSH_KEY }} ubuntu@${{ secrets.EC2_PUBLIC_IP }} <> build.log 2>> error.log &