Production deployment
The recommended method to deploying your docs site is by using Vercel.
The main benefits of using Vercel over GitHub Pages is the ease of integration with GitHub repos and also deploying automatic previews on Pull Requests. The only caveat is that private GitHub repos require all pushes to a PR to also be members of the Vercel account which increases the cost of the subscription. In such a case, there is a workaround that allows Vercel to still host the docs and provide previews but requires a little more setup.
Scenario A: Public GitHub repo​
Once you are ready to deploy to Vercel, ensure that you have done the following:
Copy the
vercel.json
file in the root of this template repo to the root of your documentation repo- This file contains some URL redirects from older MkDocs docs that we had at the company before we moved to Docusaurus. If your documentation did not pre-exist in MkDocs, then you can remove these fields.
cautionPlease ensure the
cleanUrls
is set to true and specified in thevercel.json
. This is necessary to make sure that Vercel deploys the app properly without expecting trailing slashes.Determine the public URL that you want to use to expose the docs site. It is common practice for the URL to follow the format of
https://docs.<YOUR_PRODUCT>.consensys.net
; however, that may be different depending on your needs.Join the #documentation Slack channel and ask for Vercel integration for your repo. Make sure to provide a link to your repo in your message.
Once integration has occurred, any new PRs should have a Vercel bot update with a preview link on all new commits to that PR.
See example Github comment
Scenario B: Private GitHub repo​
- Join the #documentation Slack channel and ask for Vercel integration for your private repo. Make sure to provide a link to your repo in your message.
- Your
build.yml
file under.github/workflows
will be modified to look like below (you do not need to take this action yourself). Essentially, we will bypass the Vercel limitation by having GitHub Actions build and push the static build directly to Vercel. The Action will also take care of commenting the preview URLs in the PR on new commits.
Updated build.yml
---
name: Build and Preview
on:
pull_request:
branches:
- main
push:
branches:
- main
jobs:
build:
name: Build
runs-on: ubuntu-latest
# the environment to deploy to / use secrets from
environment: vercel
# modify the default permissions of the GITHUB_TOKEN, so as to only allow least privileges
permissions:
contents: read
pull-requests: write
steps:
- uses: actions/checkout@v3
- name: Build
uses: ConsenSys/docs-gha/build@main
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- run: cp vercel.json ./build
- uses: amondnet/vercel-action@v25.1.1
id: vercel-action-staging
if: github.event_name == 'pull_request'
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
vercel-token: ${{ secrets.VERCEL_TOKEN }}
vercel-org-id: ${{ secrets.ORG_ID }}
vercel-project-id: ${{ secrets.PROJECT_ID }}
working-directory: ./build
scope: infura-web
- uses: amondnet/vercel-action@v25.1.1
id: vercel-action-production
if: github.event_name == 'push'
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
vercel-token: ${{ secrets.VERCEL_TOKEN }}
vercel-org-id: ${{ secrets.ORG_ID }}
vercel-project-id: ${{ secrets.PROJECT_ID }}
working-directory: ./build
vercel-args: "--prod "
scope: infura-web
github-comment: false
Example Action comment in PR
Setting up private repos with Vercel (for documentation team only)
Install the Vercel CLI
Run
vercel login
. Make sure you login with an account that is part of theInfura Web
team accountRun
vercel link
in the root directory of your Docusaurus project- Make sure to link to the
Infura Web
account and not your personal one - If you previously created the project in the account already you can link to the existing one, otherwise create a new one
- Make sure to link to the
After completing the prompts, you should see a
.vercel
folder that includes a JSON file withProject ID
andOrg ID
Login to the Vercel Dashboard and navigate to tokens
Create a new token with the scope selected to
Infura Web
and expiration set tonever
. Make sure to copy this somewhere securely (preferably 1Password) as this token will never be shown again. If you lose it, it will need to be deleted and regenerated. There is also a security concern, as these tokens have access to the entireInfura Web
accountNavigate to your environments setting in GitHub:
https://github.com/ConsenSys/<DOC_REPO>/settings/environments
. Replace<DOC_REPO>
with your repo nameCreate a new environment titled
vercel
.Add three new environment secrets to the
vercel
environmentORG_ID
:orgId
in theproject.json
in.vercel
folderPROJECT_ID
:projectId
in theproject.json
in.vercel
folderVERCEL_TOKEN
: token generated from step 5-6 above
Copy the modified
build.yml
file above and put it into the.github/workflows
folderNavigate to your project settings on the Vercel Dashboard and change the
Build & Development Settings
underGeneral
forFramework Preset
toOther
and toggle theOverride
forBuild Command
and leave it empty. Make sure to save. See below for example.Any new PR or push to
main
should automatically trigger the Action to build within GitHub and then have the artifacts pushed to Vercel directly.Make sure to edit the actions if there is something different about the docs repo (e.g. the main branch is called
master
instead ofmain
)