Merge pull request #49 from classic-daramg/chore/set-ci-cd #1
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: spring server cd | |
| on: | |
| push: | |
| branches: [ "main" ] | |
| workflow_dispatch: | |
| jobs: | |
| deploy: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Set up JDK 22 | |
| uses: actions/setup-java@v4 | |
| with: | |
| java-version: '22' | |
| distribution: 'temurin' | |
| - name: Setup Gradle | |
| uses: gradle/actions/setup-gradle@v3 | |
| - name: Build with Gradle | |
| run: ./gradlew clean build -x test | |
| - name: Configure AWS Credentials | |
| 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: us-east-1 | |
| - name: Login to ECR Public | |
| uses: aws-actions/aws-ecr-login@v2 | |
| with: | |
| registry-type: public | |
| - name: Docker Build & Push | |
| env: | |
| ECR_URI: ${{ secrets.ECR_URI }} | |
| run: | | |
| BUILD_DATE=$(date +%s) | |
| docker build --build-arg BUILD_DATE=$BUILD_DATE -t $ECR_URI:latest . | |
| docker push $ECR_URI:latest | |
| - name: EC2 ์๋ฒ ๋ฐฐํฌ | |
| uses: appleboy/ssh-action@v1.0.3 | |
| env: | |
| ECR_URI: ${{ secrets.ECR_URI }} | |
| with: | |
| host: ${{ secrets.EC2_HOST }} | |
| username: ${{ secrets.EC2_USERNAME }} | |
| key: ${{ secrets.EC2_SSH_KEY }} | |
| envs: ECR_URI | |
| script: | | |
| cd ~/server | |
| git pull | |
| docker-compose down | |
| docker rmi ${{ env.ECR_URI }}:latest || true | |
| docker-compose pull | |
| docker-compose up -d | |
| docker image prune -f |