| name: Deploy to Google Cloud |
|
|
| on: |
| workflow_dispatch: |
| push: |
| branches: |
| - main |
|
|
| jobs: |
| deploy: |
| runs-on: ubuntu-latest |
| permissions: |
| contents: "read" |
| id-token: "write" |
| steps: |
| - name: Checkout code |
| uses: actions/checkout@v4 |
|
|
| - name: Set image name |
| id: set-image-name |
| run: echo "image_name=${{ vars.DOCKER_REPO_REGION }}-docker.pkg.dev/${{ vars.PROJECT_ID }}/${{ vars.DOCKER_REPO_NAME }}/kimina-lean-server:$(git rev-parse --short HEAD)" >> "$GITHUB_OUTPUT" |
|
|
| - name: Build Docker image |
| run: | |
| docker build . -t "${{ steps.set-image-name.outputs.image_name }}" |
| |
|
|
| - name: "GCP auth" |
| id: "auth" |
| uses: "google-github-actions/auth@v2" |
| with: |
| workload_identity_provider: "${{ vars.WORKLOAD_IDENTITY_PROVIDER_LOCATION }}" |
| service_account: "${{ vars.SERVICE_ACCOUNT }}@${{ vars.PROJECT_ID }}.iam.gserviceaccount.com" |
|
|
| - name: "Set up Cloud SDK" |
| uses: "google-github-actions/setup-gcloud@v2" |
| - name: Configure Docker |
| run: gcloud auth configure-docker ${{ vars.DOCKER_REPO_REGION }}-docker.pkg.dev |
|
|
| - name: Push Docker image |
| run: docker push "${{ steps.set-image-name.outputs.image_name }}" |
|
|
| - name: Create new instance template |
| run: | |
| TEMPLATE="kimina-tpl-${{ github.sha }}" |
| IMAGE="${{ steps.set-image-name.outputs.image_name }}" |
| REGION="${{ vars.DOCKER_REPO_REGION }}" |
| gcloud compute instance-templates create-with-container $TEMPLATE \ |
| --container-image=$IMAGE \ |
| --container-restart-policy=on-failure \ |
| --container-env LEAN_SERVER_HOST=0.0.0.0,LEAN_SERVER_PORT=80,LEAN_SERVER_LOG_LEVEL=INFO,LEAN_SERVER_ENVIRONMENT=prod,LEAN_SERVER_LEAN_VERSION=v4.15.0,LEAN_SERVER_MAX_REPLS=,LEAN_SERVER_MAX_REPL_USES=1000,LEAN_SERVER_MAX_REPL_MEM=8G,LEAN_SERVER_MAX_WAIT=120,LEAN_SERVER_API_KEY=${{ secrets.LEAN_SERVER_API_KEY }}, \ |
| --metadata=instance_group_name=ig-1 \ |
| --container-stdin \ |
| --container-tty \ |
| --machine-type=n2-standard-16 \ |
| --region=$REGION \ |
| --boot-disk-size=50GB --boot-disk-type=pd-ssd \ |
| --tags=http-server,https-server,lb-health-check |
| |
| - name: Roll out rolling‑update to MIG |
| run: | |
| TEMPLATE="kimina-tpl-${{ github.sha }}" |
| REGION="${{ vars.DOCKER_REPO_REGION }}" |
| gcloud compute instance-groups managed rolling-action start-update ig-1 \ |
| --version=template=$TEMPLATE \ |
| --max-unavailable=0 \ |
| --region=$REGION |
| |
| - name: Clean up old instance‑templates |
| run: | |
| # list all kimina‑tpl‑* templates, newest first, skip the first 5, delete the rest |
| old=$(gcloud compute instance-templates list \ |
| --filter="name~^kimina-tpl-" \ |
| --sort-by="~creationTimestamp" \ |
| --format="value(name)" \ |
| | tail -n +6) |
| if [ -n "$old" ]; then |
| gcloud compute instance-templates delete $old -q |
| fi |
| |