|
| 1 | +name: Cloud Run Deploy |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - master |
| 7 | + - main |
| 8 | + |
| 9 | +env: |
| 10 | + # Change this section according to your needs |
| 11 | + IMAGE_NAME: iris-dev-template |
| 12 | + SERVICE: iris-dev-template |
| 13 | + DOMAIN_NAME: iris-dev-template.demo.community.intersystems.com |
| 14 | + |
| 15 | + # Leave this section untouched |
| 16 | + PROJECT_ID: iris-community-demos |
| 17 | + CLUSTER_NAME: demo |
| 18 | + GITHUB_SHA: ${{ github.sha }} |
| 19 | + GCR_LOCATION: eu.gcr.io |
| 20 | + REGION: europe-west2 |
| 21 | + NAMESPACE: demo |
| 22 | + |
| 23 | +jobs: |
| 24 | + deploy-cloud-run: |
| 25 | + name: Deploy to Cloud Run |
| 26 | + runs-on: ubuntu-20.04 |
| 27 | + steps: |
| 28 | + - name: Checkout |
| 29 | + uses: actions/checkout@v2 |
| 30 | + |
| 31 | + - name: Setup Cloud SDK |
| 32 | + uses: google-github-actions/setup-gcloud@v0.2.0 |
| 33 | + with: |
| 34 | + version: '327.0.0' |
| 35 | + service_account_key: ${{ secrets.SERVICE_ACCOUNT_KEY }} |
| 36 | + |
| 37 | + - name: Authorize Docker push |
| 38 | + run: gcloud auth configure-docker |
| 39 | + |
| 40 | + - name: Build and Push image |
| 41 | + run: | |
| 42 | + docker buildx build -t ${GCR_LOCATION}/${PROJECT_ID}/${IMAGE_NAME}:${GITHUB_SHA} . |
| 43 | + docker push ${GCR_LOCATION}/${PROJECT_ID}/${IMAGE_NAME}:${GITHUB_SHA} |
| 44 | +
|
| 45 | + - name: Deploy to Cloud Run |
| 46 | + run: | |
| 47 | + echo "[INFO] Set google project..." |
| 48 | + gcloud config set project ${PROJECT_ID} |
| 49 | +
|
| 50 | + echo "[INFO] Deploy service..." |
| 51 | + gcloud run deploy ${SERVICE} \ |
| 52 | + --platform gke \ |
| 53 | + --cluster ${CLUSTER_NAME} \ |
| 54 | + --cluster-location ${REGION} \ |
| 55 | + --namespace ${NAMESPACE} \ |
| 56 | + --port 52773 \ |
| 57 | + --min-instances 1 \ |
| 58 | + --memory 512Mi \ |
| 59 | + --timeout 300 \ |
| 60 | + --verbosity debug \ |
| 61 | + --image ${GCR_LOCATION}/${PROJECT_ID}/${IMAGE_NAME}:${GITHUB_SHA} |
| 62 | +
|
| 63 | + echo "[INFO] Create domain mappings..." |
| 64 | + if [[ $(gcloud run domain-mappings list --platform gke --cluster ${CLUSTER_NAME} --cluster-location ${REGION} --namespace ${NAMESPACE} --filter "DOMAIN=${DOMAIN_NAME}" | grep -v DOMAIN | wc -l) == 0 ]]; then |
| 65 | + gcloud run domain-mappings create \ |
| 66 | + --service ${SERVICE} \ |
| 67 | + --platform gke \ |
| 68 | + --cluster ${CLUSTER_NAME} \ |
| 69 | + --cluster-location ${REGION} \ |
| 70 | + --namespace ${NAMESPACE} \ |
| 71 | + --verbosity debug \ |
| 72 | + --domain ${DOMAIN_NAME} |
| 73 | + fi |
| 74 | +
|
| 75 | + - name: Create domain name |
| 76 | + run: | |
| 77 | + gcloud container clusters get-credentials ${CLUSTER_NAME} --region ${REGION} --project ${PROJECT_ID} |
| 78 | + kubectl version |
| 79 | + echo "[INFO] Checking if [${DOMAIN_NAME}] is in the existing Ingress annotation..." |
| 80 | + CURRENT_DOMAINS_LIST=$(kubectl -n gke-system get svc istio-ingress -o jsonpath="{.metadata.annotations['external-dns\.alpha\.kubernetes\.io/hostname']}") |
| 81 | + if [[ $(echo ${CURRENT_DOMAINS_LIST} | grep -w "${DOMAIN_NAME}" | wc -c) -eq 0 ]]; then \ |
| 82 | + echo "[INFO] Domain [${DOMAIN_NAME}] is ABSENT in the domains list. Adding..."; \ |
| 83 | + kubectl -n gke-system annotate --overwrite svc istio-ingress external-dns\.alpha\.kubernetes\.io/hostname=${CURRENT_DOMAINS_LIST},${DOMAIN_NAME}; \ |
| 84 | + echo -n "[INFO] Resulting domain names: " |
| 85 | + kubectl -n gke-system get svc istio-ingress -o jsonpath="{.metadata.annotations['external-dns\.alpha\.kubernetes\.io/hostname']}" |
| 86 | + else |
| 87 | + echo "[INFO] Domain [${DOMAIN_NAME}] is in the domains list. Leave untouched..."; \ |
| 88 | + fi |
| 89 | +
|
| 90 | + - name: Enable TLS-access |
| 91 | + run: | |
| 92 | + gcloud container clusters get-credentials ${CLUSTER_NAME} --region ${REGION} --project ${PROJECT_ID} |
| 93 | + kubectl version |
| 94 | + kubectl patch configmap config-domainmapping -n knative-serving -p '{"data":{"autoTLS":"Enabled"}}' |
0 commit comments