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.
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
To start the application
- Copy
config/dev.secret.example.exs
toconfig/dev.secret.exs
and replace ueberauthclient_id
andclient_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.
to create a migration issue the command in app/thundermoon
directory and specify the repo
mix ecto.gen.migration create_user -r Thundermoon.Repo
go to ./apps
and 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)
npm install -g cypress@4.5.0
MIX_ENV=integration mix do ecto.create, ecto.migrate, run apps/thundermoon/priv/repo/seeds.exs
run the application
MIX_ENV=integration mix phx.server
start the cypress Test Runner in app/thundermoon_web/assets
npm run cypress
start testing ....
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
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
stop docker stack
docker stack rm thundermoon
restart docker swarm
TAG=<container_tag> deploy.sh
show all services
docker service ls
see details of one service
docker service ps --no-trunc thundermoon_app
ssh into production server, then
docker ps
docker exec -it <container-id> sh
./bin/thundermoon_umbrella remote
:observer_cli.start()
SENTRY_DSN=https://12345@sentry.io/123 MIX_ENV=prod mix sentry.send_test_event
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> \
-e SSH_USER_AT_HOST=<deploy_user@ip_address>
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