Skip to content

Commit

Permalink
Clean up meteor version checking
Browse files Browse the repository at this point in the history
- Handle short releases (1.6 vs 1.6.0)
- Handle `-` suffixed releases (1.6-pre1, 1.6.1-beta.1, etc)
- Consolidate version checks into common function

Fixes CyCoreSystems#56
  • Loading branch information
Ulexus committed Nov 24, 2017
1 parent 73241f3 commit 12d1b6b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 28 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## Meteor 1.4
## Meteor 1.4+

The `latest` Docker tag and the `master` git branch are for Meteor 1.4+. For
prior versions of Meteor, please use the `legacy` tag and branch.
Expand Down Expand Up @@ -32,7 +32,7 @@ logins on your site, you must use the `:build` Docker tag (`build` git branch).
* References your external MongoDB database
* Uses Docker links (i.e. `MONGO_PORT`...)
* Explicit Mongo URLs by at `MONGO_URL`
* NOTE: This does NOT set `MONGO_OPLOG_URL`. There were too many potention complications. As a result, unless you explicitly set `MONGO_OPLOG_URL`, Meteor will fall back to a polling-based approach to database synchronization. Note that oplog tailing requires a working replica set on your MongoDB server as well as access to the `local` database.
* NOTE: This does NOT set `MONGO_OPLOG_URL`. There were too many potential complications. As a result, unless you explicitly set `MONGO_OPLOG_URL`, Meteor will fall back to a polling-based approach to database synchronization. Note that oplog tailing requires a working replica set on your MongoDB server as well as access to the `local` database.
* Optionally specify the port on which the web server should run (`PORT`); defaults to 80
* Non-root location of Meteor tree; the script will search for the first .meteor directory
* _NOTE_: PhantomJS is no longer pre-installed. This package was swelling the size of the image by 50%, and it is not maintainable with the standard Docker Node images. Instead, please use one of the docker-friendly (read port-based) spiderable packages on Meteor, such as [ongoworks:spiderable](https://atmospherejs.com/ongoworks/spiderable); if there is demand, please create an issue on Github, and I'll see about managing a separate branch for it.
Expand Down
58 changes: 32 additions & 26 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ set -e
export MONGO_URL
export PORT

# MIN_METEOR_RELEASE is the minimum Meteor version which can be run with this script
MIN_METEOR_RELEASE=1.4.0

# If we were given arguments, run them instead
if [ $? -gt 0 ]; then
exec "$@"
Expand Down Expand Up @@ -49,6 +52,32 @@ fi
mkdir -p $APP_DIR
mkdir -p $SRC_DIR

function checkver {
set +e # Allow commands inside this function to fail

# Strip "-" suffixes
local VER=$(echo $1 | cut -d'-' -f1)

# Format to x.y.z
if [ $(echo $1 | wc -c) -lt 5 ]; then
# if version is x.y, bump it to x.y.0
RELEASE_VER=${VER}.0
else
# If version is x.y.z.A, truncate it to x.y.z
RELEASE_VER=$(echo $VER |cut -d'.' -f1-3)
fi

semver -r '>='$MIN_METEOR_RELEASE $RELEASE_VER >/dev/null
if [ $? -ne 0 ]; then
echo "Application's Meteor version ($1) is less than ${MIN_METEOR_RELEASE}; please use ulexus/meteor:legacy"

if [ -z "${IGNORE_METEOR_VERSION}" ]; then
exit 1
fi
fi

set -e
}

# getrepo pulls the supplied git repository into $SRC_DIR
function getrepo {
Expand Down Expand Up @@ -85,22 +114,7 @@ if [ -e "${METEOR_DIR}" ]; then
# Check Meteor version
echo "Checking Meteor version..."
RELEASE=$(cat .meteor/release | cut -f2 -d'@')

# HACK: if version is x.y, bump it to x.y.0 to work around faulty semver
if [ $(echo $RELEASE | wc -c) -lt 5 ]; then
RELEASE=${RELEASE}.0
fi

set +e # Allow the next command to fail
semver -r '>=1.3.1' $(echo $RELEASE |cut -d'.' -f1-3)
if [ $? -ne 0 ]; then
echo "Application's Meteor version ($RELEASE) is less than 1.3.1; please use ulexus/meteor:legacy"

if [ -Z "${IGNORE_METEOR_VERSION}" ]; then
exit 1
fi
fi
set -e
checkver $RELEASE

# Download Meteor installer
echo "Downloading Meteor install script..."
Expand Down Expand Up @@ -150,16 +164,8 @@ if [ -e ${BUNDLE_DIR}/programs/server ]; then

# Check Meteor version
echo "Checking Meteor version..."
set +e # Allow the next command to fail
semver -r '>=1.3.1' $(cat config.json | jq .meteorRelease | tr -d '"' | cut -f2 -d'@' | cut -d'.' -f1-3)
if [ $? -ne 0 ]; then
echo "Application's Meteor version is less than 1.3.1; please use ulexus/meteor:legacy"

if [ -Z "${IGNORE_METEOR_VERSION}" ]; then
exit 1
fi
fi
set -e
set +e # Allow the next commands to fail
checkver $(cat config.json | jq -r .meteorRelease | cut -f2 -d'@')

echo "Installing NPM prerequisites..."
# Install all NPM packages
Expand Down

0 comments on commit 12d1b6b

Please sign in to comment.