Merge branch 'feature/docker'

This commit is contained in:
Hubert Van De Walle 2020-04-30 15:39:17 +02:00
commit 6b8c5d11ae
10 changed files with 160 additions and 17 deletions

5
.env.dist Normal file
View File

@ -0,0 +1,5 @@
MYSQL_ROOT_PASSWORD=
MYSQL_DATABASE=
MYSQL_USER=
MYSQL_PASSWORD=
JWT_SECRET=

14
api/Dockerfile Normal file
View File

@ -0,0 +1,14 @@
FROM openjdk:13-alpine
ENV APPLICATION_USER ktor
RUN adduser -D -g '' $APPLICATION_USER
RUN mkdir /app
RUN chown -R $APPLICATION_USER /app
USER $APPLICATION_USER
COPY ./target/api-0.0.1-jar-with-dependencies.jar /app/notes-api.jar
WORKDIR /app
CMD ["java", "-server", "-XX:+UnlockExperimentalVMOptions", "-XX:InitialRAMFraction=2", "-XX:MinRAMFraction=2", "-XX:MaxRAMFraction=2", "-XX:+UseG1GC", "-XX:MaxGCPauseMillis=100", "-XX:+UseStringDeduplication", "-jar", "notes-api.jar"]

View File

@ -24,7 +24,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<kotlin.compiler.incremental>true</kotlin.compiler.incremental>
<kotlin.compiler.jvmTarget>12</kotlin.compiler.jvmTarget>
<main.class>io.ktor.server.netty.EngineMain</main.class>
<main.class>be.vandewalleh.NotesApplicationKt</main.class>
<java.version>13</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
@ -150,11 +150,6 @@
<artifactId>HikariCP</artifactId>
<version>3.4.2</version>
</dependency>
<dependency>
<groupId>com.sksamuel.hoplite</groupId>
<artifactId>hoplite-core</artifactId>
<version>${hoplite_version}</version>
</dependency>
<dependency>
<groupId>com.sksamuel.hoplite</groupId>
<artifactId>hoplite-yaml</artifactId>

View File

@ -1,18 +1,18 @@
env: staging
database:
host: 127.0.0.1
host: ${MYSQL_HOST}
port: 3306
name: Notes
username: test
password: test
name: ${MYSQL_DATABASE}
username: ${MYSQL_USER}
password: ${MYSQL_PASSWORD}
server:
host: 0.0.0.0
port: 8081
jwt:
secret: ${random.string(25)}
secret: ${JWT_SECRET}
auth:
validity: 1
unit: HOURS

View File

@ -19,6 +19,7 @@ import org.kodein.di.generic.singleton
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import javax.sql.DataSource
import kotlin.system.exitProcess
val kodein = Kodein {
import(serviceModule)

26
deploy.sh Executable file
View File

@ -0,0 +1,26 @@
#!/bin/bash
check_installed() {
if ! [ -x "$(command -v $1)" ]; then
echo "Error: $1 is not installed." >&2
exit 1
fi
}
check_installed docker-compose
check_installed yarn
check_installed mvn
docker-compose down
# Generate Nuxt.js static website
pushd frontend || exit 1
yarn run generate
popd || exit 1
# Generate fat jar
pushd api || exit 1
mvn clean package
popd || exit 1
docker-compose up -d --build

View File

@ -1,18 +1,59 @@
version: '3'
version: '2.2'
services:
nginx:
image: nginx:latest
container_name: notes-nginx
environment:
- PUID=1000
- PGID=1000
- TZ=Europe/Brussels
volumes:
- ./frontend/dist:/usr/share/nginx/html
- ./nginx/nginx.conf:/etc/nginx/nginx.conf
- ./nginx/server.conf:/etc/nginx/server.conf
ports:
- 80:80
- 443:443
depends_on:
- api
db:
image: mariadb
container_name: notes-mariadb
env_file:
- .env
environment:
- PUID=1000
- PGID=1000
- MYSQL_ROOT_PASSWORD=test
- TZ=Europe/Brussels
- MYSQL_DATABASE=Notes
- MYSQL_USER=test
- MYSQL_PASSWORD=test
ports:
# This is only for testing
- 3306:3306
volumes:
- notes-db-volume:/var/lib/mysql
healthcheck:
test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"]
timeout: 10s
retries: 10
api:
build: ./api
container_name: notes-api
ports:
# This is only for testing
- 8081:8081
env_file:
- .env
environment:
- TZ=Europe/Brussels
- MYSQL_HOST=db
depends_on:
db:
condition: service_healthy
volumes:
notes-db-volume:

View File

@ -3,5 +3,5 @@ export default function ({ $axios }) {
console.log('Making request to ' + config.url)
})
$axios.setBaseURL('http://localhost:8081')
$axios.setBaseURL(process.env.API_URL)
}

33
nginx/nginx.conf Normal file
View File

@ -0,0 +1,33 @@
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/server.conf;
}

28
nginx/server.conf Normal file
View File

@ -0,0 +1,28 @@
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location /api/ {
rewrite ^/api/(.*) /$1 break;
proxy_pass http://api:8081/;
}
}