Modified deploy.yml to deploy from kubernetes instead of docker compose #7
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 Deploy | |
| on: | |
| push: | |
| branches: [ main ] | |
| jobs: | |
| build-and-push: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Log in to secrets | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Build and Push client | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: ./client | |
| push: true | |
| tags: | | |
| ${{ secrets.DOCKERHUB_USERNAME }}/client:${{ github.run_number }} | |
| ${{ secrets.DOCKER_USERNAME }}/client:latest | |
| - name: Build and Push server | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: ./server | |
| push: true | |
| tags: | | |
| ${{ secrets.DOCKERHUB_USERNAME }}/server:${{ github.run_number }} | |
| ${{ secrets.DOCKERHUB_USERNAME }}/server:latest | |
| deploy: | |
| runs-on: ubuntu-latest | |
| needs: build-and-push | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up kubectl | |
| uses: azure/setup-kubectl@v3 | |
| - name: Configure kubeconfig | |
| run: | | |
| mkdir -p ~/.kube | |
| echo "${{ secrets.KUBECONFIG }}" > ~/.kube/config | |
| chmod 600 ~/.kube/config | |
| - name: Update image tags | |
| run: | | |
| sed -i "s|image: ${{ secrets.DOCKERHUB_USERNAME }}/server:.*|image: ${{ secrets.DOCKERHUB_USERNAME }}/server:${{ github.run_number }}|" k8s/backend/deployment.yaml | |
| sed -i "s|image: ${{ secrets.DOCKERHUB_USERNAME }}/client:.*|image: ${{ secrets.DOCKERHUB_USERNAME }}/client:${{ github.run_number }}|" k8s/frontend/deployment.yaml | |
| - name: Deploy to k3s | |
| run: | | |
| kubectl apply -f k8s/postgres/secret.yaml | |
| kubectl apply -f k8s/postgres/deployment.yaml | |
| kubectl apply -f k8s/backend/deployment.yaml | |
| kubectl apply -f k8s/frontend/deployment.yaml | |
| kubectl rollout status deployment/backend --timeout=120s | |
| kubectl rollout status deployment/frontend --timeout=120s | |
| - name: Verify deployment | |
| run: | | |
| kubectl get pods | |
| kubectl get services |