Deployment
Potionx includes a deployment
folder which contains the recipe for a Pulumi deployment to Digital Ocean's Kubernetes service. Recipes for the other major Kubernetes platforms are planned and the current recipe can be easily adapted to other providers.
The recipe is deployed and created updated on every push to Github.
Architecture
The recipe generates the following cloud architecture:
A non-highly available PostgreSQL setup is used by default, but can easily be swapped out for a HA setup in deployment/index.ts
.
Prerequisites
The following prerequisites are required:
Cloudflare
- Sign up/in to Cloudflare
- Add a domain that you already own (we recommend DNSimple or Hover if you need to purchase one)
- If your subdomain will be
www
, remove thewww
type from the DNS management table - Copy the
Custom Nameserves
to your domain provider undercustom DNS
- Navigate to https://dash.cloudflare.com/profile/api-tokens
- Create a token that has
Edit zone DNS
permissions - Save the token somewhere, you'll need it later
Digital Ocean
- Sign up/in to DigitalOcean (You'll need a credit card)
- Create a token with read/write scope here: https://cloud.digitalocean.com/account/api/tokens
- Save the token somewhere, you'll need it later
Github
- Sign up/in to Github
- Set up a repository to push your code to
- Grab a personal access token here with
read/write
permissions forpackages
: https://github.com/settings/tokens - Save the token somewhere, you'll need it later
- Navigate to your project's actions secrets settings page https://github.com/USERNAME-OR-ORG/PROJECT-NAME/settings/secrets/actions
- Create a new repository secret called
CR_PAT
- Add your token from step #5 to it
- Hover the account dropdown on the top right and select "feature preview"
- Enable
Improved container support
Pulumi
- Sign up/in to Pulumi
- Create a new project and select the Kubernetes + typescript options
- Install the Pulumi CLI
- Create a Pulumi access token
- Save the token somewhere, you'll need it later
- Back in Github, navigate to your project's actions secrets settings page https://github.com/USERNAME-OR-ORG/PROJECT-NAME/settings/secrets/actions
- Create a new repository secret called
PULUMI_TOKEN
and add your Pulumi secret token from step #4
Setting up your Pulumi config
- Navigate to your
deployment
folder and run the following commands:
Don't forget to change the commands with the appropriate information as marked, including the Digital Ocean and Cloudflare tokens
pulumi login # enter your access token from Pulumi step #4 when asked
pulumi stack # Create a new stack when asked in the format organization-name/stack, where organization-name is your username by default
pulumi config set domain YOUR-DOMAIN --secret # the domain you added to Cloudflare
pulumi config set subdomain YOUR-SUBDOMAIN --secret # www for example
pulumi config set cloudflare:apiToken YOUR-CLOUDFLARE-TOKEN --secret # from step 5 of the Cloudflare set up
pulumi config set digitalocean:token YOUR-DIGITALOCEAN-TOKEN --secret # from step 3 of the DigitalOcean set up
pulumi config set passwordDb A-STRONG-PASSWORD --secret # Choose a very strong password for your database user, mix phx.gen.secret can help
pulumi config set passwordRedis A-STRONG-PASSWORD --secret # Choose a very strong password for your Redis user, mix phx.gen.secret can help
pulumi config set secretKeyBase A-STRONG-PASSWORD --secret # Choose a very strong password for your Redis user, mix phx.gen.secret can help
pulumi config set --path "authProviders.azureAd.clientId" YOUR-AZURE-SOCIAL-LOGIN-CLIENT-ID --secret
pulumi config set --path "authProviders.azureAd.clientSecret" YOUR-AZURE-SOCIAL-LOGIN-CLIENT-SECRET --secret
pulumi config set --path "authProviders.google.clientId" YOUR-GOOGLE-SOCIAL-LOGIN-CLIENT-ID --secret
pulumi config set --path "authProviders.google.clientSecret" YOUR-GOOGLE-SOCIAL-LOGIN-CLIENT-SECRET --secret
- Then, back in Github, add a secret called
PULUMI_STACK
with the value of your Pulumi stack to https://github.com/USERNAME-OR-ORG/PROJECT-NAME/settings/secrets/actions.
Remember to add the right callback URLs to your authentication providers
Push your code to Github
Pushing your code to Github will run your tests, build a Docker image for your app and create your deplyoment. Subsequent pushes will update the app image used in your deployment.
Your first deploy may fail due to the certificate manager and certificate issuer being out of sync initially. Simply running the workflow in Github again or pushing again should solve the issue. The issue is detailed here: https://cert-manager.io/docs/concepts/webhook/#webhook-connection-problems-shortly-after-cert-manager-installation