Skip to content

Commit

Permalink
Refactoring API startup process in docker
Browse files Browse the repository at this point in the history
- Enable reading configuration from git, to be able to support Mesos and Kubernetes, see Haufe-Lexware/wicked.haufe.io#34
  • Loading branch information
DonMartin76 committed Nov 28, 2016
1 parent 4eb19e4 commit daecd31
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Dockerfile.template
Expand Up @@ -4,4 +4,4 @@ EXPOSE 3001

RUN cp -R /usr/src/portal-env/initial-config /var/portal-api

CMD [ "npm", "start" ]
CMD [ "/usr/src/app/bin/docker-start.sh" ]
55 changes: 55 additions & 0 deletions bin/docker-start.sh
@@ -0,0 +1,55 @@
#!/bin/bash

set -e

runtimeEnv=$(uname)

if [ "$runtimeEnv" != "Linux" ] || [ ! -f /.dockerenv ]; then
echo "Do not use this script in non-dockerized environments."
echo "Detected non-Linux runtime $runtimeEnv, or /.dockerenv is not present."
echo "Use 'node bin/api' or 'npm start'.'"
exit 1
fi

exit 1

if [ ! -z "$GIT_CREDENTIALS" ] && [ ! -z "$GIT_REPO" ]; then

tmpDir=$(mktemp -d)

echo "Cloning configuration repository from $GIT_REPO into $tmpDir..."
pushd $tmpDir

if [ -z "$GIT_BRANCH" ]; then
echo "Checking out branch 'master'..."
git clone https://${GIT_CREDENTIALS}@${GIT_REPO} --depth 1 .
else
echo "Checking out branch '$GIT_BRANCH'..."
git clone https://${GIT_CREDENTIALS}@${GIT_REPO} --depth 1 --branch ${GIT_BRANCH} .
fi

if [ ! -d "$tmpDir/static" ]; then
echo "===================================================================================="
echo "ERROR: Could not find directory 'static' in $tmpDir, wrong repository?"
echo "===================================================================================="
exit 1
fi

echo "Cleaning up old configuration (if applicable)"
rm -rf /var/portal-api/static
echo "Copying configuration to /var/portal-api/static"
cp -R static /var/portal-api
echo "Done."

popd

echo "Cleanining up temp dir."
rm -rf $tmpDir

else
echo "Assuming /var/portal-api/static is prepopulated, not cloning configuration repo."
fi

echo "Starting API..."

npm start
2 changes: 1 addition & 1 deletion package.json
@@ -1,5 +1,5 @@
{
"version": "0.10.1",
"version": "0.10.2",
"private": true,
"dependencies": {
"chai": "3.5.0",
Expand Down

0 comments on commit daecd31

Please sign in to comment.