Merge branch 'main' of https://github.com/Speed-Jobs/backend-server #26
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: Build and Push Backend Image | |
| on: | |
| push: | |
| branches: | |
| - main | |
| paths: | |
| - '**' | |
| - '.github/workflows/deploy-server.yaml' | |
| env: | |
| IMAGE_NAME: speedjobs-spring-server # 이미지 이름 통일 | |
| DEPLOYMENT_NAME: speedjobs-spring-server # 디플로이먼트 이름도 env로 관리 | |
| VERSION: "1.0.0" | |
| jobs: | |
| build-and-push: | |
| runs-on: ubuntu-latest | |
| environment: speedjobs-server # GitHub Environment 이름도 통일 | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v3 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v2 | |
| - name: Login to Harbor | |
| run: | | |
| echo "${{ secrets.DOCKER_REGISTRY_PASSWORD }}" | docker login ${{ secrets.DOCKER_REGISTRY }} \ | |
| -u "${{ secrets.DOCKER_REGISTRY_USER }}" \ | |
| --password-stdin | |
| - name: Build Docker image | |
| run: | | |
| docker build --no-cache -t ${{ env.IMAGE_NAME }}:${{ env.VERSION }} . | |
| - name: Tag and Push Docker image | |
| run: | | |
| docker tag ${{ env.IMAGE_NAME }}:${{ env.VERSION }} ${{ secrets.DOCKER_REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.VERSION }} | |
| docker push ${{ secrets.DOCKER_REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.VERSION }} | |
| - name: Setup kubectl | |
| uses: azure/setup-kubectl@v3 | |
| with: | |
| version: 'latest' | |
| - name: Configure Kubernetes | |
| run: | | |
| mkdir -p $HOME/.kube | |
| echo "${{ secrets.KUBECONFIG }}" | base64 -d > $HOME/.kube/config | |
| chmod 600 $HOME/.kube/config | |
| - name: Restart Deployment | |
| run: | | |
| kubectl rollout restart deployment/${{ env.DEPLOYMENT_NAME }} -n skala-practice | |
| kubectl rollout status deployment/${{ env.DEPLOYMENT_NAME }} -n skala-practice --timeout=5m | |
| - name: Summary | |
| run: | | |
| echo "Docker 이미지 푸시 완료" | |
| echo "- ${{ secrets.DOCKER_REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.VERSION }}" | |
| echo "Kubernetes Deployment 재시작 완료 (deployment=${{ env.DEPLOYMENT_NAME }})" |