name: Build and Deploy SQDC Dashboard on: push: branches: - '**' pull_request: branches: - '**' env: REGISTRY_URL: ${{ secrets.REGISTRY_URL }} REGISTRY_USER: ${{ secrets.REGISTRY_USER }} REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }} IMAGE_TAG: ${{ github.sha }} jobs: build: name: Build Docker Image runs-on: ubuntu-latest defaults: run: working-directory: dashboard-sqdc steps: - uses: actions/checkout@v3 - uses: actions/setup-node@v3 with: node-version: '18' cache: 'npm' cache-dependency-path: dashboard-sqdc/package-lock.json - run: npm ci - run: npm run build - uses: docker/setup-buildx-action@v2 - name: Login to Container Registry run: echo "$REGISTRY_PASSWORD" | docker login "$REGISTRY_URL" -u "$REGISTRY_USER" --password-stdin - name: Build and Push API image run: | docker build -f Dockerfile.api -t "$REGISTRY_URL/sortifal/pfee:$IMAGE_TAG" -t "$REGISTRY_URL/sortifal/pfee:latest" . docker push "$REGISTRY_URL/sortifal/pfee:$IMAGE_TAG" docker push "$REGISTRY_URL/sortifal/pfee:latest" - name: Build and Push Frontend image run: | docker build -f Dockerfile.frontend -t "$REGISTRY_URL/sortifal/pfee-frontend:$IMAGE_TAG" -t "$REGISTRY_URL/sortifal/pfee-frontend:latest" . docker push "$REGISTRY_URL/sortifal/pfee-frontend:$IMAGE_TAG" docker push "$REGISTRY_URL/sortifal/pfee-frontend:latest" deploy: name: Deploy to Kubernetes runs-on: ubuntu-latest needs: build if: github.event_name == 'push' defaults: run: working-directory: dashboard-sqdc steps: - uses: actions/checkout@v3 - uses: azure/setup-kubectl@v3 with: version: 'latest' - name: Configure kubectl run: | mkdir -p $HOME/.kube echo "${{ secrets.KUBE_CONFIG }}" > $HOME/.kube/config chmod 600 $HOME/.kube/config - name: Create registry credentials run: | kubectl create secret docker-registry registry-credentials \ --docker-server="$REGISTRY_URL" \ --docker-username="$REGISTRY_USER" \ --docker-password="$REGISTRY_PASSWORD" \ -n sqdc-dashboard \ --dry-run=client -o yaml | kubectl apply -f - - name: Install Kustomize run: | curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash sudo mv kustomize /usr/local/bin/ - name: Deploy with Kustomize run: | cd k8s kustomize edit set image gitea.vidoks.fr/sortifal/pfee="$REGISTRY_URL/sortifal/pfee:$IMAGE_TAG" kustomize edit set image gitea.vidoks.fr/sortifal/pfee-frontend="$REGISTRY_URL/sortifal/pfee-frontend:$IMAGE_TAG" kubectl apply -k . - name: Verify deployment run: | kubectl rollout status deployment/sqdc-api -n sqdc-dashboard --timeout=5m kubectl rollout status deployment/sqdc-frontend -n sqdc-dashboard --timeout=5m kubectl get pods,svc,ingress -n sqdc-dashboard