Merge pull request #34 from WorkTechDevelop/settings-check #33
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
| # .github/workflows/build-and-deploy.yml | |
| name: Build and Deploy React App to K3s | |
| on: | |
| push: | |
| branches: | |
| - main | |
| jobs: | |
| build_and_deploy: | |
| runs-on: ubuntu-latest | |
| env: | |
| IMAGE_NAME: react-app | |
| IMAGE_TAG: build-${{ github.run_number }} | |
| IMAGE_FILE: react-app.tar | |
| steps: | |
| - name: Checkout repo | |
| uses: actions/checkout@v3 | |
| - name: Build Docker image | |
| run: | | |
| docker build -t $IMAGE_NAME:$IMAGE_TAG . | |
| - name: Save Docker image to tar | |
| run: | | |
| docker save $IMAGE_NAME:$IMAGE_TAG -o $IMAGE_FILE | |
| - name: List files after build | |
| run: | | |
| ls -la ${{ github.workspace }} | |
| - name: Check file permissions for react-app.tar | |
| run: | | |
| ls -l ${{ github.workspace }}/react-app.tar | |
| - name: Fix permissions for react-app.tar | |
| run: | | |
| chmod 644 ${{ github.workspace }}/react-app.tar | |
| - name: Copy image to VPS | |
| uses: appleboy/scp-action@v0.1.6 | |
| with: | |
| host: ${{ secrets.SERVER_IP }} | |
| username: ${{ secrets.SERVER_USER }} | |
| key: ${{ secrets.SSH_PRIVATE_KEY }} | |
| source: "${{ github.workspace }}/react-app.tar" | |
| target: "/home/deployer/frontend" | |
| - name: Deploy on VPS | |
| uses: appleboy/ssh-action@v1.0.0 | |
| with: | |
| host: ${{ secrets.SERVER_IP }} | |
| username: ${{ secrets.SERVER_USER }} | |
| key: ${{ secrets.SSH_PRIVATE_KEY }} | |
| script: | | |
| # настроим контекст k3s | |
| export KUBECONFIG=/etc/rancher/k3s/k3s.yaml | |
| # переменные для образа и файла | |
| IMAGE_NAME=react-app | |
| IMAGE_TAG=${{ env.IMAGE_TAG }} | |
| IMAGE_FILE=react-app.tar | |
| echo "Importing image into containerd..." | |
| # теперь путь правильный — не github/workspace, а прямо в frontend | |
| ctr -n k8s.io images import /home/deployer/frontend/$IMAGE_FILE | |
| cd /home/deployer/frontend | |
| echo "Updating deployment to $IMAGE_NAME:$IMAGE_TAG" | |
| k3s kubectl set image deployment wt-frontend-deployment \ | |
| react-container=$IMAGE_NAME:$IMAGE_TAG -n default \ | |
| || k3s kubectl apply -f deployment.yaml | |
| # рестартим rollout | |
| k3s kubectl rollout restart deployment wt-frontend-deployment | |
| # вывод статуса для отладки | |
| k3s kubectl get pods -l app=wt-frontend -n default | |
| k3s kubectl get svc wt-frontend-svc -n default |