From c4ee0e1c825b4416d66d200a51b1b418cd6e71bb Mon Sep 17 00:00:00 2001 From: Sean Fong Date: Thu, 4 Jul 2024 13:47:19 +0930 Subject: [PATCH 1/8] Deploy documentation to s3 attempt 1 --- .github/workflows/deploy_docs.yml | 25 ++++++-------- .../SmartFormsRedirectToCorrectRoute.js | 34 ++++++++++++++++++- documentation/docusaurus.config.ts | 6 ++-- services/populate-express/package.json | 2 +- 4 files changed, 47 insertions(+), 20 deletions(-) diff --git a/.github/workflows/deploy_docs.yml b/.github/workflows/deploy_docs.yml index 3bdcb69f7..c9b5477f7 100644 --- a/.github/workflows/deploy_docs.yml +++ b/.github/workflows/deploy_docs.yml @@ -2,7 +2,6 @@ name: Smart Forms Docs Deployment Workflow on: push: - branches: ['main'] permissions: contents: read @@ -10,12 +9,8 @@ permissions: id-token: write jobs: - deploy-docusaurus: - name: Deploy Docusaurus to GitHub Pages - environment: - name: github-pages - url: ${{ steps.build-publish.outputs.page_url }} - + deploy-docusaurus-s3: + name: Deploy Docusaurus to S3 runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -26,20 +21,20 @@ jobs: node-version: 18 cache: npm + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v4 + with: + role-to-assume: arn:aws:iam::209248795938:role/SmartFormsReactAppDeployment + aws-region: ap-southeast-2 + - name: Install dependencies run: npm ci - name: Build documentation website run: npm run build -w documentation - - name: Upload Build Artifact - uses: actions/upload-pages-artifact@v3 - with: - path: documentation/build - - - name: Deploy to GitHub Pages - id: deployment - uses: actions/deploy-pages@v4 + - name: Upload static Storybook site to S3 + run: aws s3 sync documentation/build s3://smart-forms-docs/docz deploy-storybook: name: Deploy Storybook to S3 diff --git a/deployment/cloudfront/SmartFormsRedirectToCorrectRoute.js b/deployment/cloudfront/SmartFormsRedirectToCorrectRoute.js index 3c00b65d2..29cd9940a 100644 --- a/deployment/cloudfront/SmartFormsRedirectToCorrectRoute.js +++ b/deployment/cloudfront/SmartFormsRedirectToCorrectRoute.js @@ -64,7 +64,7 @@ function handler(event) { // Handle Storybook routes if (uri.includes('/storybook')) { - // Reroute to smartforms.csiro.au/ig/index.html + // Reroute to smartforms.csiro.au/storybook/index.html if (uri === '/storybook/') { request.uri += 'index.html'; return request; @@ -78,6 +78,38 @@ function handler(event) { return request; } + + // Handle Docz routes + if(uri.includes('/docz')) { + // Reroute to smartforms.csiro.au/docz/index.html + if(uri === '/docz/') { + request.uri += 'index.html'; + return request; + } + + if(uri === '/docz') { + request.uri = '/redirect.html'; + return request; + } + + return request; + } + + // Handle Docs assets and img routes + if(uri.includes('/docs')) { + // Re-route /docs/assets to /assets prefix + if (uri.startsWith('/docs/assets')) { + request.uri = uri.replace('/docs/assets', '/assets'); + return request + } + + // Re-route /docs/img to /img prefix + if (uri.startsWith('/docs/img')) { + request.uri = uri.replace('/docs/img', '/img'); + return request + } + } + // Handle Forms Server API routes if (uri.includes('/api')) { // Remove the /api prefix diff --git a/documentation/docusaurus.config.ts b/documentation/docusaurus.config.ts index b91302cd2..ed994ccde 100644 --- a/documentation/docusaurus.config.ts +++ b/documentation/docusaurus.config.ts @@ -12,12 +12,12 @@ const config: Config = { url: 'https://smartforms.csiro.au', // Set the // pathname under which your site is served // For GitHub pages deployment, it is often '//' - baseUrl: '/docs', + baseUrl: '/docz', // GitHub pages deployment config. // If you aren't using GitHub pages, you don't need these. - organizationName: 'aehrc', // Usually your GitHub org/user name. - projectName: 'smart-forms', // Usually your repo name.\ + organizationName: '', // Usually your GitHub org/user name. + projectName: '', // Usually your repo name.\ trailingSlash: false, onBrokenLinks: 'warn', diff --git a/services/populate-express/package.json b/services/populate-express/package.json index 62228e0f4..6aed579cd 100644 --- a/services/populate-express/package.json +++ b/services/populate-express/package.json @@ -1,6 +1,6 @@ { "name": "populate-express", - "version": "2.2.6", + "version": "2.2.7", "description": "", "main": "lib/index.js", "scripts": { From fdba61032f44b1ea5aeeb906ce73e18808bf8c41 Mon Sep 17 00:00:00 2001 From: Sean Fong Date: Thu, 4 Jul 2024 14:37:42 +0930 Subject: [PATCH 2/8] Deploy documentation to S3 attempt 2 --- .github/workflows/deploy_docs.yml | 2 +- documentation/docusaurus.config.ts | 1 - .../theme/NotFound/Content/LoadingPage.tsx | 23 ------------- .../theme/NotFound/Content/NotFoundPage.tsx | 34 ------------------- .../src/theme/NotFound/Content/index.tsx | 24 ------------- 5 files changed, 1 insertion(+), 83 deletions(-) delete mode 100644 documentation/src/theme/NotFound/Content/LoadingPage.tsx delete mode 100644 documentation/src/theme/NotFound/Content/NotFoundPage.tsx delete mode 100644 documentation/src/theme/NotFound/Content/index.tsx diff --git a/.github/workflows/deploy_docs.yml b/.github/workflows/deploy_docs.yml index c9b5477f7..d2f4313bc 100644 --- a/.github/workflows/deploy_docs.yml +++ b/.github/workflows/deploy_docs.yml @@ -33,7 +33,7 @@ jobs: - name: Build documentation website run: npm run build -w documentation - - name: Upload static Storybook site to S3 + - name: Upload static Docusaurus site to S3 run: aws s3 sync documentation/build s3://smart-forms-docs/docz deploy-storybook: diff --git a/documentation/docusaurus.config.ts b/documentation/docusaurus.config.ts index ed994ccde..1672f3200 100644 --- a/documentation/docusaurus.config.ts +++ b/documentation/docusaurus.config.ts @@ -18,7 +18,6 @@ const config: Config = { // If you aren't using GitHub pages, you don't need these. organizationName: '', // Usually your GitHub org/user name. projectName: '', // Usually your repo name.\ - trailingSlash: false, onBrokenLinks: 'warn', onBrokenMarkdownLinks: 'warn', diff --git a/documentation/src/theme/NotFound/Content/LoadingPage.tsx b/documentation/src/theme/NotFound/Content/LoadingPage.tsx deleted file mode 100644 index 00a9ad6ad..000000000 --- a/documentation/src/theme/NotFound/Content/LoadingPage.tsx +++ /dev/null @@ -1,23 +0,0 @@ -import React from 'react'; -import clsx from 'clsx'; -import Translate from '@docusaurus/Translate'; -import Heading from '@theme/Heading'; -import type { Props } from '@theme/NotFound/Content'; - -function LoadingPage({ className }: Props) { - return ( -
-
-
- - - Loading Page... - - -
-
-
- ); -} - -export default LoadingPage; diff --git a/documentation/src/theme/NotFound/Content/NotFoundPage.tsx b/documentation/src/theme/NotFound/Content/NotFoundPage.tsx deleted file mode 100644 index a70220fa9..000000000 --- a/documentation/src/theme/NotFound/Content/NotFoundPage.tsx +++ /dev/null @@ -1,34 +0,0 @@ -import React from 'react'; -import clsx from 'clsx'; -import Translate from '@docusaurus/Translate'; -import Heading from '@theme/Heading'; -import type { Props } from '@theme/NotFound/Content'; - -function NotFoundPage({ className }: Props) { - return ( -
-
-
- - - Page Not Found - - -

- - We could not find what you were looking for. - -

-

- - Please contact the owner of the site that linked you to the original URL and let them - know their link is broken. - -

-
-
-
- ); -} - -export default NotFoundPage; diff --git a/documentation/src/theme/NotFound/Content/index.tsx b/documentation/src/theme/NotFound/Content/index.tsx deleted file mode 100644 index 3dea7028c..000000000 --- a/documentation/src/theme/NotFound/Content/index.tsx +++ /dev/null @@ -1,24 +0,0 @@ -import React, { useEffect, useState } from 'react'; -import type { Props } from '@theme/NotFound/Content'; -import NotFoundPage from '@site/src/theme/NotFound/Content/NotFoundPage'; -import LoadingPage from '@site/src/theme/NotFound/Content/LoadingPage'; - -export default function NotFoundContent({ className }: Props): JSX.Element { - const [showLoadingPage, setShowLoadingPage] = useState(true); - - useEffect(() => { - const timeoutId = setTimeout(() => { - setShowLoadingPage(false); - }, 500); - - return () => { - clearTimeout(timeoutId); - }; - }, []); - - if (showLoadingPage) { - return ; - } - - return ; -} From 2662dbfdf88af6f8e3f9ea734898854408257277 Mon Sep 17 00:00:00 2001 From: Sean Fong Date: Thu, 4 Jul 2024 15:12:57 +0930 Subject: [PATCH 3/8] Update CloudFront redirect to route function --- .../SmartFormsRedirectToCorrectRoute.js | 31 +++++++------------ 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/deployment/cloudfront/SmartFormsRedirectToCorrectRoute.js b/deployment/cloudfront/SmartFormsRedirectToCorrectRoute.js index 29cd9940a..1167760a5 100644 --- a/deployment/cloudfront/SmartFormsRedirectToCorrectRoute.js +++ b/deployment/cloudfront/SmartFormsRedirectToCorrectRoute.js @@ -48,18 +48,21 @@ function handler(event) { } } + // Replace http://example.com/ig/* into http://example.com/ig/*/index.html // if (uri.match(/\/ig\/[a-z0-9]+\//i)) { // request.uri += "index.html"; // return request; // } + var uriChunks = uri.split('/'); var lastUriChunk = uriChunks[uriChunks.length - 1]; if (!lastUriChunk.includes('.')) { request.uri += '.html'; return request; } + } // Handle Storybook routes @@ -79,35 +82,25 @@ function handler(event) { } - // Handle Docz routes - if(uri.includes('/docz')) { - // Reroute to smartforms.csiro.au/docz/index.html - if(uri === '/docz/') { + // Handle Docs routes + if (uri.includes('/docs')) { + // Reroute to smartforms.csiro.au/docs/index.html + if (uri === '/docs/') { request.uri += 'index.html'; return request; } - if(uri === '/docz') { + if (uri === '/docs') { request.uri = '/redirect.html'; return request; } - return request; - } - - // Handle Docs assets and img routes - if(uri.includes('/docs')) { - // Re-route /docs/assets to /assets prefix - if (uri.startsWith('/docs/assets')) { - request.uri = uri.replace('/docs/assets', '/assets'); - return request + if (!uri.includes('.')) { + request.uri += '/index.html'; + return request; } - // Re-route /docs/img to /img prefix - if (uri.startsWith('/docs/img')) { - request.uri = uri.replace('/docs/img', '/img'); - return request - } + return request; } // Handle Forms Server API routes From 0c3273f9acdea4a223050afd9ca9c00cb93bdb87 Mon Sep 17 00:00:00 2001 From: Sean Fong Date: Thu, 4 Jul 2024 15:14:10 +0930 Subject: [PATCH 4/8] Deploy documentation to S3 attempt 3 --- .github/workflows/deploy_docs.yml | 2 +- .../cloudfront/SmartFormsRedirectToCorrectRoute.js | 10 +++++----- documentation/docs/sdc/index.mdx | 2 +- documentation/docusaurus.config.ts | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/deploy_docs.yml b/.github/workflows/deploy_docs.yml index d2f4313bc..dafee6e65 100644 --- a/.github/workflows/deploy_docs.yml +++ b/.github/workflows/deploy_docs.yml @@ -34,7 +34,7 @@ jobs: run: npm run build -w documentation - name: Upload static Docusaurus site to S3 - run: aws s3 sync documentation/build s3://smart-forms-docs/docz + run: aws s3 sync documentation/build s3://smart-forms-docs/docs deploy-storybook: name: Deploy Storybook to S3 diff --git a/deployment/cloudfront/SmartFormsRedirectToCorrectRoute.js b/deployment/cloudfront/SmartFormsRedirectToCorrectRoute.js index 1167760a5..c6c5cdb70 100644 --- a/deployment/cloudfront/SmartFormsRedirectToCorrectRoute.js +++ b/deployment/cloudfront/SmartFormsRedirectToCorrectRoute.js @@ -82,15 +82,15 @@ function handler(event) { } - // Handle Docs routes - if (uri.includes('/docs')) { - // Reroute to smartforms.csiro.au/docs/index.html - if (uri === '/docs/') { + // Handle Docz routes + if (uri.includes('/docz')) { + // Reroute to smartforms.csiro.au/docz/index.html + if (uri === '/docz/') { request.uri += 'index.html'; return request; } - if (uri === '/docs') { + if (uri === '/docz') { request.uri = '/redirect.html'; return request; } diff --git a/documentation/docs/sdc/index.mdx b/documentation/docs/sdc/index.mdx index 54e021d07..915a4708a 100644 --- a/documentation/docs/sdc/index.mdx +++ b/documentation/docs/sdc/index.mdx @@ -11,7 +11,7 @@ The SDC specification provides a set of guidance around the use of Questionnaire :::tip -Before diving into this section, it might be worth reading the [usage examples guide](/docs/components#usage-examples) in the Components section. +Before diving into this section, it might be worth reading the [usage examples guide](/docs/components#usage-examples-guide) in the Components section. ::: diff --git a/documentation/docusaurus.config.ts b/documentation/docusaurus.config.ts index 1672f3200..35807377b 100644 --- a/documentation/docusaurus.config.ts +++ b/documentation/docusaurus.config.ts @@ -12,7 +12,7 @@ const config: Config = { url: 'https://smartforms.csiro.au', // Set the // pathname under which your site is served // For GitHub pages deployment, it is often '//' - baseUrl: '/docz', + baseUrl: '/docs', // GitHub pages deployment config. // If you aren't using GitHub pages, you don't need these. From 9a70161055f945b4a04d037973985c399ffa8483 Mon Sep 17 00:00:00 2001 From: Sean Fong Date: Thu, 4 Jul 2024 16:45:32 +0930 Subject: [PATCH 5/8] Add trust proxy to preserve HTTPS protocol in extract-express --- push-extract-image.sh | 2 +- services/extract-express/package.json | 2 +- services/extract-express/src/index.ts | 6 ++++++ services/extract-express/src/transform.ts | 2 +- 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/push-extract-image.sh b/push-extract-image.sh index 6ef8567c5..7a0687de5 100644 --- a/push-extract-image.sh +++ b/push-extract-image.sh @@ -24,5 +24,5 @@ cd services/extract-express && npm run compile && cd - # Build the Docker image for multiple architectures, then push to Docker Hub. docker buildx build --file ./services/extract-express/Dockerfile \ --tag aehrc/smart-forms-extract:latest \ - --tag aehrc/smart-forms-extract:v0.3.0 \ + --tag aehrc/smart-forms-extract:v0.3.1 \ --platform linux/amd64,linux/arm64/v8 --push --no-cache . diff --git a/services/extract-express/package.json b/services/extract-express/package.json index 6488d43db..17a61ca54 100644 --- a/services/extract-express/package.json +++ b/services/extract-express/package.json @@ -1,6 +1,6 @@ { "name": "extract-express", - "version": "0.3.0", + "version": "0.3.1", "description": "", "main": "lib/index.js", "scripts": { diff --git a/services/extract-express/src/index.ts b/services/extract-express/src/index.ts index 53a815665..d77ff0004 100644 --- a/services/extract-express/src/index.ts +++ b/services/extract-express/src/index.ts @@ -48,9 +48,15 @@ app.use( origin: '*' }) ); + +// Allows the app to accept JSON and URL encoded data up to 50MB app.use(express.json({ limit: '50mb' })); app.use(express.urlencoded({ extended: true })); +// Allows the app to work behind reverse proxies, forwarding the correct req.protocol to the /StructureMap/$transform call +// Without this, doing a HTTPS $extract call will result in a HTTP $transform call +app.set('trust proxy', true); + app.get('/fhir/QuestionnaireResponse/\\$extract', (_, res) => { res.send( 'This service is healthy!\nPerform a POST request to the same path for QuestionnaireResponse $extract.' diff --git a/services/extract-express/src/transform.ts b/services/extract-express/src/transform.ts index 6c316e8d8..f9595318f 100644 --- a/services/extract-express/src/transform.ts +++ b/services/extract-express/src/transform.ts @@ -64,7 +64,7 @@ export async function invokeTransform( ); } - return await response.json(); + return response.json(); } export interface TransformInputParameters extends Parameters { From a7e2eec2560e5839c3cbc69f95b29ae5622f106c Mon Sep 17 00:00:00 2001 From: Sean Fong Date: Thu, 4 Jul 2024 16:48:07 +0930 Subject: [PATCH 6/8] Add trust proxy to preserve HTTPS protocol in populate and assemble express --- services/assemble-express/src/index.ts | 6 ++++++ services/populate-express/src/index.ts | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/services/assemble-express/src/index.ts b/services/assemble-express/src/index.ts index 9b59496d3..4c74dc7d7 100644 --- a/services/assemble-express/src/index.ts +++ b/services/assemble-express/src/index.ts @@ -42,9 +42,15 @@ app.use( origin: '*' }) ); + +// Allows the app to accept JSON and URL encoded data up to 50MB app.use(express.json({ limit: '50mb' })); app.use(express.urlencoded({ extended: true })); +// Allows the app to work behind reverse proxies, forwarding the correct req.protocol to the /StructureMap/$transform call +// Without this, doing a HTTPS $extract call will result in a HTTP $transform call +app.set('trust proxy', true); + app.get('/fhir/Questionnaire/\\$assemble', (_, res) => { res.send( 'This service is healthy!\nPerform a POST request to the same path for Questionnaire $assemble.' diff --git a/services/populate-express/src/index.ts b/services/populate-express/src/index.ts index 003368f03..be50cafb6 100644 --- a/services/populate-express/src/index.ts +++ b/services/populate-express/src/index.ts @@ -44,9 +44,15 @@ app.use( origin: '*' }) ); + +// Allows the app to accept JSON and URL encoded data up to 50MB app.use(express.json({ limit: '50mb' })); app.use(express.urlencoded({ extended: true })); +// Allows the app to work behind reverse proxies, forwarding the correct req.protocol to the /StructureMap/$transform call +// Without this, doing a HTTPS $extract call will result in a HTTP $transform call +app.set('trust proxy', true); + app.get('/fhir/Questionnaire/\\$populate', (_, res) => { res.send( 'This service is healthy!\nPerform a POST request to the same path for Questionnaire $populate.' From dfef7f57259ff80ad3b94bcd0ac0792ff6c28ab2 Mon Sep 17 00:00:00 2001 From: Sean Fong Date: Thu, 4 Jul 2024 17:13:32 +0930 Subject: [PATCH 7/8] Add FORMS_SERVER_URL='https://smartforms.csiro.au/api/fhir' env to deployed $assemble --- deployment/forms-server/assemble-endpoint/lib/index.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/deployment/forms-server/assemble-endpoint/lib/index.ts b/deployment/forms-server/assemble-endpoint/lib/index.ts index cb0081f27..8ef4a0998 100644 --- a/deployment/forms-server/assemble-endpoint/lib/index.ts +++ b/deployment/forms-server/assemble-endpoint/lib/index.ts @@ -38,7 +38,10 @@ export class AssembleEndpoint extends Construct { logging: AwsLogDriver.awsLogs({ streamPrefix: 'forms-server-assemble', logRetention: RetentionDays.ONE_MONTH - }) + }), + environment: { + FORMS_SERVER_URL: 'https://smartforms.csiro.au/api/fhir' + } }); this.service = new FargateService(this, 'FormsServerAssembleService', { From 1fee9cec02285159e8f4260f0990d0aa5b3a8496 Mon Sep 17 00:00:00 2001 From: Sean Fong Date: Thu, 4 Jul 2024 17:15:42 +0930 Subject: [PATCH 8/8] Rename CI workflows --- .github/workflows/{main.yml => build_test_lint.yml} | 2 +- .github/workflows/deploy_app.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename .github/workflows/{main.yml => build_test_lint.yml} (97%) diff --git a/.github/workflows/main.yml b/.github/workflows/build_test_lint.yml similarity index 97% rename from .github/workflows/main.yml rename to .github/workflows/build_test_lint.yml index 8d6063271..ac6840eaa 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/build_test_lint.yml @@ -1,4 +1,4 @@ -name: Smart Forms Workflow +name: Smart Forms Build-Test-Lint Workflow on: push: diff --git a/.github/workflows/deploy_app.yml b/.github/workflows/deploy_app.yml index 14dfadb98..3a1600fc9 100644 --- a/.github/workflows/deploy_app.yml +++ b/.github/workflows/deploy_app.yml @@ -1,4 +1,4 @@ -name: Smart Forms App S3 Deployment Workflow +name: Smart Forms App Deployment Workflow on: push: