Skip to content

Commit d5273ad

Browse files
author
Keith Halsall
committed
Update the website to dynamically add the router url
1 parent 3030f18 commit d5273ad

File tree

2 files changed

+32
-9
lines changed

2 files changed

+32
-9
lines changed

.github/workflows/deploy-website.yml

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
name: Deploy Website to Cloud Run
22

33
on:
4-
push:
5-
paths:
6-
- website/**
4+
workflow_dispatch:
5+
workflow_call:
76

87
env:
98
GEN: "workshop"
@@ -32,22 +31,46 @@ jobs:
3231
run: |
3332
docker build -t gcr.io/summit-enterprise-workshop/${{github.actor}}-website:latest .
3433
docker images
35-
working-directory: ./website
34+
working-directory: .final/website
3635

3736
- name: Push Docker image to Google Container Registry
3837
run: |
3938
docker push gcr.io/summit-enterprise-workshop/${{github.actor}}-website:latest
40-
working-directory: ./website
39+
working-directory: ./final/website
40+
41+
- name: Get Router URL
42+
run: |
43+
gcloud run services describe ${{vars.ACTOR}}-router --region us-central1 --format 'value(status.url)' > url.json
44+
echo "URL=$(cat url.json)" >> $GITHUB_ENV
4145
4246
- name: Deploy Website to Cloud Run
4347
run: |
4448
gcloud run deploy ${{github.actor}}-website \
4549
--image gcr.io/summit-enterprise-workshop/${{github.actor}}-website:latest \
4650
--platform managed \
4751
--region us-central1 \
48-
--update-env-vars APOLLO_KEY=${{ secrets.APOLLO_KEY }},APOLLO_GRAPH_REF=${{ secrets.APOLLO_GRAPH_REF }} \
52+
--update-env-vars APOLLO_KEY=${{ secrets.APOLLO_KEY }},APOLLO_GRAPH_REF=${{ secrets.APOLLO_GRAPH_REF }}, ROUTER_URL=${{env.url}} \
4953
--allow-unauthenticated
5054
- name: Get URL
5155
run: |
5256
gcloud run services describe ${{vars.ACTOR}}-website --region us-central1 --format 'value(status.url)' > url.json
53-
echo "::notice URL=$(cat url.json)"
57+
echo "webURL=$(cat url.json)" >> $GITHUB_ENV
58+
59+
- name: Get current README to update
60+
run: |
61+
curl --request POST \
62+
--header 'content-type: application/json' \
63+
--header 'X-API-Key: user:fp.d88ba77d-487c-4b97-9780-f1e4c5352a22:ftuXT6T7OktKoMaUZhQwSw' \
64+
--url 'https://graphql.api.apollographql.com/api/graphql' \
65+
--data '{"query":"query Query($ref: ID!) {\n variant(ref: $ref) {\n ... on GraphVariant {\n readme {\n content\n }\n }\n }\n}","variables":{"ref":"${{vars.ACTOR}}${{env.GEN}}"}}' -o readme.json
66+
67+
- name: Set Env
68+
run: echo "CONTENT=$(cat readme.json | jq .data.variant.readme.content)" >> $GITHUB_ENV
69+
70+
- name: Update README
71+
run: |
72+
curl --request POST \
73+
--header 'content-type: application/json' \
74+
--header 'X-API-Key: user:fp.d88ba77d-487c-4b97-9780-f1e4c5352a22:ftuXT6T7OktKoMaUZhQwSw' \
75+
--url 'https://graphql.api.apollographql.com/api/graphql' \
76+
--data '{"query":"mutation Mutation($graphId: ID!, $name: String!, $readme: String!) {\n graph(id: $graphId) {\n variant(name: $name) {\n updateVariantReadme(readme: $readme) {\n readme {\n content\n }\n }\n }\n }\n}","variables":{"graphId":"${{vars.ACTOR}}${{env.GEN}}","name":"current","readme":"${{env.CONTENT}} \n###WEBSITE URL \n ${{env.webURL}}"}}'

final/website/src/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ import theme from './theme.js';
1414
import {ChakraProvider} from '@chakra-ui/react';
1515
import { DEFAULT_ROUTER_URL } from './config';
1616

17-
const routerUrl = localStorage.getItem('router-url') || DEFAULT_ROUTER_URL;
17+
const routerUrl = process.env.ROUTER_URL;
1818

1919
// ----- Configure the apollo client here ------
2020
const client = new ApolloClient({
2121
cache: new InMemoryCache(),
22-
uri: 'https://' + routerUrl,
22+
uri: routerUrl,
2323
name: 'web-workshop-client',
2424
version: '0.1'
2525
});

0 commit comments

Comments
 (0)