Skip to content

Commit

Permalink
[docker] Update root Dockerfile and run-in-docker
Browse files Browse the repository at this point in the history
This update allows the root Dockerfile to be used as a development
container and updates run-in-docker.sh to use the same entrypoint script
while maintaining backward compatibility for anyone who has scripted
mappings to /gen and /root/.m2/repository.
  • Loading branch information
jimschubert committed May 25, 2016
1 parent fe66364 commit 4367311
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 34 deletions.
22 changes: 14 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
FROM jimschubert/8-jdk-alpine-mvn:1.0

ENV GEN_DIR /opt/swagger-codegen

RUN set -x && \
apk add --no-cache bash

RUN mkdir /opt

ADD . /opt/swagger-codegen
ADD . ${GEN_DIR}

VOLUME ${MAVEN_HOME}/.m2/repository

WORKDIR ${GEN_DIR}

WORKDIR /opt/swagger-codegen
RUN mvn -am -pl "modules/swagger-codegen-cli" package

RUN mvn -am -pl "modules/swagger-codegen-cli" package && \
mv /opt/swagger-codegen/modules/swagger-codegen-cli/target/swagger-codegen-cli.jar /opt/swagger-codegen/swagger-codegen-cli.jar && \
mvn clean && \
rm -rf ${MAVEN_HOME}/.m2/repository
COPY docker-entrypoint.sh /usr/local/bin/

ENTRYPOINT ["java", "-jar", "/opt/swagger-codegen/swagger-codegen-cli.jar"]
ENTRYPOINT ["docker-entrypoint.sh"]

CMD ["help"]
CMD ["build"]
24 changes: 24 additions & 0 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env bash

set -euo pipefail

# GEN_DIR allows to share the entrypoint between Dockerfile and run-in-docker.sh (backward compatible)
GEN_DIR=${GEN_DIR:-/opt/swagger-codegen}
JAVA_OPTS=${JAVA_OPTS:-"-Xmx1024M -DloggerPath=conf/log4j.properties"}

codegen="${GEN_DIR}/modules/swagger-codegen-cli/target/swagger-codegen-cli.jar"

case "$1" in
generate|help|langs|meta|config-help)
# If ${GEN_DIR} has been mapped elsewhere from default, and that location has not been built
if [[ ! -f "${codegen}" ]]; then
(cd ${GEN_DIR} && exec mvn -am -pl "modules/swagger-codegen-cli" package)
fi
command=$1
shift
exec java ${JAVA_OPTS} -jar ${codegen} ${command} "$@"
;;
*) # Any other commands, e.g. docker run imagename ls -la or docker run -it imagename /bin/bash
exec "$@"
;;
esac
34 changes: 8 additions & 26 deletions run-in-docker.sh
Original file line number Diff line number Diff line change
@@ -1,34 +1,16 @@
#!/bin/bash
set -e
cd "$(dirname $BASH_SOURCE)"
set -exo pipefail

maven_cache_repo="$HOME/.m2/repository"
myname="$(basename $BASH_SOURCE)"
cd "$(dirname ${BASH_SOURCE})"

if [ "$1" = "mvn" ]; then
cmd="$1"
shift
args="$@"
else
jar="modules/swagger-codegen-cli/target/swagger-codegen-cli.jar"

# Check if project is built
if [ ! -f "$jar" ]; then
echo "ERROR File not found: $jar"
echo "ERROR Did you forget to './$myname mvn package'?"
exit 1
fi

cmd="java -jar /gen/$jar"
args="$@"
fi
maven_cache_repo="${HOME}/.m2/repository"

mkdir -p "$maven_cache_repo"
mkdir -p "${maven_cache_repo}"

set -x

docker run -it \
docker run --rm -it \
-w /gen \
-e GEN_DIR=/gen \
-v "${PWD}:/gen" \
-v "${maven_cache_repo}:/root/.m2/repository" \
maven:3-jdk-7 $cmd $args
--entrypoint /gen/docker-entrypoint.sh \
maven:3-jdk-7 "$@"

0 comments on commit 4367311

Please sign in to comment.