Merge pull request #556 from projects200/fix/ci #236
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: DEV SERVER CI/CD | |
| on: | |
| push: | |
| branches: | |
| - develop | |
| workflow_dispatch: | |
| jobs: | |
| backend-CI: | |
| runs-on: ubuntu-latest | |
| # Testcontainers가 CI 환경에서 Docker를 잘 찾도록 환경 변수 추가 | |
| env: | |
| TESTCONTAINERS_RYUK_DISABLED: true | |
| TESTCONTAINERS_CHECKS_DISABLE: true | |
| DOCKER_HOST: unix:///var/run/docker.sock | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Set up JDK 21 | |
| uses: actions/setup-java@v4 | |
| with: | |
| java-version: "21" | |
| distribution: "corretto" | |
| - name: Cache Gradle packages | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| ~/.gradle/caches | |
| ~/.gradle/wrapper | |
| key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} | |
| restore-keys: | | |
| ${{ runner.os }}-gradle- | |
| # [핵심 2] Docker 소켓 권한 부여 & 상태 확인 | |
| # 이 스텝이 실패하면 아예 Runner 문제임 | |
| - name: Check Docker & Grant Permissions | |
| run: | | |
| echo "Granting permissions to docker socket..." | |
| sudo chmod 666 /var/run/docker.sock | |
| echo "Checking Docker info..." | |
| docker info | |
| shell: bash | |
| - name: Configure AWS credentials | |
| if: ${{ github.ref == 'refs/heads/develop'}} | |
| uses: aws-actions/configure-aws-credentials@v4 | |
| with: | |
| aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
| aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
| aws-region: ${{ secrets.AWS_REGION }} | |
| # 1. 애플리케이션 속성 파일 설정 | |
| - name: Configure Application Properties | |
| run: | | |
| mkdir -p src/main/resources/ | |
| echo ${{ secrets.APPLICATION_DEV_YML }} | base64 -d > src/main/resources/application-dev.yml | |
| shell: bash | |
| # 2. Firebase Admin SDK 설정 | |
| - name: Configure Firebase Admin SDK | |
| run: | | |
| mkdir -p src/main/resources/firebase | |
| echo ${{ secrets.DEV_FIREBASE_ADMIN_SDK_JSON }} | base64 -d > src/main/resources/firebase/undabang-firebase-adminsdk.json | |
| shell: bash | |
| # 3. 모든 설정이 끝난 후 빌드 실행 | |
| # 권한 부여 및 --no-daemon 옵션 추가 (메모리 절약) | |
| - name: Build Gradle | |
| run: | | |
| chmod +x gradlew | |
| ./gradlew clean build -Dspring.profiles.active=dev-docs --no-daemon | |
| shell: bash | |
| - name: Build and push image to Amazon ECR | |
| if: ${{ github.ref == 'refs/heads/develop' }} | |
| env: | |
| REGISTRY: 825773631552.dkr.ecr.ap-northeast-2.amazonaws.com | |
| REPOSITORY: undabang/dev-server-repository | |
| IMAGE_TAG: latest | |
| run: | | |
| aws ecr get-login-password --region ap-northeast-2 | docker login --username AWS --password-stdin $REGISTRY | |
| cp build/libs/*.jar deploy-dev/ | |
| cd deploy-dev | |
| docker build -t $REPOSITORY . | |
| rm *.jar | |
| docker tag $REPOSITORY:$IMAGE_TAG $REGISTRY/$REPOSITORY:$IMAGE_TAG | |
| docker push $REGISTRY/$REPOSITORY:$IMAGE_TAG | |
| - name: Upload build file to S3 and trigger CodeDeploy | |
| if: ${{ github.ref == 'refs/heads/develop' }} | |
| run: | | |
| mkdir -p deploy && cp -r deploy-dev/* deploy/ | |
| zip -r deploy.zip deploy | |
| aws s3 cp deploy.zip s3://${{ secrets.AWS_S3_DEPLOY_DEV_BUCKET_NAME }}/deploy.zip | |
| aws deploy create-deployment \ | |
| --application-name ${{ secrets.AWS_CODEDEPLOY_DEV_APP_NAME }} \ | |
| --deployment-config-name CodeDeployDefault.AllAtOnce \ | |
| --deployment-group-name ${{ secrets.AWS_CODEDEPLOY_DEV_GROUP_NAME }} \ | |
| --file-exists-behavior OVERWRITE \ | |
| --s3-location bucket=${{ secrets.AWS_S3_DEPLOY_DEV_BUCKET_NAME }},bundleType=zip,key=deploy.zip |