Skip to content

Commit

Permalink
fixes #106 generate build.sh for easy docker build with version
Browse files Browse the repository at this point in the history
  • Loading branch information
stevehu committed Feb 19, 2018
1 parent 02f6c7a commit f832b9b
Show file tree
Hide file tree
Showing 11 changed files with 174 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,9 @@ public void generate(String targetPath, Object model, Any config) throws IOExcep
boolean enableHttps = config.toBoolean("enableHttps");
String httpsPort = config.toString("httpsPort");
boolean enableRegistry = config.toBoolean("enableRegistry");
boolean supportOracle = config.toBoolean("supportOracle");
boolean supportMysql = config.toBoolean("supportMysql");
boolean supportPostgresql = config.toBoolean("supportPostgresql");
boolean supportH2ForTest = config.toBoolean("supportH2ForTest");
boolean supportClient = config.toBoolean("supportClient");
String dockerOrganization = config.toString("dockerOrganization");
if(dockerOrganization == null || dockerOrganization.length() == 0) dockerOrganization = "networknt";

transfer(targetPath, "", "pom.xml", templates.graphql.pom.template(config));
// There is only one port that should be exposed in Dockerfile, otherwise, the service
Expand All @@ -58,6 +56,7 @@ public void generate(String targetPath, Object model, Any config) throws IOExcep
}
transfer(targetPath, "docker", "Dockerfile", templates.graphql.dockerfile.template(config, expose));
transfer(targetPath, "docker", "Dockerfile-Redhat", templates.graphql.dockerfileredhat.template(config, expose));
transfer(targetPath, "", "build.sh", templates.graphql.buildSh.template(dockerOrganization, config.get("groupId") + "." + config.get("artifactId") + "-" + config.get("version")));
transfer(targetPath, "", ".gitignore", templates.graphql.gitignore.template());
transfer(targetPath, "", "README.md", templates.graphql.README.template());
transfer(targetPath, "", "LICENSE", templates.graphql.LICENSE.template());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
@args (String org, String serviceId)
#!/bin/bash

set -ex

VERSION=$1
IMAGE_NAME="@org/@serviceId"

showHelp() {
echo " "
echo "Error: $1"
echo " "
echo " build.sh [VERSION]"
echo " "
echo " where [VERSION] version of the docker image that you want to publish (example: 0.0.1)"
echo " "
echo " example: ./build.sh 0.0.1"
echo " "
}

build() {
echo "Building ..."
mvn clean install
echo "Successfully built!"
}

cleanup() {
if [[ "$(docker images -q $IMAGE_NAME 2> /dev/null)" != "" ]]; then
echo "Removing old $IMAGE_NAME images"
docker images | grep $IMAGE_NAME | awk '{print $3}' | xargs docker rmi -f
echo "Cleanup completed!"
fi
}

publish() {
echo "Building Docker image with version $VERSION"
docker build -t $IMAGE_NAME:$VERSION -t $IMAGE_NAME:latest -f ./docker/Dockerfile . --no-cache=true
docker build -t $IMAGE_NAME:$VERSION-redhat -f ./docker/Dockerfile-Redhat . --no-cache=true
echo "Images built with version $VERSION"
echo "Pushing image to DockerHub"
docker push $IMAGE_NAME
echo "Image successfully published!"
}

if [ -z $VERSION ]; then
showHelp "[VERSION] parameter is missing"
exit
fi

build;
cleanup;
publish;
3 changes: 2 additions & 1 deletion light-graphql-4j/src/test/resources/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@
"password": "my-secret-pw"
},
"supportH2ForTest": false,
"supportClient": false
"supportClient": false,
"dockerOrganization": "networknt"
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,8 @@ public void generate(String targetPath, Object model, Any config) throws IOExcep
boolean enableHttps = config.toBoolean("enableHttps");
String httpsPort = config.toString("httpsPort");
boolean enableRegistry = config.toBoolean("enableRegistry");
boolean supportOracle = config.toBoolean("supportOracle");
boolean supportMysql = config.toBoolean("supportMysql");
boolean supportPostgresql = config.toBoolean("supportPostgresql");
boolean supportH2ForTest = config.toBoolean("supportH2ForTest");
String dockerOrganization = config.toString("dockerOrganization");
if(dockerOrganization == null || dockerOrganization.length() == 0) dockerOrganization = "networknt";

