name: Build and Deploy Log Center on: push: branches: - main - master jobs: build-and-deploy: runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v3 - name: Set up Docker Buildx uses: docker/setup-buildx-action@v2 with: config-inline: | [registry."docker.io"] mirrors = ["https://docker.m.daocloud.io", "https://docker.1panel.live", "https://hub.rat.dev"] - name: Login to Huawei Cloud SWR uses: docker/login-action@v2 with: registry: ${{ secrets.SWR_SERVER }} username: ${{ secrets.SWR_USERNAME }} password: ${{ secrets.SWR_PASSWORD }} # Build API Image - name: Build and Push API uses: docker/build-push-action@v4 with: context: . file: ./Dockerfile push: true provenance: false tags: ${{ secrets.SWR_SERVER }}/${{ secrets.SWR_ORG }}/log-center-api:latest # Build Web Image - name: Build and Push Web uses: docker/build-push-action@v4 with: context: ./web file: ./web/Dockerfile push: true provenance: false tags: ${{ secrets.SWR_SERVER }}/${{ secrets.SWR_ORG }}/log-center-web:latest build-args: | VITE_API_BASE_URL=https://qiyuan-log-center-api.airlabs.art - name: Setup Kubectl run: | curl -LO "https://files.m.daocloud.io/dl.k8s.io/release/v1.28.2/bin/linux/amd64/kubectl" chmod +x kubectl mv kubectl /usr/local/bin/ - name: Deploy to K3s uses: Azure/k8s-set-context@v3 with: method: kubeconfig kubeconfig: ${{ secrets.KUBE_CONFIG }} - name: Update K8s Manifests run: | echo "Environment: Production" # Replace image placeholders sed -i "s|\${CI_REGISTRY_IMAGE}/log-center-api:latest|${{ secrets.SWR_SERVER }}/${{ secrets.SWR_ORG }}/log-center-api:latest|g" k8s/api-deployment-prod.yaml sed -i "s|\${CI_REGISTRY_IMAGE}/log-center-web:latest|${{ secrets.SWR_SERVER }}/${{ secrets.SWR_ORG }}/log-center-web:latest|g" k8s/web-deployment-prod.yaml # Apply configurations kubectl apply -f k8s/api-deployment-prod.yaml kubectl apply -f k8s/web-deployment-prod.yaml kubectl apply -f k8s/ingress.yaml # Restart deployments kubectl rollout restart deployment/log-center-api kubectl rollout restart deployment/log-center-web