-
Notifications
You must be signed in to change notification settings - Fork 6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[docker] Update root Dockerfile and run-in-docker
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
1 parent
fe66364
commit 4367311
Showing
3 changed files
with
46 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 "$@" |