boolean supportClient = config.toBoolean("supportClient");

Expand All @@ -55,6 +53,7 @@ public void generate(String targetPath, Object model, Any config) throws IOExcep
}
transfer(targetPath, "docker", "Dockerfile", templates.hybrid.server.dockerfile.template(config, expose));
transfer(targetPath, "docker", "Dockerfile-Redhat", templates.hybrid.server.dockerfileredhat.template(config, expose));
transfer(targetPath, "", "build.sh", templates.hybrid.server.buildSh.template(dockerOrganization, config.get("groupId") + "." + config.get("artifactId") + "-" + config.get("version")));
transfer(targetPath, "", ".gitignore", templates.hybrid.gitignore.template());
transfer(targetPath, "", "README.md", templates.hybrid.server.README.template());
transfer(targetPath, "", "LICENSE", templates.hybrid.LICENSE.template());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,12 @@ public String getFramework() {
@Override
public void generate(String targetPath, Object model, Any config) throws IOException {
// whoever is calling this needs to make sure that model is converted to Map<String, Object>
String rootPackage = config.get("rootPackage").toString();
String modelPackage = config.get("modelPackage").toString();
String handlerPackage = config.get("handlerPackage").toString();
boolean overwriteHandler = config.toBoolean("overwriteHandler");
boolean overwriteHandlerTest = config.toBoolean("overwriteHandlerTest");
boolean enableHttp = config.toBoolean("enableHttp");
String httpPort = config.toString("httpPort");
boolean enableHttps = config.toBoolean("enableHttps");
String httpsPort = config.toString("httpsPort");
boolean enableRegistry = config.toBoolean("enableRegistry");
boolean supportOracle = config.toBoolean("supportOracle");
boolean supportMysql = config.toBoolean("supportMysql");
boolean supportPostgresql = config.toBoolean("supportPostgresql");
boolean supportH2ForTest = config.toBoolean("supportH2ForTest");
boolean supportClient = config.toBoolean("supportClient");

transfer(targetPath, "", "pom.xml", templates.hybrid.service.pom.template(config));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
@args (String org, String serviceId)
#!/bin/bash

set -ex

VERSION=$1
IMAGE_NAME="@org/@serviceId"

showHelp() {
echo " "
echo "Error: $1"
echo " "
echo " build.sh [VERSION]"
echo " "
echo " where [VERSION] version of the docker image that you want to publish (example: 0.0.1)"
echo " "
echo " example: ./build.sh 0.0.1"
echo " "
}

build() {
echo "Building ..."
mvn clean install
echo "Successfully built!"
}

cleanup() {
if [[ "$(docker images -q $IMAGE_NAME 2> /dev/null)" != "" ]]; then
echo "Removing old $IMAGE_NAME images"
docker images | grep $IMAGE_NAME | awk '{print $3}' | xargs docker rmi -f
echo "Cleanup completed!"
fi
}

publish() {
echo "Building Docker image with version $VERSION"
docker build -t $IMAGE_NAME:$VERSION -t $IMAGE_NAME:latest -f ./docker/Dockerfile . --no-cache=true
docker build -t $IMAGE_NAME:$VERSION-redhat -f ./docker/Dockerfile-Redhat . --no-cache=true
echo "Images built with version $VERSION"
echo "Pushing image to DockerHub"
docker push $IMAGE_NAME
echo "Image successfully published!"
}

if [ -z $VERSION ]; then
showHelp "[VERSION] parameter is missing"
exit
fi

build;
cleanup;
publish;
3 changes: 2 additions & 1 deletion light-hybrid-4j/src/test/resources/serverConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@
"password": "my-secret-pw"
},
"supportH2ForTest": false,
"supportClient": false
"supportClient": false,
"dockerOrganization": "networknt"
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ public void generate(String targetPath, Object model, Any config) throws IOExcep
String httpsPort = config.toString("httpsPort");
boolean enableRegistry = config.toBoolean("enableRegistry");
boolean supportClient = config.toBoolean("supportClient");
String dockerOrganization = config.toString("dockerOrganization");
if(dockerOrganization == null || dockerOrganization.length() == 0) dockerOrganization = "networknt";

transfer(targetPath, "", "pom.xml", templates.rest.openapi.pom.template(config));
// There is only one port that should be exposed in Dockerfile, otherwise, the service
Expand All @@ -96,6 +98,7 @@ public void generate(String targetPath, Object model, Any config) throws IOExcep
}
transfer(targetPath, "docker", "Dockerfile", templates.rest.dockerfile.template(config, expose));
transfer(targetPath, "docker", "Dockerfile-Redhat", templates.rest.dockerfileredhat.template(config, expose));
transfer(targetPath, "", "build.sh", templates.rest.buildSh.template(dockerOrganization, config.get("groupId") + "." + config.get("artifactId") + "-" + config.get("version")));
transfer(targetPath, "", ".gitignore", templates.rest.gitignore.template());
transfer(targetPath, "", "README.md", templates.rest.README.template());
transfer(targetPath, "", "LICENSE", templates.rest.LICENSE.template());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ public void generate(String targetPath, Object model, Any config) throws IOExcep
String httpsPort = config.toString("httpsPort");
boolean enableRegistry = config.toBoolean("enableRegistry");
boolean supportClient = config.toBoolean("supportClient");
String dockerOrganization = config.toString("dockerOrganization");
if(dockerOrganization == null || dockerOrganization.length() == 0) dockerOrganization = "networknt";

