Merge pull request #34 from StartUpLight/develop #3
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" ] | |
| jobs: | |
| build-and-push: | |
| runs-on: ubuntu-latest | |
| env: | |
| SPRING_PROFILES_ACTIVE: test | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| 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@v3 | |
| - 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@v2 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_PASSWORD }} | |
| - name: Set image tag | |
| id: vars | |
| run: echo "IMAGE_TAG=${GITHUB_SHA::7}" >> $GITHUB_ENV | |
| - name: Build Docker image | |
| run: docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/startuplight-be:${{ env.IMAGE_TAG }} -f deploy/Dockerfile . | |
| - name: Docker Hub push | |
| run: docker push ${{ secrets.DOCKERHUB_USERNAME }}/startuplight-be:${{ env.IMAGE_TAG }} | |
| - name: Checkout manifest repository | |
| uses: actions/checkout@v4 | |
| with: | |
| repository: 'StartUpLight/STARLIGHT_MANIFEST' | |
| token: ${{ secrets.PAT }} | |
| path: 'manifest' | |
| - name: Update deployment.yml | |
| env: | |
| DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} | |
| IMAGE_TAG: ${{ env.IMAGE_TAG }} | |
| run: | | |
| sed -i "s|image:.*|image: ${DOCKERHUB_USERNAME}/startuplight-be:${IMAGE_TAG}|g" manifest/production/deployment.yml | |
| # 변경사항 확인 | |
| echo "Updated deployment.yml:" | |
| cat manifest/production/deployment.yml | |
| - name: Commit and push changes | |
| env: | |
| IMAGE_TAG: ${{ env.IMAGE_TAG }} | |
| run: | | |
| cd manifest | |
| git config --local user.email "[email protected]" | |
| git config --local user.name "SeongHo5356" | |
| git add production/deployment.yml | |
| git commit -m "Update image tag to $IMAGE_TAG" || exit 0 | |
| git push |