Skip to content

Commit

Permalink
feat: created docker-compose
Browse files Browse the repository at this point in the history
  • Loading branch information
Ioann Kurchin committed Apr 6, 2022
1 parent 2e86536 commit e33b1a2
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 3 deletions.
10 changes: 10 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
COFFEE_CONTAINER_PATH=/random_coffee/app
COFFEE_CONTAINER_NAME=random_coffee
COFFEE_CONTAINER_LOGS=/random_coffee/app/logs
COFFEE_CONTAINER_PORT=8080
COFFEE_DB_HOST=172.17.0.1
COFFEE_DB_PASSWORD=postgres
COFFEE_DB_PORT_NUMBER=5432
COFFEE_DB_NAME=coffee_db
COFFEE_DB_USER=postgres
COFFEE_DB_CONTAINER_NAME=coffee_postgres
10 changes: 10 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
COFFEE_CONTAINER_PATH=/random_coffee/app
COFFEE_CONTAINER_NAME=random_coffee
COFFEE_CONTAINER_LOGS=/random_coffee/app/logs
COFFEE_CONTAINER_PORT=8080
COFFEE_DB_HOST=postgres
COFFEE_DB_PORT_NUMBER=5432
COFFEE_DB_NAME=coffee_postgres_db
COFFEE_DB_USER=postgres
COFFEE_DB_PASSWORD=postgres
COFFEE_DB_CONTAINER_NAME=coffee_postgres
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ To run the application, use the following command:
sbt bootstrap/run
```

## Running with docker compose
To run the application in docker, start by building application's docker image with:
```
sbt clean docker:publishLocal
```
After image is created, run:
```
docker compose up / docker compose up -d (if you wan't compose to run in detached mode)
```

### Running Unit Tests Locally
Use the command below to run unit tests:
```
Expand Down
4 changes: 4 additions & 0 deletions bootstrap/docker.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Docker / defaultLinuxInstallLocation := sys.env.getOrElse("COFFEE_CONTAINER_PATH", "/random_coffee/app")
Docker / packageName := sys.env.getOrElse("COFFEE_CONTAINER_NAME", "random_coffee")
dockerExposedVolumes := Seq(sys.env.getOrElse("COFFEE_CONTAINER_LOGS", "/random_coffee/app/logs"))
dockerExposedPorts := Seq(sys.env.getOrElse("COFFEE_CONTAINER_PORT", "8080").toInt)
6 changes: 3 additions & 3 deletions bootstrap/src/main/resources/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ authentication {

db {
driver = "org.postgresql.Driver"
url = "jdbc:postgresql://localhost:5432/random_coffee?currentSchema=authentication"
url = "jdbc:postgresql://"${RANDOM_COFFEE_DB_SERVER_NAME}":5432/coffee_db?currentSchema=authentication"
user = "postgres"
user = ${?AUTH_DB_USER}
user = "postgres"
password = "postgres"
password = "postgres"
password = ${?AUTH_DB_PASSWORD}
}

liquibase {
Expand Down
1 change: 1 addition & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ lazy val bootstrap = project
commonSettings,
Compile / mainClass := Some("com.epam.random_coffee.RandomCoffeeApp")
)
.enablePlugins(JavaAppPackaging, DockerPlugin)
.aggregate(`auth-service`, `rc-events-service`)
.dependsOn(`auth-service`, `rc-events-service`)

Expand Down
41 changes: 41 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
version: '3'
services:
postgres:
image: "postgres"
container_name: ${COFFEE_DB_CONTAINER_NAME}
environment:
POSTGRES_USER: ${COFFEE_DB_USER}
POSTGRES_PASSWORD: ${COFFEE_DB_PASSWORD}
POSTGRES_DB: ${COFFEE_DB_NAME}
PG_DATA: /var/lib/postgresql/data/pgdata
ports:
- "${COFFEE_DB_PORT_NUMBER}:5432"
volumes:
- ./init_db.sh:/docker-entrypoint-initdb.d/init_db.sh
restart: always
healthcheck:
test: pg_isready -U ${COFFEE_DB_USER} -d ${COFFEE_DB_NAME}
interval: 10s
timeout: 5s
retries: 3
deploy:
resources:
limits:
cpus: '1'
memory: 4G

random_coffee:
image: "random_coffee:0.0.1"
depends_on:
- postgres
environment:
RANDOM_COFFEE_CONTAINER_PATH: ${COFFEE_CONTAINER_PATH}
RANDOM_COFFEE_CONTAINER_NAME: ${COFFEE_CONTAINER_NAME}
RANDOM_COFFEE_CONTAINER_LOGS: ${COFFEE_CONTAINER_LOGS}
RANDOM_COFFEE_DB_SERVER_NAME: ${COFFEE_DB_HOST}
RANDOM_COFFEE_DB_PORT_NUMBER: ${COFFEE_DB_PORT_NUMBER}
RANDOM_COFFEE_DB_NAME: ${COFFEE_DB_NAME}
RANDOM_COFFEE_DB_USER: ${COFFEE_DB_USER}
RANDOM_COFFEE_DB_PASSWORD: ${COFFEE_DB_PASSWORD}
ports:
- "${COFFEE_CONTAINER_PORT}:8080"
7 changes: 7 additions & 0 deletions init_db.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash
set -e
psql -v ON_ERROR_STOP=1 --username "postgres" --dbname "coffee_db" <<-EOSQL
BEGIN;
CREATE SCHEMA authentication;
COMMIT;
EOSQL
1 change: 1 addition & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.6")
addSbtPlugin("com.github.sbt" % "sbt-native-packager" % "1.9.4")

0 comments on commit e33b1a2

Please sign in to comment.