운영환경 배포 - V1.5.1 #23
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: Deployment Workflow | |
| on: | |
| push: | |
| branches: [ "main" ] | |
| pull_request: | |
| branches: [ "main" ] | |
| jobs: | |
| build-and-push: | |
| runs-on: ubuntu-latest | |
| env: | |
| SPRING_PROFILES_ACTIVE: test | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v6 | |
| with: | |
| submodules: recursive | |
| token: ${{ secrets.PAT }} | |
| - name: Set up JDK 21 | |
| uses: actions/setup-java@v4 | |
| with: | |
| java-version: '21' | |
| distribution: 'temurin' | |
| - name: Setup Gradle | |
| uses: gradle/actions/setup-gradle@v5 | |
| - name: Grant execute permission for gradlew | |
| run: chmod +x gradlew | |
| - name: Build with Gradle Wrapper | |
| run: ./gradlew clean build --info --stacktrace --no-daemon | |
| - name: Docker login | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_PASSWORD }} | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v3 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Set image tag | |
| id: vars | |
| run: echo "IMAGE_TAG=${GITHUB_SHA::7}" >> $GITHUB_ENV | |
| # Multi-architecture 빌드 및 푸시 | |
| - name: Build and push Docker image | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| file: deploy/Dockerfile | |
| platforms: linux/amd64,linux/arm64 # 두 아키텍처 모두 빌드 | |
| push: true | |
| tags: ${{ secrets.DOCKERHUB_USERNAME }}/startuplight-be:${{ env.IMAGE_TAG }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| - name: Checkout manifest repository | |
| uses: actions/checkout@v6 | |
| with: | |
| repository: 'StartUpLight/STARLIGHT_MANIFEST' | |
| token: ${{ secrets.PAT }} | |
| path: 'manifest' | |
| - name: Update deployment.yml and push manifest | |
| env: | |
| DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} | |
| IMAGE_TAG: ${{ env.IMAGE_TAG }} | |
| run: | | |
| update_manifest() { | |
| local dir="$1" | |
| local file="$dir/production/deployment.yml" | |
| sed -i "s|image:.*|image: ${DOCKERHUB_USERNAME}/startuplight-be:${IMAGE_TAG}|g" "$file" | |
| echo "Updated $file:" | |
| cat "$file" | |
| git -C "$dir" config --local user.email "[email protected]" | |
| git -C "$dir" config --local user.name "SeongHo5356" | |
| git -C "$dir" add production/deployment.yml | |
| if [ -z "$(git -C "$dir" status --porcelain)" ]; then | |
| echo "No changes to commit in $dir" | |
| return 0 | |
| fi | |
| git -C "$dir" commit -m "Update image tag to $IMAGE_TAG" | |
| for i in {1..3}; do | |
| echo "Push attempt $i for $dir" | |
| git -C "$dir" pull --rebase origin main && \ | |
| git -C "$dir" push && \ | |
| echo "Successfully pushed $dir" && \ | |
| break || { | |
| echo "Push failed for $dir, retrying in 2 seconds..." | |
| sleep 2 | |
| } | |
| done | |
| if ! git -C "$dir" diff --quiet origin/main HEAD; then | |
| echo "ERROR: Failed to push $dir after 3 attempts" | |
| return 1 | |
| fi | |
| } | |
| update_manifest manifest |