This repository has been archived by the owner on Dec 9, 2024. It is now read-only.
Work in progress #113
This file contains 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: Deploy on Google Cloud Platform | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Run Lint | |
uses: golangci/golangci-lint-action@v3 | |
- name: Authenticate to Google Cloud | |
uses: google-github-actions/auth@v1 | |
with: | |
credentials_json: ${{ secrets.GOOGLE_CREDENTIALS }} | |
- name: Set up Google Cloud SDK | |
uses: google-github-actions/setup-gcloud@v1 | |
with: | |
project_id: ${{ secrets.GCP_PROJECT_ID }} | |
# - name: Setup Nginx Secret | |
# env: | |
# SERVICE_NAME: ${{ secrets.SERVICE_NAME }} | |
# run: | | |
# cat <<EOF > nginx.conf | |
# server { | |
# listen 8000 default_server; | |
# server_name _; | |
# gzip on; | |
# gzip_vary on; | |
# gzip_proxied any; | |
# gzip_comp_level 6; | |
# gzip_buffers 16 8k; | |
# gzip_http_version 1.1; | |
# gzip_min_length 256; | |
# gzip_types | |
# application/javascript | |
# application/wasm | |
# image/webp | |
# text/css | |
# text/plain; | |
# location ~* \.(?:wasm|js|webp)$ { | |
# access_log off; | |
# log_not_found off; | |
# expires max; | |
# add_header Cache-Control "public"; | |
# try_files $uri $uri/ @proxy; | |
# } | |
# location / { | |
# try_files $uri $uri/ @proxy; | |
# } | |
# location @proxy { | |
# proxy_pass http://127.0.0.1:8888; | |
# proxy_http_version 1.1; | |
# # proxy_set_header Upgrade $http_upgrade; | |
# # proxy_set_header Connection "upgrade"; | |
# # proxy_set_header Host $host; | |
# # proxy_cache_bypass $http_upgrade; | |
# } | |
# sendfile on; | |
# tcp_nopush on; | |
# tcp_nodelay on; | |
# keepalive_timeout 65; | |
# types_hash_max_size 2048; | |
# } | |
# EOF | |
# if ! gcloud secrets create "${SERVICE_NAME}_nginx_config" --replication-policy='automatic' --data-file=nginx.conf; then | |
# echo "Secret already exists. Adding new version..." | |
# gcloud secrets versions add "${SERVICE_NAME}_nginx_config" --data-file=nginx.conf | |
# fi | |
# export PROJECT_NUMBER=$(gcloud projects describe $(gcloud config get-value project) --format='value(projectNumber)') | |
# gcloud secrets add-iam-policy-binding "${SERVICE_NAME}_nginx_config" --member=serviceAccount:${PROJECT_NUMBER}[email protected] --role='roles/secretmanager.secretAccessor' | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Authenticate Docker | |
run: gcloud auth configure-docker --quiet ${{ secrets.REGION }}-docker.pkg.dev | |
- name: Build and push | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
push: true | |
tags: ${{ secrets.REGISTRY }}/${{ secrets.SERVICE_NAME }}:${{ github.sha }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
- name: Setup Sidecar | |
env: | |
SERVICE_NAME: ${{ secrets.SERVICE_NAME }} | |
REGION: ${{ secrets.REGION }} | |
REGISTRY: ${{ secrets.REGISTRY }} | |
GITHUB_SHA: ${{ github.sha }} | |
run: | | |
cat <<EOF | envsubst > service.yaml | |
apiVersion: serving.knative.dev/v1 | |
kind: Service | |
metadata: | |
name: $SERVICE_NAME | |
labels: | |
cloud.googleapis.com/location: $REGION | |
spec: | |
template: | |
spec: | |
containers: | |
- image: $REGISTRY/$SERVICE_NAME:$GITHUB_SHA | |
name: play | |
resources: | |
limits: | |
cpu: 4000m | |
memory: 4Gi | |
EOF | |
gcloud run services replace service.yaml | |
# - name: Deploy on Cloud Run | |
# uses: google-github-actions/deploy-cloudrun@main | |
# with: | |
# image: ${{ secrets.REGISTRY }}/${{ secrets.SERVICE_NAME }}:${{ github.sha }} | |
# service: ${{ secrets.SERVICE_NAME }} | |
# region: ${{ secrets.REGION }} |