transfer(targetPath, "", "pom.xml", templates.rest.swagger.pom.template(config));
// There is only one port that should be exposed in Dockerfile, otherwise, the service
Expand All @@ -95,6 +97,7 @@ public void generate(String targetPath, Object model, Any config) throws IOExcep

transfer(targetPath, "docker", "Dockerfile", templates.rest.dockerfile.template(config, expose));
transfer(targetPath, "docker", "Dockerfile-Redhat", templates.rest.dockerfileredhat.template(config, expose));
transfer(targetPath, "", "build.sh", templates.rest.buildSh.template(dockerOrganization, config.get("groupId") + "." + config.get("artifactId") + "-" + config.get("version")));
transfer(targetPath, "", ".gitignore", templates.rest.gitignore.template());
transfer(targetPath, "", "README.md", templates.rest.README.template());
transfer(targetPath, "", "LICENSE", templates.rest.LICENSE.template());
Expand Down
52 changes: 52 additions & 0 deletions light-rest-4j/src/main/resources/templates/rest/buildSh.rocker.raw
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
@args (String org, String serviceId)
#!/bin/bash

set -ex

VERSION=$1
IMAGE_NAME="@org/@serviceId"

showHelp() {
echo " "
echo "Error: $1"
echo " "
echo " build.sh [VERSION]"
echo " "
echo " where [VERSION] version of the docker image that you want to publish (example: 0.0.1)"
echo " "
echo " example: ./build.sh 0.0.1"
echo " "
}

build() {
echo "Building ..."
mvn clean install
echo "Successfully built!"
}

cleanup() {
if [[ "$(docker images -q $IMAGE_NAME 2> /dev/null)" != "" ]]; then
echo "Removing old $IMAGE_NAME images"
docker images | grep $IMAGE_NAME | awk '{print $3}' | xargs docker rmi -f
echo "Cleanup completed!"
fi
}

publish() {
echo "Building Docker image with version $VERSION"
docker build -t $IMAGE_NAME:$VERSION -t $IMAGE_NAME:latest -f ./docker/Dockerfile . --no-cache=true
docker build -t $IMAGE_NAME:$VERSION-redhat -f ./docker/Dockerfile-Redhat . --no-cache=true
echo "Images built with version $VERSION"
echo "Pushing image to DockerHub"
docker push $IMAGE_NAME
echo "Image successfully published!"
}

if [ -z $VERSION ]; then
showHelp "[VERSION] parameter is missing"
exit
fi

build;
cleanup;
publish;
3 changes: 2 additions & 1 deletion light-rest-4j/src/test/resources/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@
"password": "my-secret-pw"
},
"supportH2ForTest": false,
"supportClient": false
"supportClient": false,
"dockerOrganization": "networknt"
}

0 comments on commit f832b9b

Please sign in to comment.