To test and run this locally you'll first need to:
- Install Go :-)
- Install Node.js and npm
- Install Docker
- Install client web app node modules
cd app
andnpm install
- Install end-to-end test runner
cd app-test
andnpm install
- Copy
default.env
toenv/local-dev/.env
(these environment variables are injected into containers and used in the apps when running locally) - Create an Auth0 tenant for the
local-dev
environment (See Auth0 Authentication section below) - Create another Auth0 tenant for the
local-test
environment if you wish
App will be public, but NOT protected with an SSL cert (which will break auth requests in chromium browsers)
- Install Terraform
- Setup AWS credentials on your local machine
- Create a hosted zone for your domain name with a staging subdomain in AWS Route53
- Create a key pair to connect to your EC2 instance in AWS EC2 under Network & Security -> Key Pairs
- Copy
default.secret.auto.tfvars
toenv/local-stage/.secret.auto.tfvars
(these are used when spinning up cloud infrastructure with terraform) - Create an Auth0 tenant for the staging environment and set the .secret.auto.tfvars appropriately
- Build/push the containers and spin up AWS infrastructure, will incur costs (
terraform destroy
to tear down)
cd ./services
docker build -t benjohns1/scheduled-tasks-services .
docker push benjohns1/scheduled-tasks-services
cd ../app
docker build -t benjohns1/scheduled-tasks-webapp .
docker push benjohns1/scheduled-tasks-webapp
cd ../env/aws-stage
terraform taint module.ecs.aws_ecs_task_definition.tasks
terraform apply
Sign-up and create an Auth0 tenant for each environment you want with the following:
- An API (e.g. 'Dev API') with the HS256 signing alg and a single permission of 'type:anon', then set the AUTH0_API_* env vars appropriately
- A machine to machine application (e.g. 'Dev Anon User') with 'type:anon' scoped access to your API, then set the AUTH0_ANON_CLIENT_* env vars
- A machine to machine application (e.g. 'Dev E2E Test User') with no scoped access to your API, then set the AUTH0_E2E_DEV_CLIENT_* env vars
- A single page application (e.g. 'Dev Web App') with Allowed Callback URLs, Allowed Web Origins, Allowed Logout URLs, and Allowed Origins (CORS) set to http://localhost:3000, then set the AUTH0_DOMAIN and AUTH0_WEBAPP_CLIENT_ID env vars
Setup local environments in one command (Windows only, for now)
- Development (hot reloading for the Sapper app and Cypress interactive test runner):
cd env/local-dev
andrun
- Test build (builds and creates container images for the web app and API):
cd env/local-test
andrun
- local-dev
- Web app: http://localhost:3000
- DB adminer: http://localhost:3001
- API server: http://localhost:3002
- local-test
- Web app: http://localhost:3100
- DB adminer: http://localhost:3101
- API server: http://localhost:3102
cd ./env/local-test
- Point to the test version of the env vars:
- on nix:
export ENV_FILEPATH=$PWD/.env
- -or- on windows:
set ENV_FILEPATH=%CD%\.env
- on nix:
- Build the app and container images:
docker-compose build
- Start the containers:
docker-compose up
- Tear it down:
docker-compose down
Run the app and services locally with a transient DB container
cd ./env/local-dev
- Point to the dev version of the env vars:
- on nix:
export ENV_FILEPATH=$PWD/.env
- -or- on windows:
set ENV_FILEPATH=%CD%\.env
- on nix:
- Start DBs:
docker-compose up
- Modify
./services
code, rebuild as-needed - Rebuild and run the services in
./services/cmd/srv
:- on nix:
go build && ./srv
- -or- on windows:
go build && srv
- on nix:
- Start the web app with hot reloading in
./app
with:npm run dev
- Open cypress for live testing in
./app-test
with:npm run cy:open
- Modify
./app
code - Tear down the DBs in
./env/local-dev
with:docker-compose down
- Run tests in
./services
with:go test ./...
Connects to DB containers for integration testing
- Start DBs in
./env/local-dev
with:docker-compose up
- Point to the test version of the env vars:
- on nix:
export ENV_FILEPATH=$PWD/.env
- -or- on windows:
set ENV_FILEPATH=%CD%\.env
- on nix:
- Run tests in
./services
with:go test ./... -tags='integration'
- Tear down the DBs in
./env/local-dev
with:docker-compose down
- Start DBs in
./env/local-dev
with:docker-compose up
- Build and run the API server & scheduler processes (in a new terminal) in
./services/cmd/srv
with:go build && ./srv
- Run the tests in
./app-test
with:npm test
- Tear down the DBs in
./env/local-dev
with:docker-compose down