Skip to content

Commit

Permalink
Added docker compose file
Browse files Browse the repository at this point in the history
  • Loading branch information
amir-shiati committed Feb 28, 2022
1 parent 2e5880a commit f5d3a6c
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 3 deletions.
32 changes: 32 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#Webservice port
API_LOCAL_PORT=8080
API_DOCKER_PORT=8080

#Postgres port
POSTGRES_LOCAL_PORT=5432
POSTGRES_DOCKER_PORT=5432

#Database name (change this!)
DATABASE_NAME=wheremoneydb
#Database user (change this!)
DATABASE_USER=admin
#Database user password (change this!)
DATABASE_PASSWORD=adminpass
DATABASE_USE_SSL=false

#Deafult webservice admin username (change this!)
DEFAULT_ADMIN_USERNAME=admin
#Deafult webservice admin password (CHANGE THIS!)
DEFAULT_ADMIN_PASSWORD=changeme

#Deafult JWT secret key (CHANGE THIS!)
DEFAULT_JWT_SECRET_KEY=6jjzadtjrhbuwld8weh2fp2kn8eh
#How long each generated token is valid.
DEFAULT_JWT_VALIDITY_IN_MS=3600000

#Maximum allowed fail login attempts.
SESSION_MAX_LOGIN_ATTEMPTS=5
#How long a user will be banned after failing to login to their account more times than allowed.
SESSION_BAN_FOR_IN_HOURS=48


9 changes: 9 additions & 0 deletions db/01-init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash
set -e
export PGPASSWORD=$POSTGRES_PASSWORD;
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
CREATE USER $POSTGRES_DB_USER WITH PASSWORD '$POSTGRES_DB_PASSWORD';
CREATE DATABASE $POSTGRES_DB_NAME;
GRANT ALL PRIVILEGES ON DATABASE $POSTGRES_DB_NAME TO $POSTGRES_DB_USER;
EOSQL
40 changes: 40 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
version: '3.1'
services:
app-api:
image: 'where-money-api'
build: .
ports:
- "${API_LOCAL_PORT}:${API_DOCKER_PORT}"
depends_on:
- app-db

environment:
SPRING_APPLICATION_JSON: '{
"datasource.jdbc-url" : "jdbc:postgresql://app-db:$POSTGRES_DOCKER_PORT/$DATABASE_NAME?useSSL=$DATABASE_USE_SSL",
"datasource.username" : "$DATABASE_USER",
"datasource.password" : "$DATABASE_PASSWORD",
"spring.jpa.properties.hibernate.dialect" : "org.hibernate.dialect.PostgreSQLDialect",
"spring.jpa.hibernate.ddl-auto" : "update",
"security.jwt.username" : "$DEFAULT_ADMIN_USERNAME",
"security.jwt.password" : "$DEFAULT_ADMIN_PASSWORD",
"security.jwt.secret-key" : "$DEFAULT_JWT_SECRET_KEY",
"security.jwt.validity-in-ms" : "$DEFAULT_JWT_VALIDITY_IN_MS",
"session.ban-for-in-hours" : "$SESSION_BAN_FOR_IN_HOURS",
"session.max-login-attempts" : "$SESSION_MAX_LOGIN_ATTEMPTS"
}'

app-db:
image: postgres:latest
ports:
- "${POSTGRES_LOCAL_PORT}:${POSTGRES_DOCKER_PORT}"
env_file: ./.env
expose:
- $POSTGRES_DOCKER_PORT
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=admin
- POSTGRES_DB_PASSWORD=$DATABASE_PASSWORD
- POSTGRES_DB_USER=$DATABASE_USER
- POSTGRES_DB_NAME=$DATABASE_NAME
volumes:
- ./db:/docker-entrypoint-initdb.d/
6 changes: 3 additions & 3 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
datasource:
jdbc-url: jdbc:postgresql://localhost:5432/wheremoney
username: disqo
password: disqo@pass_123
jdbc-url: jdbc:postgresql://127.0.0.1:5434/wheremoneydb
username: admin
password: adminpass
pool-size: 30

spring:
Expand Down

0 comments on commit f5d3a6c

Please sign in to comment.