Skip to content

grrrisu/thundermoon-umbrella

Repository files navigation

Stop the War in Ukraine

Build Status

Codacy Badge

Thundermoon.Umbrella

Sim.Realm Diagram

image: Thunderbird Moon by Joe Wilson-Sxwaset

This is a collection of examples using phoenix live view. The state is hold in memory and broadcasted to all clients. The examples include a simple chat, a counter, Conways Game of Life and Lotka-Volterra.

Changelog

Umbrella Apps

Docker

to start the application in a docker container

first copy and rename the files in .env_files to app and db.

set the corresponding values in those files and then run:

docker build -t thundermoon:build .
docker build -t thundermoon:app --target=app -f .semaphore/Dockerfile_release .
IMAGE=thundermoon:app docker-compose up

stop application

docker-compose down

Developement

Setup

To start the application

  • Copy config/dev.secret.example.exs to config/dev.secret.exs and replace ueberauth client_id and client_secret with your Github App credentials
  • Install dependencies with mix deps.get
  • Create and migrate your database with mix do ecto.create, ecto.migrate
  • Install Node.js dependencies with cd apps/thundermoon_apps/assets && npm install
  • Start Phoenix endpoint with mix phx.server

Now you can visit localhost:4000 from your browser.

Migration

to create a migration issue the command in app/thundermoon directory and specify the repo

mix ecto.gen.migration create_user -r Thundermoon.Repo

New Sub Application

go to ./appsand issue the mix new command like this: mix new lotka_volterra --module LotkaVolterra --sup

copy the new mix.exs file to the docker container in the Dockerfile line 15 (section install dependencies)

Testing

Cypress

Install

npm install -g cypress@4.5.0

MIX_ENV=integration mix do ecto.create, ecto.migrate, run apps/thundermoon/priv/repo/seeds.exs
Run

run the application

MIX_ENV=integration mix phx.server

start the cypress Test Runner in app/thundermoon_web/assets

npm run cypress

start testing ....

Docker

Run cypress with docker

docker build -t thundermoon:build . docker build -t thundermoon:integration -f .semaphore/Dockerfile_integration .

IMAGE="thundermoon:integration" docker-compose -f .semaphore/docker-compose.integration.yml up --abort-on-container-exit --exit-code-from browser

Release

manually a test release can be built

MIX_ENV=prod mix esbuild default --minify
MIX_ENV=prod mix phx.digest
MIX_ENV=prod mix release

export SECRET_KEY_BASE=REALLY_LONG_SECRET
export DATABASE_URL=ecto://<user>:<password>@localhost/thundermoon_dev

_build/dev/rel/thundermoon_umbrella/bin/thundermoon_umbrella eval "Thundermoon.Release.migrate"
_build/prod/rel/thundermoon_umbrella/bin/thundermoon_umbrella start

Production

stop docker stack

docker stack rm thundermoon

restart docker swarm

TAG=<container_tag> deploy.sh

Debug

ssh into production server, then

docker ps
docker exec -it <container-id> sh
./bin/thundermoon_umbrella remote
:observer_cli.start()

Send Test Error

SENTRY_DSN=https://12345@sentry.io/123 MIX_ENV=prod mix sentry.send_test_event

Semaphore

set dockerhub credentials as semaphore secrets

sem create secret dockerhub-secrets \
  -e DOCKER_USERNAME=<your-dockerhub-username> \
  -e DOCKER_PASSWORD=<your-dockerhub-password>

set app specific credentials

sem create secret thundermoon-secrets \
  -e DB_PASSWORD=<password> \
  -e SECRET_KEY_BASE=<secret> \
  -e SECRET_LIVE_VIEW_KEY=<secret> \
  -e SENTRY_DSN=<secret> \
  -e GITHUB_CLIENT_ID=<secret> \
  -e GITHUB_CLIENT_SECRET=<secret>

add deploy-key containing the private key to the secrets and add the pub key to the deploy server

sem create secret deploy-key -f ~/.ssh/id_rsa_semaphoreci:/home/semaphore/.keys/deploy-key