From d6127082e9dba7978c67ddfd23df4a5fff883366 Mon Sep 17 00:00:00 2001 From: Jose Fuentes Date: Thu, 13 Dec 2018 20:27:35 +0100 Subject: [PATCH 1/3] Add stacksmith scripts --- stacksmith/user-scripts/boot.sh | 22 ++++++++ stacksmith/user-scripts/build.sh | 86 ++++++++++++++++++++++++++++++++ stacksmith/user-scripts/run.sh | 9 ++++ 3 files changed, 117 insertions(+) create mode 100755 stacksmith/user-scripts/boot.sh create mode 100755 stacksmith/user-scripts/build.sh create mode 100755 stacksmith/user-scripts/run.sh diff --git a/stacksmith/user-scripts/boot.sh b/stacksmith/user-scripts/boot.sh new file mode 100755 index 000000000..2e3f1921e --- /dev/null +++ b/stacksmith/user-scripts/boot.sh @@ -0,0 +1,22 @@ +#!/bin/bash +set -eux + +#!/bin/bash + +set -euo pipefail + +# This file will store the config env variables needed by the app +readonly CONF=/build/env.config + +cat >"${CONF}" <<'EOF' +export MONGO_URL=mongodb://{{DATABASE_USER}}:{{DATABASE_PASSWORD}}@{{DATABASE_HOST}}:{{DATABASE_PORT}}/{{DATABASE_NAME}} +export ROOT_URL=http://localhost +export PORT=3000 +EOF + +sed -i -e "s/{{DATABASE_USER}}/${DATABASE_USER}/" "${CONF}" +sed -i -e "s/{{DATABASE_PASSWORD}}/${DATABASE_PASSWORD}/" "${CONF}" +sed -i -e "s/{{DATABASE_HOST}}/${DATABASE_HOST}/" "${CONF}" +sed -i -e "s/{{DATABASE_PORT}}/${DATABASE_PORT}/" "${CONF}" +sed -i -e "s/{{DATABASE_NAME}}/${DATABASE_NAME}/" "${CONF}" + diff --git a/stacksmith/user-scripts/build.sh b/stacksmith/user-scripts/build.sh new file mode 100755 index 000000000..144ba4683 --- /dev/null +++ b/stacksmith/user-scripts/build.sh @@ -0,0 +1,86 @@ +#!/bin/bash +set -euxo pipefail + +BUILD_DEPS="bsdtar gnupg wget curl bzip2 python git ca-certificates perl-Digest-SHA" +NODE_VERSION=v8.14.0 +METEOR_RELEASE=1.6.0.1 +USE_EDGE=false +METEOR_EDGE=1.5-beta.17 +NPM_VERSION=latest +FIBERS_VERSION=2.0.0 +ARCHITECTURE=linux-x64 +NODE_VERSION=v10.14.1 + +sudo yum groupinstall 'Development Tools' +sudo yum install -y http://opensource.wandisco.com/centos/7/git/x86_64/wandisco-git-release-7-2.noarch.rpm +sudo yum install -y git + +sudo useradd --user-group --system --home-dir /home/wekan wekan +sudo mkdir -p /home/wekan +sudo chown wekan:wekan /home/wekan/ + +sudo -u wekan git clone https://github.com/j-fuentes/wekan.git /home/wekan/app + +sudo yum install -y ${BUILD_DEPS} + +# Meteor installer doesn't work with the default tar binary, so using bsdtar while installing. +# https://github.com/coreos/bugs/issues/1095#issuecomment-350574389 +sudo cp $(which tar) $(which tar)~ +sudo ln -sf $(which bsdtar) $(which tar) + +# Install nodejs +wget https://nodejs.org/dist/${NODE_VERSION}/node-${NODE_VERSION}-${ARCHITECTURE}.tar.gz +wget https://nodejs.org/dist/${NODE_VERSION}/SHASUMS256.txt.asc + +grep ${NODE_VERSION}-${ARCHITECTURE}.tar.gz SHASUMS256.txt.asc | shasum -a 256 -c - + +tar xvzf node-${NODE_VERSION}-${ARCHITECTURE}.tar.gz +rm node-${NODE_VERSION}-${ARCHITECTURE}.tar.gz +sudo mv node-${NODE_VERSION}-${ARCHITECTURE} /opt/nodejs +sudo rm -f /usr/bin/node +sudo rm -f /usr/bin/npm +sudo ln -s /opt/nodejs/bin/node /usr/bin/node || true +sudo ln -s /opt/nodejs/bin/npm /usr/bin/npm || true + +sudo npm install -g npm@${NPM_VERSION} +sudo npm install -g node-gyp +sudo npm install -g --unsafe-perm fibers@${FIBERS_VERSION} + +cd /home/wekan + +#install meteor +sudo curl "https://install.meteor.com" -o /home/wekan/install_meteor.sh +sudo chmod +x /home/wekan/install_meteor.sh +sudo sed -i 's/VERBOSITY="--silent"/VERBOSITY="--progress-bar"/' ./install_meteor.sh +echo "Starting meteor ${METEOR_RELEASE} installation... \n" + +# Check if opting for a release candidate instead of major release +if [ "$USE_EDGE" = false ]; then + sudo su -c '/home/wekan/install_meteor.sh' - wekan +else + sudo -u wekan git clone --recursive --depth 1 -b release/METEOR@${METEOR_EDGE} git://github.com/meteor/meteor.git /home/wekan/.meteor; +fi; + +# Get additional packages +sudo mkdir -p /home/wekan/app/packages +sudo chown wekan:wekan --recursive /home/wekan/app +cd /home/wekan/app/packages +sudo -u wekan git clone --depth 1 -b master git://github.com/wekan/flow-router.git kadira-flow-router +sudo -u wekan git clone --depth 1 -b master git://github.com/meteor-useraccounts/core.git meteor-useraccounts-core +sudo -u wekan git clone --depth 1 -b master git://github.com/wekan/meteor-accounts-cas.git +sudo -u wekan git clone --depth 1 -b master git://github.com/wekan/wekan-ldap.git +sudo sed -i 's/api\.versionsFrom/\/\/api.versionsFrom/' /home/wekan/app/packages/meteor-useraccounts-core/package.js +sudo -u wekan /home/wekan/.meteor/meteor -- help + +# Build app +cd /home/wekan/app +meteor=/home/wekan/.meteor/meteor +sudo -u wekan ${meteor} add standard-minifier-js +sudo -u wekan ${meteor} npm install +sudo -u wekan ${meteor} build --directory /home/wekan/app_build +sudo cp /home/wekan/app/fix-download-unicode/cfs_access-point.txt /home/wekan/app_build/bundle/programs/server/packages/cfs_access-point.js +sudo chown wekan:wekan /home/wekan/app_build/bundle/programs/server/packages/cfs_access-point.js +cd /home/wekan/app_build/bundle/programs/server/ +sudo npm install +sudo chown -R wekan:wekan ./node_modules +sudo mv /home/wekan/app_build/bundle /build diff --git a/stacksmith/user-scripts/run.sh b/stacksmith/user-scripts/run.sh new file mode 100755 index 000000000..20d4743ba --- /dev/null +++ b/stacksmith/user-scripts/run.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +readonly CONF=/build/env.config + +source ${CONF} + +cd /build +echo "starting the wekan service..." +node main.js From 7b3e2c58e29de6477dfcd2e2051d241c67266c85 Mon Sep 17 00:00:00 2001 From: Jose Fuentes Date: Fri, 14 Dec 2018 09:35:48 +0100 Subject: [PATCH 2/3] Pipefail error --- Stackerfile.yml | 9 +++++++++ stacksmith/user-scripts/boot.sh | 5 ++++- stacksmith/user-scripts/run.sh | 1 + 3 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 Stackerfile.yml diff --git a/Stackerfile.yml b/Stackerfile.yml new file mode 100644 index 000000000..26c403c00 --- /dev/null +++ b/Stackerfile.yml @@ -0,0 +1,9 @@ +appId: wekan-public/apps/77b94f60-dec9-0136-304e-16ff53095928 +appVersion: "0" +files: + userUploads: + - README.md + userScripts: + build: stacksmith/user-scripts/build.sh + boot: stacksmith/user-scripts/boot.sh + run: stacksmith/user-scripts/run.sh diff --git a/stacksmith/user-scripts/boot.sh b/stacksmith/user-scripts/boot.sh index 2e3f1921e..19ea8825d 100755 --- a/stacksmith/user-scripts/boot.sh +++ b/stacksmith/user-scripts/boot.sh @@ -1,5 +1,5 @@ #!/bin/bash -set -eux +set -euxo pipefail #!/bin/bash @@ -8,6 +8,9 @@ set -euo pipefail # This file will store the config env variables needed by the app readonly CONF=/build/env.config +# EMAIL_URL can also be set here by injecting another env variable in the template +# ROOT_URL can also be set at runtime, by querying AWS api or by using ingress annotations in the template for k8s. + cat >"${CONF}" <<'EOF' export MONGO_URL=mongodb://{{DATABASE_USER}}:{{DATABASE_PASSWORD}}@{{DATABASE_HOST}}:{{DATABASE_PORT}}/{{DATABASE_NAME}} export ROOT_URL=http://localhost diff --git a/stacksmith/user-scripts/run.sh b/stacksmith/user-scripts/run.sh index 20d4743ba..e7cc6df6f 100755 --- a/stacksmith/user-scripts/run.sh +++ b/stacksmith/user-scripts/run.sh @@ -1,4 +1,5 @@ #!/bin/bash +set -euxo pipefail readonly CONF=/build/env.config From cac74122f204bfb13e9e277901b9a385c75f4135 Mon Sep 17 00:00:00 2001 From: Jose Fuentes Date: Mon, 17 Dec 2018 13:09:32 +0100 Subject: [PATCH 3/3] Wait for DB on boot --- Stackerfile.yml | 2 +- stacksmith/user-scripts/boot.sh | 4 ---- stacksmith/user-scripts/build.sh | 2 +- stacksmith/user-scripts/run.sh | 12 +++++++++++- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/Stackerfile.yml b/Stackerfile.yml index 26c403c00..1922d538a 100644 --- a/Stackerfile.yml +++ b/Stackerfile.yml @@ -1,5 +1,5 @@ appId: wekan-public/apps/77b94f60-dec9-0136-304e-16ff53095928 -appVersion: "0" +appVersion: "v1.85.0" files: userUploads: - README.md diff --git a/stacksmith/user-scripts/boot.sh b/stacksmith/user-scripts/boot.sh index 19ea8825d..bd95102f0 100755 --- a/stacksmith/user-scripts/boot.sh +++ b/stacksmith/user-scripts/boot.sh @@ -1,10 +1,6 @@ #!/bin/bash set -euxo pipefail -#!/bin/bash - -set -euo pipefail - # This file will store the config env variables needed by the app readonly CONF=/build/env.config diff --git a/stacksmith/user-scripts/build.sh b/stacksmith/user-scripts/build.sh index 144ba4683..a8f756e67 100755 --- a/stacksmith/user-scripts/build.sh +++ b/stacksmith/user-scripts/build.sh @@ -11,7 +11,7 @@ FIBERS_VERSION=2.0.0 ARCHITECTURE=linux-x64 NODE_VERSION=v10.14.1 -sudo yum groupinstall 'Development Tools' +sudo yum groupinstall -y 'Development Tools' sudo yum install -y http://opensource.wandisco.com/centos/7/git/x86_64/wandisco-git-release-7-2.noarch.rpm sudo yum install -y git diff --git a/stacksmith/user-scripts/run.sh b/stacksmith/user-scripts/run.sh index e7cc6df6f..2aea7ea07 100755 --- a/stacksmith/user-scripts/run.sh +++ b/stacksmith/user-scripts/run.sh @@ -1,10 +1,20 @@ #!/bin/bash -set -euxo pipefail +set -euo pipefail readonly CONF=/build/env.config source ${CONF} +# wait for DB +check_db() { + mongo $MONGO_URL --eval "db.runCommand( { connectionStatus: 1} )" --quiet | python -c 'import json,sys;obj=json.load(sys.stdin);code = 0 if obj["ok"]==1 else 1; sys.exit(code);' +} +until check_db; do + period=5 + echo "Cannot connect to db, waiting ${period} seconds before trying again..." + sleep ${period} +done + cd /build echo "starting the wekan service..." node main.js