docs : erd 수정 #189
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: AWS EC2 Deploy | |
| on: | |
| push: | |
| branches: | |
| - main | |
| jobs: | |
| deploy: | |
| runs-on: ubuntu-22.04 | |
| steps: | |
| - uses: actions/checkout@v3 | |
| - name: Set up JDK 17 | |
| uses: actions/setup-java@v3 | |
| with: | |
| java-version: '17' | |
| distribution: 'corretto' | |
| - name: Gradle Caching | |
| uses: actions/cache@v3 | |
| with: | |
| path: | | |
| ~/.gradle/caches | |
| ~/.gradle/wrapper | |
| key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} | |
| restore-keys: | | |
| ${{ runner.os }}-gradle- | |
| - name: Grant execute permission for gradlew | |
| run: chmod +x gradlew | |
| - name: Make application.yml | |
| run: | | |
| mkdir -p src/main/resources | |
| echo "${{ secrets.APPLICATION_SECRET }}" > src/main/resources/application-release.yml | |
| shell: bash | |
| - name: BootJar with Gradle | |
| run: ./gradlew clean bootJar -Dspring.profiles.active=release | |
| - name: Docker Image push | |
| run: | | |
| docker buildx create --use | |
| docker login -u ${{ secrets.DOCKERHUB_USERNAME }} -p ${{ secrets.DOCKERHUB_PASSWORD }} | |
| docker buildx build --platform linux/amd64 \ | |
| -t ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPOSITORY }} \ | |
| --push . | |
| - name: Blue-Green Deploy to EC2 (compose) | |
| uses: appleboy/[email protected] | |
| with: | |
| host: ${{ secrets.EC2_SERVER_IP }} | |
| username: ${{ secrets.SSH_USERNAME }} | |
| key: ${{ secrets.SSH_PRIVATE_KEY }} | |
| script: | | |
| export REGISTRY_IMAGE=${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPOSITORY }}:latest | |
| if docker ps --format '{{.Names}}' | grep -q '^app-blue$'; then | |
| NEXT_PROFILE=green | |
| NEXT_NAME=app-green | |
| CURRENT_PROFILE=blue | |
| CURRENT_NAME=app-blue | |
| NEXT_PORT=8081 | |
| NEXT_CONF=green.conf | |
| else | |
| NEXT_PROFILE=blue | |
| NEXT_NAME=app-blue | |
| CURRENT_PROFILE=green | |
| CURRENT_NAME=app-green | |
| NEXT_PORT=8080 | |
| NEXT_CONF=blue.conf | |
| fi | |
| docker compose --profile $NEXT_PROFILE pull $NEXT_NAME | |
| docker compose --profile $NEXT_PROFILE up -d $NEXT_NAME | |
| for i in {1..24}; do | |
| if curl -fs http://localhost:${NEXT_PORT}/actuator/health; then | |
| break | |
| fi | |
| echo "Waiting for app on port ${NEXT_PORT} to be healthy... ($i/24)" | |
| sleep 5 | |
| done | |
| if curl -fs http://localhost:${NEXT_PORT}/actuator/health; then | |
| ln -sfn ~/nginx/${NEXT_CONF} ~/nginx/nginx.conf | |
| docker exec -i nginx nginx -t | |
| docker exec -i nginx nginx -s reload || docker restart nginx | |
| docker compose --profile $CURRENT_PROFILE stop $CURRENT_NAME | |
| docker compose --profile $CURRENT_PROFILE rm -f $CURRENT_NAME | |
| else | |
| echo "New app failed health check. Rolling back..." | |
| docker compose --profile $NEXT_PROFILE stop $NEXT_NAME | |
| docker compose --profile $NEXT_PROFILE rm -f $NEXT_NAME | |
| exit 1 | |
| fi |