5
5
- ' *'
6
6
env :
7
7
CLOUDSDK_CORE_DISABLE_PROMPTS : 1
8
- SA_NAME : terraform_access
9
8
PROJECT_ID : finside # use this as source of truth instead of terraform.tfvars
9
+ CUSTOM_DOMAIN : api2.finside.org
10
+ VERSION_MAJOR : 2
11
+ SERVICE_NAME : realoptions
10
12
jobs :
11
13
release :
12
14
runs-on : ubuntu-latest
22
24
run : |
23
25
cargo test
24
26
25
- # Setup gcloud CLI
26
- # To create a service account,
27
- # gcloud iam service-accounts create [SA-NAME] \
28
- # --description "[SA-DESCRIPTION]" \
29
- # --display-name "[SA-DISPLAY-NAME]"
30
-
31
- # to create a key for the service account,
32
- # gcloud iam service-accounts keys create ~/key.json \
33
- # --iam-account [SA-NAME]@[PROJECT-ID].iam.gserviceaccount.com
34
-
35
- # to base64 it,
36
- # cat ~/key.json | base64
37
-
38
- # to get email address,
39
- # gcloud iam service-accounts list
40
-
41
- # to grant roles,
42
- # gcloud projects add-iam-policy-binding [project] \
43
- # --member serviceAccount:[emailaddress] \
44
- # --role roles/run.admin
45
- # gcloud projects add-iam-policy-binding [project] \
46
- # --member serviceAccount:[emailaddress] \
47
- # --role roles/viewer
48
- # gcloud projects add-iam-policy-binding [project] \
49
- # --member serviceAccount:[emailaddress] \
50
- # --role roles/cloudbuild.builds.builder
51
- # gcloud projects add-iam-policy-binding [project] \
52
- # --member serviceAccount:[emailaddress] \
53
- # --role roles/iam.serviceAccountUser
54
- # gcloud projects add-iam-policy-binding [project] \
55
- # --member serviceAccount:[emailaddress] \
56
- # --role roles/firebasehosting.admin
57
- #
58
27
- uses : GoogleCloudPlatform/github-actions/setup-gcloud@master
59
28
with :
60
29
version : ' 275.0.0'
@@ -67,69 +36,21 @@ jobs:
67
36
docker build . -f docker/option_price.Dockerfile --tag gcr.io/$PROJECT_ID/$SERVICE_NAME:$GITHUB_SHA
68
37
docker push gcr.io/$PROJECT_ID/$SERVICE_NAME:$GITHUB_SHA
69
38
70
- # Deploy image to Cloud Run
71
- - name : Deploy
72
- run : |
73
- gcloud run deploy $SERVICE_NAME \
74
- --image gcr.io/$PROJECT_ID/$SERVICE_NAME:$GITHUB_SHA \
75
- --region $RUN_REGION \
76
- --platform managed
77
-
78
- # API Management
79
- # gcloud services enable servicecontrol.googleapis.com
80
- # gcloud services enable endpoints.googleapis.com
81
- # gcloud projects add-iam-policy-binding [project] \
82
- # --member serviceAccount:[emailaddress] \
83
- # --role roles/servicemanagement.configEditor
84
- - name : Swagger
85
- run : |
86
- sed "s/$CUSTOM_DOMAIN/$GATEWAY_SERVICE/g" docs/openapi_v2.yml > docs/urlsubstitute.yml
87
- gcloud endpoints services deploy docs/urlsubstitute.yml \
88
- --project $PROJECT_ID
89
-
90
- # # Todo! dynamic service configuration
91
- - name : Build API Gateway
39
+ - name : Terraform
92
40
run : |
93
- GATEWAY_CONFIG=$(gcloud endpoints configs list --service ${GATEWAY_SERVICE} --limit 1 \
94
- | grep $(date +'%Y-%m-%d') | head -n1 | awk '{print $1;}')
95
- curl --fail -o "service.json" -H "Authorization: Bearer $(gcloud auth print-access-token)" \
96
- "https://servicemanagement.googleapis.com/v1/services/${GATEWAY_SERVICE}/configs/${GATEWAY_CONFIG}?view=FULL"
97
- docker build . -f docker/gateway.Dockerfile --tag gcr.io/${PROJECT_ID}/endpoints-runtime-serverless:${GATEWAY_SERVICE}-${GATEWAY_CONFIG}
98
- docker push gcr.io/${PROJECT_ID}/endpoints-runtime-serverless:${GATEWAY_SERVICE}-${GATEWAY_CONFIG}
41
+ terraform apply -var="custom_api_domain=$CUSTOM_DOMAIN" -var="api_version_major=$VERSION_MAJOR" -var="project=$PROJECT_ID" -var="github_sha=$GITHUB_SHA" -var="service_name=$SERVICE_NAME"
99
42
100
- - name : Deploy Gateway
101
- run : |
102
- GATEWAY_CONFIG=$(gcloud endpoints configs list --service ${GATEWAY_SERVICE} --limit 1 \
103
- | grep $(date +'%Y-%m-%d') | head -n1 | awk '{print $1;}')
104
- gcloud run deploy ${SERVICE_NAME}-gateway \
105
- --image=gcr.io/${PROJECT_ID}/endpoints-runtime-serverless:${GATEWAY_SERVICE}-${GATEWAY_CONFIG} \
106
- --set-env-vars=ESPv2_ARGS=--cors_preset=basic \
107
- --allow-unauthenticated \
108
- --platform managed \
109
- --project $PROJECT_ID \
110
- --region $RUN_REGION
111
-
112
- - name : Policy binding
113
- run : |
114
- gcloud run services add-iam-policy-binding $SERVICE_NAME \
115
- --member "serviceAccount:${{secrets.ESP_PROJECT_NUMBER}}[email protected] " \
116
- --role "roles/run.invoker" \
117
- --platform managed \
118
- --region $RUN_REGION \
119
- --project ${PROJECT_ID}
120
- # had to add service account to verified owners, see https://cloud.google.com/run/docs/mapping-custom-domains
121
- # this will error if custom domain already exists, so || true at the end
122
- - name : Custom domain
43
+ - name : templatize yml
123
44
run : |
124
- gcloud beta run domain-mappings create --service $SERVICE_NAME \
125
- --domain $CUSTOM_DOMAIN --platform managed --region $RUN_REGION \
126
- --project ${PROJECT_ID} || true
45
+ export VISIBLE_HOST=$CUSTOM_DOMAIN
46
+ export HOST=$(terraform output realoptions_gateway_url)
47
+ source /dev/stdin <<<"$(echo 'cat <<EOF >final.yml'; cat ./docs/openapi_v2.yml; echo EOF;)"
48
+ mv -f final.yml ./docs/openapi_v2.yml
127
49
128
50
- name : release files
129
51
uses : ncipollo/release-action@v1
130
52
with :
131
53
artifacts : " ./target/x86_64-unknown-linux-musl/release/*,./serverless.yml,./docs/openapi_v2.yml"
132
- # bodyFile: "body.md"
133
54
token : ${{ secrets.ACCESS_TOKEN }}
134
55
- name : kickoff main site job
135
56
run : |
0 commit comments