Skip to content

Codeware multi stack and architecture playground

License

Notifications You must be signed in to change notification settings

codeware-sthlm/codeware

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation


codeware sthlm logo

Codeware Playground

A playground for multi stack and architecture powered by Codeware Sthlm.

MIT

Contents

Packages

Nx Plugins

Add support for Payload in your existing Nx workspace.

npx add @cdwr/nx-payload

Quickly create a new Nx workspace with a Payload application, using the plugin as a preset.

npx create-nx-payload

GitHub Actions

GitHub action that analyzes the environment to deploy to based on the event details.

GitHub action that brings automatic Fly.io deployments to your Nx workspace.

GitHub action that brings automatic Nx migrations to your workspace.

Node Libraries

Fly CLI node wrapper for programmatic deployments to Fly.io.

Utilities

A set of core utilities for the Codeware ecosystem.

Startup Payload multi-tenant in dev mode

The Payload suite consists of

  • Payload Admin UI (cms)
  • Web Client (web)
  • Docker Postgres Database
  • Nginx Reverse Proxy to simulate multi-tenancy

Important

For a better DX you should not connect to Infisical in dev mode, since the development seed has much more data.

Make sure the credentials in the .env.local file are not set.

Terminal 1: Start Postgres and admin UI

Start Postgres in Docker

nx dx:postgres cms

Serve admin UI

nx serve cms

Note

Database is auto-seeded with static data when the admin UI is started.

Optional

Clear database and run migrations
nx payload cms migrate:fresh
Generate seed data

Seed data is stored in environment-specific TypeScript files in

  • libs/shared/util/seed/src/lib/static-data.

You can remove the existing seed data and keep just an empty object to force the generation of new seed data.

nx seed cms

Terminal 2: Start web client

Note

Live-reload is not fully operational.

nx start web

Terminal 3: Start reverse proxy to simulate multi-tenancy

nx payload-proxy:up

Note

You can now access the different web sites as different tenants:

🌐 cms.localhost

πŸ™Ž system@local.dev @ dev

Optional

Stop the proxy
nx payload-proxy:down
Communicate with the proxy
nx payload-proxy [docker compose options]

Development Tools & Services

Infisical Secrets Management

The Infisical secret management tool is used to manage secrets for the Codeware ecosystem.

  1. Install Infisical CLI

  2. Login to access the secrets

    infisical login
  3. List the development secrets

    # all secrets
    infisical secrets --recursive
    
    # cms application (all secrets and some by tag)
    infisical secrets --recursive --path /cms
    infisical secrets --tag cms
    
    # web application (all secrets and some by tag)
    infisical secrets --recursive --path /web
    infisical secrets --tag web
    
    # 'demo' tenant using web application
    infisical secrets --path /web/tenants/demo

Using the secrets

Add Infisical creadentials to you local environment.

apps/cms/.env.local

# Alt 1: Client credentials
INFISICAL_CLIENT_ID=
INFISICAL_CLIENT_SECRET=

# Alt 2: Service token
INFISICAL_SERVICE_TOKEN=

Note

Secrets can also be injected into process.env for any command, but this is not how we normally do it.

infisical run --path [path] -- [command]

Fly.io Deployment

The Fly.io platform is used to host the deployed applications and the required services.

Deployments are automatic on push events, detected by the nx-fly-deployment-action.

Still it's highly recommended to have the Fly CLI installed locally.

  1. Install Fly CLI

  2. Login to your Fly account

    fly auth login
  3. List the applications (for example)

    fly apps list

Database setup for preview deployments

Applications affected by a pull request are deployed to a temporary preview environment. To handle the dynamic nature of preview deployments, a Fly Postgres cluster pg-preview is used to store the temporary databases.

Applications deployed to preview will be automatically attached to the Postgres cluster, and detached when the pull request is closed.

Note

Some commands for reference and knowledge:

# Create a Postgres development cluster
fly pg create --name pg-preview --org codeware --region arn --vm-size shared-cpu-1x --volume-size 1 --initial-cluster-size 2

# Detach application from the Postgres cluster
fly pg detach pg-preview -a cdwr_cms_pr_{pr-number}

# Delete application
fly apps destroy cdwr_cms_pr_{pr-number}

# List all Postgres databases
fly pg db list -a pg-preview

# Cleanup dangling database and user
sh scripts/cleanup-db.sh cdwr_cms_pr_{pr-number} {cluster-password}
Connect to the database on local machine

Forward server port 5432 to local port 5433 to avoid conflicts with local Postgres running in Docker.

fly proxy 5433:5432 -a pg-preview

Connect with the following connection string:

postgres://postgres:<password>@localhost:5433

Release Management

The release process is semi-automatic which means:

  • Releases are generated from a local machine by a developer
  • GitHub action trigger on the tags and publish to NPM

Simply run the following command to start the release process:

nx release-cli