diff --git a/README.md b/README.md index 0c04d35..e95e2ca 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,30 @@ # deployment Deploy all services with docker-compose + +## Usage + +### Proxy and tls +Set your email address in the docker compose to get let's encrypt tls certificates or delete that service and use your own nging configuration. In that case you can look at ./conf.d/nginx.conf to see the proxy configuration. + +### Postgres +The postgres db is initiated with the init-user.sh to create users for the user server and the api server. Change the passwords and/or user names. To that also in the docker compose. + +### Start the services +```bash +docker-compose up -d +``` + +### Verify +To see running containers do +```bash +docker container list +``` +To see logs of container do +```bash +docker logs +``` +To get a terminal for postgres +```bash +docker exec -it sh +psql -U fapi -d flotte_api +``` diff --git a/conf.d/nginx.conf b/conf.d/nginx.conf new file mode 100644 index 0000000..f68dcc3 --- /dev/null +++ b/conf.d/nginx.conf @@ -0,0 +1,19 @@ +server { + listen 443 ssl; + server_name SERVERNAME + ssl_certificate /etc/letsencrypt/live/flotte.duckdns.org/fullchain.pem; + ssl_certificate_key /etc/letsencrypt/live/flotte.duckdns.org/privkey.pem; + + location /user-management { + rewrite /user-management(.*)$ $1 break; + proxy_pass http://user-management:8080; + } + location = /graphql { + proxy_pass http://api-server:4000; + } + location / { + proxy_pass http://frontend:8080; + } + + +} diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..361583f --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,58 @@ +version: '2.0' +services: + db: + image: postgres:12.4-alpine + ports: + - "8001:5432" + volumes: + - database-volume:/var/lib/postgresql/data + - ./init-users.sh:/docker-entrypoint-initdb.d/init-users.sh + environment: + - POSTGRES_PASSWORD=password + user-management: + image: flotte-docker-registry.spdns.org/flotte-user-managment + ports: + - "5000:5000" + - "8080:8080" + links: + - "db:database" + environment: + - POSTGRES_CONNECTION_URL=postgres://fuser_management:passwordofuserserver@database/user_management + - RUST_LOG=trace + - HTTP_SERVER_ADDRESS=0.0.0.0:8080 + - RPC_SERVER_ADDRESS=0.0.0.0:5000 + - ENABLE_CORS=true + api-server: + image: flotte-docker-registry.spdns.org/apollo-server + ports: + - "4000:4000" + links: + - "db:database" + - "user-management:um" + environment: + - RPC_HOST=um:5000 + - POSTGRES_CONNECTION_URL=postgres://fapi:passwordofapiserver@database/flotte_api + - NODE_ENV=nodevelop + frontend: + image: flotte-docker-registry.spdns.org/frontend-server + ports: + - "8081:8080" + proxy: + image: staticfloat/nginx-certbot + links: + - "frontend:frontend" + - "api-server:api-server" + - "api-server2:api-server2" + - "user-management:user-management" + restart: always + environment: + CERTBOT_EMAIL: "youremail@example.de" + ports: + - "80:80" + - "443:443" + volumes: + - ./conf.d:/etc/nginx/user.conf.d:ro + - letsencrypt:/etc/letsencrypt +volumes: + database-volume: {} + letsencrypt: diff --git a/init-users.sh b/init-users.sh new file mode 100644 index 0000000..e35fdad --- /dev/null +++ b/init-users.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +set -e + +psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL + CREATE USER fuser_management WITH PASSWORD 'passwordofuserserver'; + CREATE DATABASE user_management; + GRANT ALL PRIVILEGES ON DATABASE user_management TO fuser_management; + + CREATE USER fapi WITH PASSWORD 'passwordofapiserver'; + CREATE DATABASE flotte_api; + GRANT ALL PRIVILEGES ON DATABASE flotte_api TO fapi; +EOSQL