Skip to content

Commit 684730d

Browse files
authored
Documentation website (#40)
* doc-site: static assets and doc files * doc-site: initial setup * doc-site: build and deploy via GHA * doc-site: update common elements * doc-site: sidebar target self * doc-site: update docusaurus version
1 parent 9e0c56b commit 684730d

37 files changed

+20859
-0
lines changed

.github/workflows/doc-site.yml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: "Build Documentation Site"
2+
on:
3+
push:
4+
branches:
5+
- main
6+
- doc-site
7+
paths:
8+
- doc-site/**
9+
10+
env:
11+
region: us-west-2
12+
s3_sync_path: /docs/modules/frontend-react
13+
BUILD_DOMAIN: ${{ secrets.ZERO_DOC_SITE_DOMAIN_NAME }}
14+
jobs:
15+
build:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v2
19+
- name: Setup node.js
20+
uses: actions/setup-node@v1
21+
with:
22+
node-version: 14.x
23+
- name: Install Dependencies
24+
working-directory: doc-site
25+
run: npm install
26+
- name: Build website
27+
working-directory: doc-site
28+
run: |
29+
npm run build
30+
ls -la
31+
- name: Upload build artifact to Github
32+
uses: actions/upload-artifact@v2
33+
with:
34+
name: build-artifact
35+
path: doc-site/build
36+
37+
deploy:
38+
name: Deploy
39+
runs-on: ubuntu-latest
40+
needs: build
41+
42+
steps:
43+
# Once github action supports nested composite actions (anything `uses` is a composite action)
44+
# Therefore we cannot reuse the code as a separate composite action until it supports it,
45+
# current the deploy logic is in this file twice because of it
46+
## https://github.com/actions/runner/issues/862
47+
- uses: actions/checkout@v2
48+
- name: Configure AWS credentials for S3 sync
49+
uses: aws-actions/configure-aws-credentials@v1
50+
with:
51+
aws-access-key-id: ${{ secrets.ZERO_DOC_SITE_AWS_ACCESS_KEY_ID }}
52+
aws-secret-access-key: ${{ secrets.ZERO_DOC_SITE_AWS_SECRET_ACCESS_KEY }}
53+
aws-region: ${{ env.region }}
54+
- name: Download build artifact from Github
55+
uses: actions/download-artifact@v1
56+
with:
57+
name: build-artifact
58+
path: build/
59+
- name: Sync with S3
60+
shell: bash
61+
run: |
62+
cd build
63+
aws s3 sync . "s3://${{ secrets.ZERO_DOC_SITE_BUCKET_NAME }}${{ env.s3_sync_path }}" --delete
64+
- name: Invalidate Cloudfront
65+
shell: bash
66+
run: |
67+
export DIST_ID=$(aws cloudfront list-distributions --query "DistributionList.Items[?Aliases.Items[?@=='${{ secrets.ZERO_DOC_SITE_BUCKET_NAME }}']].Id | [0]" | tr -d '"')
68+
aws cloudfront create-invalidation --distribution-id ${DIST_ID} --paths "${{ env.s3_sync_path }}*"

doc-site/.gitignore

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Dependencies
2+
/node_modules
3+
4+
# Production
5+
/build
6+
7+
# Generated files
8+
.docusaurus
9+
.cache-loader
10+
11+
# Misc
12+
.DS_Store
13+
.env.local
14+
.env.development.local
15+
.env.test.local
16+
.env.production.local
17+
18+
npm-debug.log*
19+
yarn-debug.log*
20+
yarn-error.log*
21+
22+
# This is downloaded during build time
23+
# to sync with zero core styles
24+
src/css/zero-downloaded-global-custom.css

doc-site/README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Website
2+
3+
This website is built using [Docusaurus 2](https://docusaurus.io/), a modern static website generator.
4+
5+
## Installation
6+
7+
```console
8+
yarn install
9+
```
10+
11+
## Local Development
12+
13+
```console
14+
yarn start
15+
```
16+
17+
This command starts a local development server and opens up a browser window. Most changes are reflected live without having to restart the server.
18+
19+
## Build
20+
21+
```console
22+
yarn build
23+
```
24+
25+
This command generates static content into the `build` directory and can be served using any static contents hosting service.
26+
27+
## Deployment
28+
29+
```console
30+
GIT_USER=<Your GitHub username> USE_SSH=true yarn deploy
31+
```
32+
33+
If you are using GitHub pages for hosting, this command is a convenient way to build the website and push to the `gh-pages` branch.

doc-site/babel.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
presets: [require.resolve('@docusaurus/core/lib/babel/preset')],
3+
};
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
title: Module Life cycle
3+
sidebar_label: Module Life cycle
4+
sidebar_position: 4
5+
---
6+
7+
8+
## Prerequisites
9+
The CI/CD pipeline of the module requires S3 bucket and cloudfront distribution to be created under the same project name. And Injects the CI-user's credentials from into the CI secrets on init phase. These are created from the zero-aws-eks-stack repository.
10+
11+
## Scaffold
12+
Based on Parameters in Project definition(`zero-project.yml`), module will be scaffolded and templated out during Zero create
13+
14+
Options that alter the templated repository
15+
- `userAuth`: Determines whether user auth provider is included in your repository
16+
- `CIVendor`: Scaffolds one of CircleCI / Github actions deployment pipeline
17+
- `billingEnabled`: Includes billing page to load products and api calls to communicated with backend service, and API key in `config.json`
18+
19+
20+
## Module Initialize phase
21+
_Run once only during `zero apply`_
22+
- Sets up CI pipeline with `env-vars` and secrets containing CI-user's AWS Credentials
23+
- Github Actions will rerun the initial commit since it was first ran without the credentials (during `zero create`)
24+
25+
## On-going
26+
### Pull request
27+
- Unit test
28+
### Push to master branch
29+
- Unit test
30+
- Build static site
31+
- (stage) Sync build to S3 bucket
32+
- (stage) Invalidate Cloudfront Cache
33+
- (prod) Sync build to S3 bucket
34+
- (prod) Invalidate Cloudfront Cache
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
---
2+
title: Module Parameters
3+
sidebar_label: Module Parameters
4+
sidebar_position: 2
5+
---
6+
7+
## Parameters
8+
9+
| Parameter | Label | Env-var(apply) | Default |
10+
|--|---|---|---|
11+
| useExistingAwsProfile | Use credentials from an existing AWS profile? | n/a | null |
12+
| profilePicker | n/a | n/a | null |
13+
| accessKeyId | AWS AccessKeyId | AWS_ACCESS_KEY_ID | null |
14+
| secretAccessKey | AWS SecretAccessKey | AWS_SECRET_ACCESS_KEY | null |
15+
| githubAccessToken | Github API Key to setup your repository and optionally CI/CD | GITHUB_ACCESS_TOKEN | null |
16+
| region | Select AWS Region | n/a | null |
17+
| productionHostRoot | Production Root Host Name (e.g. mydomain.com) - this must be the root of the chosen domain, not a subdomain. | n/a | null |
18+
| productionFrontendSubdomain | Production Frontend Host Name (e.g. app.) | n/a | app. |
19+
| productionBackendSubdomain | Production Backend Host Name (e.g. api.) | n/a | api. |
20+
| stagingHostRoot | Staging Root Host Name (e.g. mydomain-staging.com) - this must be the root of the chosen domain, not a subdomain. | n/a | null |
21+
| stagingFrontendSubdomain | Staging Frontend Host Name (e.g. app.) | n/a | app. |
22+
| stagingBackendSubdomain | Staging Backend Host Name (e.g. api.) | n/a | api. |
23+
| randomSeed | Random seed that will be shared between projects to come up with deterministic resource names | n/a | null |
24+
| userAuth | Enable user management using Kratos and authentication using the Oathkeeper access proxy? | n/a | true |
25+
| CIVendor | Using either circleCI or github Actions to build / test your repository | n/a | circleci |
26+
| circleciApiKey | Circle CI API Key to setup your CI/CD for repositories | CIRCLECI_API_KEY | null |
27+
| billingEnabled | Provides a subscription example using stripe in backend and frontend repository | n/a | null |
28+
| stagingStripePublicApiKey | Staging Stripe public api key, used for frontend repository (Recommended: using sandbox key while setting up) | n/a | null |
29+
| stagingStripeSecretApiKey | Staging Stripe secret api key, used for backend repository (Recommended: using sandbox key while setting up) | n/a | null |
30+
| productionStripePublicApiKey | Production Stripe public api key, used for frontend repository (Recommended: using sandbox key while setting up) | n/a | null |
31+
| productionStripeSecretApiKey | Production Stripe secret api key, used for backend repository (Recommended: using sandbox key while setting up) | n/a | null |
32+
33+
:::info
34+
Content generated by
35+
```shell
36+
## requires binary: `yq`
37+
which yqq >/dev/null || echo "Please install yq"
38+
cat <<EOF
39+
| Parameter | Label | Env-var(apply) | Default |
40+
|--|---|---|---|
41+
EOF
42+
cat zero-module.yml | yq -r '.parameters[] | "| " + .field + " | " + (.label//"n/a") + " | " + (.envVarName //"n/a") + " | " + ((.default)|tostring //"n/a") + " | "'
43+
```
44+
:::

doc-site/docs/about/overview.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
title: Overview
3+
sidebar_label: Overview
4+
sidebar_position: 1
5+
---
6+
7+
8+
This is a [Zero] module which sets up a
9+
React web-app bundled statically served through CloudFront and S3 from the [zero-aws-eks-stack][zero-infra].
10+
11+
The `/templates` folder is meant to be filled in via [Zero][zero] and results in Simple React application. It also contains a simple CircleCI pipeline which defines how to build and deploy the service.
12+
13+
This repository is business-logic agnostic; mainly showcasing some universal best practices:
14+
15+
- Creating an optimized build of your frontend application.
16+
- Out of the box CI/CD flow CircleCi.
17+
- testing
18+
- building your web-app as a static distribution in /dist folder.
19+
- syncs the built bundle to AWS S3.
20+
- invalidates Cloudfront cached version.
21+
22+
[zero]: https://github.com/commitdev/zero
23+
[zero-infra]: https://github.com/commitdev/zero-aws-eks-stack
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
title: Billing using Stripe
3+
sidebar_label: Stripe
4+
sidebar_position: 3
5+
---
6+
7+
## Billing example
8+
If you have enabled Billing from Zero, a subscription and checkout example using [Stripe](https://stripe.com), coupled with the backend repository to provide an end-to-end checkout example for you to customize. We also setup a webhook and an endpoint in the backend to receive webhook when events occur.
9+
10+
### Requirements
11+
This billing example requires the following backend API endpoints:
12+
```
13+
GET /billing/products
14+
POST /billing/success
15+
POST /billing/cancel
16+
POST /billing/checkout
17+
```
18+
19+
### Setup
20+
The following example content has been set up in Stripe:
21+
- 1 product
22+
- 3 prices(subscriptions) [annual, monthly, daily]
23+
- 1 webhook [`charge.failed`, `charge.succeeded`, `customer.created`, `subscription_schedule.created`]
24+
See link for available webhooks: https://stripe.com/docs/api/webhook_endpoints/create?lang=curl#create_webhook_endpoint-enabled_events
25+
26+
this is setup using the script [scripts/stripe-example-setup.sh][backend-stripe-setup-script]
27+
28+
### Deployment
29+
The deployment requires the publishable key in the build, per environment you will have to provide `stripePublishableKey` in `config/<env>.json` [`production`/`staging`/`development`], then when CI builds it will create a bundle with the Stripe publishable API key
30+
31+
[backend-stripe-setup-script]: https://github.com/commitdev/zero-deployable-backend/blob/main/templates/scripts/stripe-example-setup.sh
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
title: User Auth
3+
sidebar_label: User Auth
4+
sidebar_position: 1
5+
---
6+
7+
## Authentication
8+
If you enabled `user_auth` from Project definition. An authentication setup would be templated out along side your frontend application.
9+
With examples of:
10+
- Authenticated and Unauthenticated navigation bar
11+
- Auth-provider implemented with user status checking
12+
- Home page with 2 blocks of data from backend, one requiring authentication
13+
- Signup/Login/Password reset forms secured with CSRF token
14+
- Example of backend API calls authenticated via https only cookie using signed JWT tokens
15+
16+
## Concept
17+
This example is built with backend components [ORY Oathkeepr][oathkeeper] as an access identity proxy and [ORY Kratos][kratos] as user-management system.
18+
19+
### Forms
20+
Forms on the frontend are secured with [CSRF tokens][csrf], they are a nonce that ensure the request cannot be repeatedly executed. Each form request(signup/login/password reset) are initiated and identifiable.
21+
22+
### API calls to the backend
23+
API calls to the backend are authenticated via the Oathkeeper proxy, they are made to the backend with `credentials: include`
24+
```javascript
25+
fetch(uri,{ credentials : "include" });
26+
```
27+
This will pass along `same-origin`'s cookie along with the request, and through Oathkeeper Proxy will inspect the Cookie against Kratos for authenticity and expiry, and upon unauthenticated request it will return `401 Unauthorized` and request **will not** make it to the backend service.
28+
29+
30+
[kratos]: https://github.com/ory/kratos
31+
[oathkeeper]: https://github.com/ory/oathkeeper
32+
[csrf]:https://owasp.org/www-community/attacks/csrf

doc-site/docusaurus.config.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/** @type {import('@docusaurus/types').DocusaurusConfig} */
2+
const { downloadCommonCustomCss, themeConfig, stylesheets, misc } = require('@commitdev/zero-doc-site-common-elements');
3+
4+
const siteUrl = process.env.BUILD_DOMAIN ? `https://${process.env.BUILD_DOMAIN}` : 'https://staging.getzero.dev';
5+
const baseUrl = '/docs/modules/frontend-react/';
6+
const repositoryName = 'zero-deployable-react-frontend';
7+
8+
let customCss;
9+
try {
10+
customCss = require.resolve(downloadCommonCustomCss());
11+
} catch (e) {
12+
console.error("Failing back to local css, if you see this warning means your module theme is likely outdated")
13+
customCss = require.resolve('./src/css/fallback.css');
14+
}
15+
16+
module.exports = {
17+
title: 'Zero Frontend - React Documentation',
18+
tagline: 'Opinionated infrastructure to take you from idea to production on day one',
19+
...misc(), //includes onBrokenLinks, onBrokenMarkdownLinks, favicon, organizationName
20+
url: siteUrl,
21+
baseUrl: baseUrl,
22+
projectName: repositoryName,
23+
themeConfig: themeConfig({ siteUrl, repositoryName }),
24+
presets: [
25+
[
26+
'@docusaurus/preset-classic',
27+
{
28+
docs :{
29+
sidebarPath: require.resolve('./sidebars.js'),
30+
path: 'docs',
31+
routeBasePath: '/',
32+
editUrl: `https://github.com/commitdev/${repositoryName}/blob/main/doc-site/`,
33+
},
34+
theme: {
35+
customCss,
36+
},
37+
debug: true,
38+
},
39+
],
40+
],
41+
stylesheets: stylesheets(),
42+
43+
};

0 commit comments

Comments
 (0)