forked from redhat-developer/odo-init-image
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use custom innerloop scripts for java and nodejs (redhat-developer#27)
* preparation for language specific scripts * add dev-* scripts for nodejs and java * remove ODO_DEPLOYMENT_BACKUP_DIR * Remove custom dev-* scripts for java images assemble and run scripts in most java images are already "innerloop friendly" * getlanguage.go: add constants for env variables * nodejs: enable debug by default and add hot reload support * add dev-assemble and dev-run scripts for Java with remote debugging enabled * small comment fix * fix rebase errors
- Loading branch information
1 parent
a3afbfd
commit bf47608
Showing
9 changed files
with
258 additions
and
10 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
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
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,68 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"io/ioutil" | ||
"log" | ||
"os" | ||
) | ||
|
||
// imageMappingsFileEnv is env variable that points to image-mappings.json file | ||
const imageMappingsFileEnv string = "ODO_IMAGE_MAPPINGS_FILE" | ||
|
||
// builderImageNameEnv in env variable with name of the image ("name" label on the image) | ||
const builderImageNameEnv string = "ODO_S2I_BUILDER_IMG" | ||
|
||
// Lang stores list of image names associated to language | ||
type Lang struct { | ||
Language string | ||
Images []string | ||
} | ||
|
||
// ImageMappings hold mappings of language to image name | ||
// the structure represents image-mappings.json file | ||
type ImageMappings []Lang | ||
|
||
// GetLanguage returns language name name for associated to imageName | ||
func (im ImageMappings) GetLanguage(imageName string) string { | ||
for _, lang := range im { | ||
for _, image := range lang.Images { | ||
if image == imageName { | ||
return lang.Language | ||
} | ||
} | ||
} | ||
return "" | ||
} | ||
|
||
func main() { | ||
// json file where all the mappings of language to image name is stored | ||
// see ImageMappings for json structure | ||
imageMappingFile := os.Getenv(imageMappingsFileEnv) | ||
|
||
// name of the current image, we will try to find what language this is based on ImageMappings | ||
imageName := os.Getenv(builderImageNameEnv) | ||
|
||
var imageMappings ImageMappings | ||
|
||
file, err := os.Open(imageMappingFile) | ||
defer file.Close() | ||
if err != nil { | ||
log.Fatalln(err) | ||
} | ||
|
||
mappings, err := ioutil.ReadAll(file) | ||
if err != nil { | ||
log.Fatalln(err) | ||
} | ||
|
||
err = json.Unmarshal(mappings, &imageMappings) | ||
if err != nil { | ||
log.Fatalln(err) | ||
} | ||
|
||
lang := imageMappings.GetLanguage(imageName) | ||
|
||
fmt.Print(lang) | ||
} |
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,18 @@ | ||
[ | ||
{ | ||
"language": "nodejs", | ||
"images": [ | ||
"rhscl/nodejs-8-rhel7", | ||
"rhoar-nodejs/nodejs-8", | ||
"rhoar-nodejs/nodejs-10" | ||
] | ||
}, | ||
{ | ||
"language": "java", | ||
"images": [ | ||
"redhat-openjdk-18/openjdk18-openshift", | ||
"openjdk/openjdk-11-rhel8", | ||
"openjdk/openjdk-11-rhel7" | ||
] | ||
} | ||
] |
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,6 @@ | ||
#!/bin/bash | ||
set -e | ||
set -x | ||
|
||
# run normal assemble script | ||
exec "${ODO_S2I_SCRIPTS_URL}/assemble" |
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,15 @@ | ||
#!/bin/bash | ||
set -e | ||
set -x | ||
|
||
DEBUG_PORT="${DEBUG_PORT:=49200}" | ||
|
||
# DEBUG_MODE is true by defualt, which means that the application will be started with remote debugging enabled. | ||
DEBUG_MODE="${DEBUG_MODE:=true}" | ||
|
||
if [ $DEBUG_MODE != "false" ]; then | ||
export JAVA_OPTS="$JAVA_OPTS -Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=${DEBUG_PORT},suspend=n" | ||
fi | ||
|
||
# run normal run s2i script | ||
exec "${ODO_S2I_SCRIPTS_URL}/run" |
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,78 @@ | ||
#!/bin/bash | ||
set -e | ||
set -x | ||
|
||
cd /tmp/src | ||
|
||
NODE_ENV="${NODE_ENV:=development}" | ||
|
||
REFRESH_WORKING_DIR=/tmp/refresh/ | ||
PACKAGE_SHA_FILE=$REFRESH_WORKING_DIR/package.json.sha1 | ||
|
||
mkdir -p $REFRESH_WORKING_DIR | ||
|
||
|
||
if [ ! -z $HTTP_PROXY ]; then | ||
echo "---> Setting npm http proxy to $HTTP_PROXY" | ||
npm config set proxy $HTTP_PROXY | ||
fi | ||
|
||
if [ ! -z $http_proxy ]; then | ||
echo "---> Setting npm http proxy to $http_proxy" | ||
npm config set proxy $http_proxy | ||
fi | ||
|
||
if [ ! -z $HTTPS_PROXY ]; then | ||
echo "---> Setting npm https proxy to $HTTPS_PROXY" | ||
npm config set https-proxy $HTTPS_PROXY | ||
fi | ||
|
||
if [ ! -z $https_proxy ]; then | ||
echo "---> Setting npm https proxy to $https_proxy" | ||
npm config set https-proxy $https_proxy | ||
fi | ||
|
||
if [ ! -z $NO_PROXY ]; then | ||
echo "---> Setting npm no proxy config to $NO_PROXY" | ||
npm config set no-proxy $NO_PROXY | ||
fi | ||
|
||
if [ ! -z $no_proxy ]; then | ||
echo "---> Setting npm no proxy config to $no_proxy" | ||
npm config set no-proxy $no_proxy | ||
fi | ||
|
||
# Change the npm registry mirror if provided | ||
if [ ! -z "$NPM_MIRROR" ]; then | ||
echo "---> Setting the npm package mirror to $NPM_MIRROR" | ||
npm config set registry $NPM_MIRROR | ||
fi | ||
|
||
echo "---> Building your Node application from source" | ||
|
||
|
||
# don't do anything if package.json is the same as the last time this script was executed | ||
if [ -f $PACKAGE_SHA_FILE ]; then | ||
out=$(sha1sum -c $PACKAGE_SHA_FILE || true) | ||
if [ "$out" == "package.json: OK" ]; then | ||
echo "---> package.json is the same as last time, no changes needed." | ||
exit 0 | ||
fi | ||
fi | ||
|
||
echo "---> package.json modified" | ||
sha1sum package.json > $PACKAGE_SHA_FILE | ||
|
||
|
||
if [ ! -z "$YARN_ENABLED" ]; then | ||
echo "---> Using 'yarn install' with YARN_ARGS" | ||
npx yarn install $YARN_ARGS | ||
else | ||
echo "---> Installing dependencies" | ||
echo "---> Using 'npm install'" | ||
npm install | ||
|
||
#do not fail when there is no build script | ||
echo "---> Building in development mode" | ||
npm run build --if-present | ||
fi |
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,32 @@ | ||
#!/bin/bash | ||
set -e | ||
set -x | ||
|
||
cd /tmp/src | ||
|
||
NODE_ENV="${NODE_ENV:=development}" | ||
DEBUG_PORT="${DEBUG_PORT:=9229}" | ||
|
||
# DEBUG_MODE is true by defualt, which means that the application will be started with remote debugging enabled. | ||
DEBUG_MODE="${DEBUG_MODE:=true}" | ||
|
||
export GIT_COMMITTER_NAME="unknown" | ||
export and GIT_COMMITTER_EMAIL="unknown@localhost" | ||
git --version | ||
|
||
echo -e "Using Node.js version: $(node --version)" | ||
echo -e "Environment:" | ||
echo -e " NODE_ENV=${NODE_ENV}" | ||
echo -e " DEBUG_PORT=${DEBUG_PORT}" | ||
echo -e " DEBUG_MODE=${DEBUG_MODE}" | ||
echo -e "Running as user $(id)" | ||
|
||
echo "Launching via npm..." | ||
|
||
if [ $DEBUG_MODE == "false" ]; then | ||
exec npm run -d start | ||
else | ||
# TODO: if users app doesn't have nodemon as a dev dependency it will take a long time to start it via npx | ||
exec npx nodemon --inspect=$DEBUG_PORT | ||
fi | ||
|
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