Skip to content

Commit ad1ddb9

Browse files
committed
updated to terraform
1 parent 4c4fa39 commit ad1ddb9

File tree

6 files changed

+206
-295
lines changed

6 files changed

+206
-295
lines changed

.github/workflows/release-tf.yml

Lines changed: 10 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ on:
55
- '*'
66
env:
77
CLOUDSDK_CORE_DISABLE_PROMPTS: 1
8-
SA_NAME: terraform_access
98
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
1012
jobs:
1113
release:
1214
runs-on: ubuntu-latest
@@ -22,39 +24,6 @@ jobs:
2224
run: |
2325
cargo test
2426
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-
#
5827
- uses: GoogleCloudPlatform/github-actions/setup-gcloud@master
5928
with:
6029
version: '275.0.0'
@@ -67,69 +36,21 @@ jobs:
6736
docker build . -f docker/option_price.Dockerfile --tag gcr.io/$PROJECT_ID/$SERVICE_NAME:$GITHUB_SHA
6837
docker push gcr.io/$PROJECT_ID/$SERVICE_NAME:$GITHUB_SHA
6938
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
9240
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"
9942
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
12344
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
12749
12850
- name: release files
12951
uses: ncipollo/release-action@v1
13052
with:
13153
artifacts: "./target/x86_64-unknown-linux-musl/release/*,./serverless.yml,./docs/openapi_v2.yml"
132-
# bodyFile: "body.md"
13354
token: ${{ secrets.ACCESS_TOKEN }}
13455
- name: kickoff main site job
13556
run: |

0 commit comments

Comments
 (0)