Build backend inside docker multi-stage build

This commit is contained in:
Hubert Van De Walle 2020-05-07 18:30:34 +02:00
parent cda9bf6006
commit e8209143d9
5 changed files with 15 additions and 37 deletions

View File

@ -1,10 +0,0 @@
api_doc_output=public/index.html
api_blueprint_src=api-doc/api.apib
aglio_template=triple
aglio_theme=cyborg
# API doc
gen-api-doc:
aglio -i $(api_blueprint_src) -o $(api_doc_output)\
--theme-template=$(aglio_template) \
--theme-variables=$(aglio_theme)

View File

@ -1,3 +1,17 @@
FROM maven:3.6.3-jdk-13 as builder
WORKDIR /tmp
# Cache dependencies
COPY pom.xml .
RUN mvn verify clean --fail-never
COPY resources resources
COPY src src
COPY test test
RUN mvn package
FROM openjdk:13-alpine
ENV APPLICATION_USER ktor
@ -8,7 +22,7 @@ RUN chown -R $APPLICATION_USER /app
USER $APPLICATION_USER
COPY ./target/api-0.0.1-jar-with-dependencies.jar /app/notes-api.jar
COPY --from=builder /tmp/target/api-*-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

@ -1,20 +0,0 @@
#!/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
docker-compose -f docker-compose.yml -f docker-compose.prod.yml stop nginx
# Generate Nuxt.js static website
pushd frontend || exit 1
yarn run generate
popd || exit 1
docker-compose -f docker-compose.yml -f docker-compose.prod.yml up -d --build nginx

View File

@ -8,16 +8,10 @@ check_installed() {
}
check_installed docker-compose
check_installed yarn
check_installed mvn
docker-compose -f docker-compose.yml -f docker-compose.prod.yml 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