Repository navigation
Update README.md (#183) #72
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: Deploy to OCI | |
| on: | |
| push: | |
| branches: [ dev ] | |
| concurrency: | |
| group: deploy-${{ github.ref }} | |
| cancel-in-progress: true | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v3 | |
| - name: Set up JDK 17 | |
| uses: actions/setup-java@v3 | |
| with: | |
| java-version: '17' | |
| distribution: 'temurin' | |
| - name: Build with Gradle | |
| run: ./gradlew clean build -x test | |
| - name: Send to Server | |
| uses: appleboy/scp-action@master | |
| with: | |
| host: ${{ secrets.SERVER_IP }} | |
| username: ubuntu | |
| key: ${{ secrets.SSH_PRIVATE_KEY }} | |
| source: "build/libs/AccountBookForMoms-0.0.1-SNAPSHOT.jar,docker-compose.yml,Dockerfile,nginx.conf" | |
| target: "/home/ubuntu/app" | |
| - name: Create secret file | |
| uses: appleboy/ssh-action@master | |
| with: | |
| host: ${{ secrets.SERVER_IP }} | |
| username: ubuntu | |
| key: ${{ secrets.SSH_PRIVATE_KEY }} | |
| script: | | |
| cat << 'EOF' > /home/ubuntu/app/application-secret.yml | |
| ${{ secrets.APPLICATION_SECRET }} | |
| EOF | |
| - name: Create FCM secret JSON file | |
| uses: appleboy/ssh-action@master | |
| with: | |
| host: ${{ secrets.SERVER_IP }} | |
| username: ubuntu | |
| key: ${{ secrets.SSH_PRIVATE_KEY }} | |
| script: | | |
| cat << 'EOF' > /home/ubuntu/app/firebase-service-account.json | |
| ${{ secrets.FCM_JSON_CONFIG }} | |
| EOF | |
| - name: Run on Server | |
| uses: appleboy/ssh-action@master | |
| with: | |
| host: ${{ secrets.SERVER_IP }} | |
| username: ubuntu | |
| key: ${{ secrets.SSH_PRIVATE_KEY }} | |
| script: | | |
| cd /home/ubuntu/app && \ | |
| cp build/libs/AccountBookForMoms-0.0.1-SNAPSHOT.jar . && \ | |
| sudo docker compose up -d --no-deps --build app --remove-orphans && \ | |
| sudo docker compose restart nginx | |
| - name: Send Discord Notification | |
| if: always() | |
| run: | | |
| if [ "${{ job.status }}" == "success" ]; then | |
| STATUS="✅ 배포 성공!" | |
| COLOR=5763719 | |
| else | |
| STATUS="❌ 배포 실패!" | |
| COLOR=15548997 | |
| fi | |
| TITLE="백엔드 CI/CD 알림" | |
| BRANCH="${{ github.ref_name }}" | |
| COMMIT_MSG=$(echo "${{ github.event.head_commit.message }}" | head -n 1 | sed 's/"/\\"/g') | |
| LOG_URL="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" | |
| curl -H "Content-Type: application/json" \ | |
| -d "{\"embeds\": [{\"title\": \"$TITLE\", \"color\": $COLOR, \"description\": \"**결과:** $STATUS\n**브랜치:** \`$BRANCH\`\n**커밋:** $COMMIT_MSG\n\n[빌드 결과 확인하기]($LOG_URL)\"}]}" \ | |
| ${{ secrets.DISCORD_WEBHOOK }} |