Use docker to run application

This commit is contained in:
Eugene Zadyra
2018-06-04 23:47:38 +02:00
parent 6edf5a284b
commit 58bbe50a3a
8 changed files with 82 additions and 2 deletions

View File

@@ -5,6 +5,11 @@ ext {
scalaVersion = "2.12.6"
}
allprojects {
group = 'com.lbs'
version = '1.0.0-SNAPSHOT'
}
apply plugin: 'idea'
subprojects {

15
docker.sh Executable file
View File

@@ -0,0 +1,15 @@
#!/bin/bash
[ -z "$TELEGRAM_TOKEN" ] && echo "Need to set TELEGRAM_TOKEN env variable" && exit 1;
[ -z "$SECURITY_SECRET" ] && echo "Need to set SECURITY_SECRET env variable" && exit 1;
case "$1" in
run)
./gradlew makeDockerFile
docker-compose -f server/build/docker/docker-compose.yml up --build
;;
*)
echo "Run as $0 (run)"
exit 1
;;
esac

View File

@@ -1,3 +1,5 @@
import org.apache.tools.ant.filters.ReplaceTokens
buildscript {
ext {
springBootVersion = '2.0.2.RELEASE'
@@ -30,4 +32,23 @@ dependencies {
testCompile('com.typesafe.akka:akka-testkit_2.12:2.4.19')
}
task replaceTokens(type: Copy) {
def finalBuildName = project.name + '-' + project.version
from 'src/main/docker'
into 'build/docker'
filter(ReplaceTokens, tokens:
['project.build.finalName': finalBuildName,
"TELEGRAM_TOKEN" : System.getenv()['TELEGRAM_TOKEN'],
"SECURITY_SECRET" : System.getenv()['SECURITY_SECRET']
])
}
task copyJar(type: Copy) {
dependsOn assemble
from file("${project.buildDir}/libs")
into file("${project.buildDir}/docker")
}
task makeDockerFile(type: Copy, dependsOn: [replaceTokens, copyJar])

View File

@@ -0,0 +1,2 @@
TELEGRAM_TOKEN=@TELEGRAM_TOKEN@
SECURITY_SECRET=@SECURITY_SECRET@

View File

@@ -0,0 +1,8 @@
FROM openjdk:8-jdk-alpine
RUN apk update && apk upgrade && apk add netcat-openbsd
RUN mkdir -p /usr/local/luxmedbookingservice
ADD @project.build.finalName@.jar /usr/local/luxmedbookingservice/
ADD run.sh run.sh
RUN chmod +x run.sh
CMD ./run.sh

View File

@@ -0,0 +1,17 @@
version: '3'
services:
luxmedbookingservice:
build: .
environment:
TELEGRAM_TOKEN: ${TELEGRAM_TOKEN}
SECURITY_SECRET: ${SECURITY_SECRET}
volumes:
- ./log:/usr/local/luxmedbookingservice/log
database:
image: postgres:9.5
ports:
- "5432:5432"
environment:
- POSTGRES_USER=lbs
- POSTGRES_PASSWORD=lsb123
- POSTGRES_DB=lbs

View File

@@ -0,0 +1,12 @@
#!/bin/sh
echo "********************************************************"
echo "Waiting for the database server to start on port 5432"
echo "********************************************************"
while ! `nc -z database 5432`; do sleep 3; done
echo "******** Database Server has started "
echo "********************************************************"
echo "Starting Luxmed Booking Service "
echo "********************************************************"
cd /usr/local/luxmedbookingservice && java -jar @project.build.finalName@.jar

View File

@@ -1,6 +1,6 @@
spring:
datasource:
url: "jdbc:postgresql://127.0.0.1:5432/lbs"
url: "jdbc:postgresql://database:5432/lbs"
username: "lbs"
password: "lsb123"
jpa:
@@ -18,7 +18,7 @@ banner:
location: "classpath:/banner.txt"
logging:
file: logs/app.log
file: log/app.log
level:
com.lbs: DEBUG
# org.hibernate.SQL: DEBUG