Mutli-stage build for production

This commit is contained in:
prichier
2020-10-22 15:19:01 +02:00
parent e945f48665
commit 1acff2dd8a
8 changed files with 167 additions and 172 deletions

View File

@@ -2,49 +2,54 @@
You will need to :
- build the image
- adapte env file
- run docker-compose
- tune the environment file
- use docker-compose to run the service
## Build the image
docker build -t mymobilizon -f docker/prod/Dockerfile .
git clone https://forge.tedomum.net/tedomum/mobilizon
cd mobilizon
docker build -t mobilizon -f docker/production/Dockerfile .
## Adapt env file
## Update the env file
cp env .env
cd docker/production/
cp env.example .env
- Edit .env content with your params.
- Edit docker-compose file with your params (environment section for mobilizon & posgres).
Edit the `.env` content with your own settings.
You can generate `MOBILIZON_INSTANCE_SECRET_KEY_BASE` and `MOBILIZON_INSTANCE_SECRET_KEY` with:
gpg --gen-random --armor 1 50
## run docker-compose
## Run the service
docker-compose -f docker-compose-simple.yml up
# set user for volumes
sudo chown 999:999 db public wal public/upload
# in another shell
docker-compose -f docker-compose-simple.yml exec -u 0 mobilizon bash
su - mobilizon
# backup secret
mv config/prod.secret.exs config/prod.secret.exs.env
# run config generation
MIX_ENV=prod mix mobilizon.instance gen -f
# reply anything (not used after) except for :
# - What is the name of your database? [mobilizon_prod]
# - What is the user used to connect to your database? [mobilizon]
# - What is the password used to connect to your database? [autogenerated]
# get secret env based bak
mv config/prod.secret.exs.env config/prod.secret.exs
# run the db init script as root
exit
psql -U postgres -p 5432 -h postgres -f setup_db.psql
# delete db init sript
rm setup_db.psql
# create an admin with mobilizon user
su - mobilizon
cd /app
MIX_ENV=prod mix mobilizon.users.new pascoual@tedomum.fr --password mobilizon
# exit with ctrl+d (twice times)
Start by initializing and running the database:
docker-compose up -d db
Instanciate required Postgres extensions:
docker-compose exec db psql -U <username>
# CREATE EXTENSION pg_trgm;
# CREATE EXTENSION unaccent;
Then run migrations:
docker-compose run --rm mobilizon eval Mobilizon.Cli.migrate
Finally, run the application:
docker-compose up -d mobilizon
## Update the service
Pull the latest image, then run the migrations:
docker-compose pull mobilizon
docker-compose run --rm mobilizon eval Mobilizon.Cli.migrate
Finally, update the service:
docker-compose up -d mobilizon