Skip to content

Commit

Permalink
Add zodern/meteor:root image
Browse files Browse the repository at this point in the history
  • Loading branch information
zodern committed Feb 3, 2018
1 parent 694a836 commit ba558d7
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 34 deletions.
1 change: 1 addition & 0 deletions image/scripts/entry.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ change_user () {

if [ -e /bundle/bundle.tar.gz ]; then
cd /bundle
chown -R app:app *.tar.gz || true
change_user

else
Expand Down
4 changes: 2 additions & 2 deletions image/scripts/setup_nvm.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
set -e
export NVM_DIR="$HOME/.nvm"
export NVM_DIR="/home/app/.nvm"
[ -s "$NVM_DIR/nvm.sh" ]
. "$NVM_DIR/nvm.sh"

NODE_VERSION="$(node $HOME/scripts/node-version.js)"
NODE_VERSION="$(node /home/app/scripts/node-version.js)"
echo "NODE_VERSION=$NODE_VERSION"

if [[ $DEBUG_NODE_VERSION == "0" ]]; then
Expand Down
9 changes: 6 additions & 3 deletions image/scripts/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,21 @@ if [ -e /bundle/bundle.tar.gz ]; then
cd /bundle

chmod -v 777 bundle.tar.gz || true
chown -R app:app *.tar.gz || true

echo "=> Extracting bundle"
tar --no-same-owner -xzf bundle.tar.gz

TAR_OPTIONS=$([ $EUID == 0 ] && echo "" || echo "--no-same-owner")
NPM_OPTIONS=$([ $EUID == 0 ] && echo " --unsafe-perm" || echo "")

tar $TAR_OPTIONS -xzf bundle.tar.gz

cd /bundle/bundle

echo "=> Setting node version"
. /home/app/scripts/setup_nvm.sh

echo "=> Installing npm dependencies"
cd ./programs/server && npm install $NPM_INSTALL_OPTIONS
cd ./programs/server && npm install $NPM_OPTIONS $NPM_INSTALL_OPTIONS

cd ../..
else
Expand Down
2 changes: 1 addition & 1 deletion image/setup/install_nvm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ set -e

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh | bash

export NVM_DIR="$HOME/.nvm"
export NVM_DIR="/home/app/.nvm"
[ -s "$NVM_DIR/nvm.sh" ]
. "$NVM_DIR/nvm.sh"

Expand Down
8 changes: 7 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ Docker image to run Meteor apps.
- Runs app as non-root user
- Compatible with Meteor up

## Tags

- `zodern/meteor:base`
- `zodern/meteor:root` Same as the base, except runs the app as the root user. Notes below about permissions do not apply to this image.
- `zodern/meteor:slim` Comming soon. Is a smaller image without node or npm preinstalled. During ONBUILD or when starting the app, it will install the correct version.

## How To Use

### Permissions
Expand Down Expand Up @@ -49,7 +55,7 @@ The `--build-arg NODE_VERSION=<node version>` is optional, and only needed if a
Run

```bash
docker run --name my-meteor-app -v /path/to/folder/with/bundle:/bundle -e "ROOT_URL=http://app.com" zodern/meteor
docker run --name my-meteor-app -v /path/to/folder/with/bundle:/bundle -p 3000:3000 -e "ROOT_URL=http://app.com" zodern/meteor
```

### Built app
Expand Down
9 changes: 9 additions & 0 deletions root-image/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM zodern/meteor
LABEL maintainer="zodern"
USER root
ONBUILD USER root
ONBUILD ARG NODE_VERSION='4.8.4'
ONBUILD RUN bash ./scripts/onbuild-node.sh
ONBUILD ENV NODE_PATH=/home/app/.onbuild-node/lib/node_modules
ONBUILD ENV PATH=/home/app/.onbuild-node/bin:$PATH
ENTRYPOINT bash /home/app/scripts/start.sh
84 changes: 57 additions & 27 deletions tests/test.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
set -e
docker build -t zodern/meteor:test ../image
docker build -t zodern/meteor ../image
docker build -t zodern/meteor:root ../root-image

command -v meteor >/dev/null 2>&1 || { curl https://install.meteor.com/ | sh; }

docker rm -f meteor-docker-test >/dev/null || true

rm -rf /tmp/docker-meteor-tests
sudo rm -rf /tmp/docker-meteor-tests
mkdir /tmp/docker-meteor-tests
cp -r ../ /tmp/docker-meteor-tests
cd /tmp/docker-meteor-tests/tests
Expand All @@ -17,21 +18,35 @@ mkdir ./app
mkdir ./bundle
mkdir ./archive

# Shows output whe the command fails
hide_output () {
file='./command_logs.txt'
rm -f "$file" || true
set +e
"$@" > "$file" 2>&1
code=$?
set -e
[ "$code" -eq 0 ] || cat "$file"

return "$code"
}

change_version() {
echo "=> Creating app with $1"

cd ..
rm -rf app
meteor create $1 app
hide_output meteor create $1 app
cd app
sleep 1

echo "=> npm install babel-runtime"
meteor npm install babel-runtime -q || true
hide_output meteor npm install babel-runtime -q || true
}

build_app() {
echo "=> Building app"
sudo rm -rf /tmp/docker-meteor-tests/bundle || true
meteor build ../bundle --debug
}

Expand All @@ -41,33 +56,35 @@ build_app_directory() {
}

test_bundle() {
echo "=> Testing bundle volume"
mv ../bundle/app.tar.gz ../bundle/bundle.tar.gz

echo "=> Creating docker container"
echo "==> Creating docker container"

docker run \
-v $PWD/../bundle:/bundle \
-v "$PWD"/../bundle:/bundle \
-e "ROOT_URL=http://localhost.com" \
-e "NPM_INSTALL_OPTIONS=--no-bin-links" \
-p 3000:3000 \
-d \
--name meteor-docker-test \
zodern/meteor:test
"$DOCKER_IMAGE"
}

test_bundle_docker() {
echo "=> Testing bundle image"
NODE_VERSION=$(meteor node --version)

echo "=> Creating image"
echo "==> Creating image"
mv ../bundle/app.tar.gz ../bundle/bundle.tar.gz
cd ../bundle

cat <<EOT > Dockerfile
FROM zodern/meteor:test
COPY --chown=app:app ./bundle.tar.gz /bundle/bundle.tar.gz
cat > Dockerfile << EOT
FROM $DOCKER_IMAGE
COPY ./bundle.tar.gz /bundle/bundle.tar.gz
EOT

docker build --build-arg $NODE_VERSION -t zodern/meteor-test .
hide_output docker build --build-arg NODE_VERSION="$NODE_VERSION" -t zodern/meteor-test .
docker run --name meteor-docker-test \
-e "ROOT_URL=http://app.com" \
-p 3000:3000 \
Expand All @@ -78,18 +95,19 @@ EOT
}

test_built_docker() {
echo "=> Testing built_app image"
NODE_VERSION=$(meteor node --version)

echo "=> Creating image"
echo "==> Creating image"

cd ../bundle/bundle
cat <<EOT > Dockerfile
FROM zodern/meteor:test
FROM $DOCKER_IMAGE
COPY --chown=app:app . /built_app
RUN cd /built_app/programs/server && npm install
RUN cd /built_app/programs/server && npm install $NPM_OPTIONS
EOT

docker build --build-arg NODE_VERSION=$NODE_VERSION -t zodern/meteor-test .
hide_output docker build --build-arg NODE_VERSION="$NODE_VERSION" -t zodern/meteor-test .
docker run --name meteor-docker-test \
-e "ROOT_URL=http://app.com" \
-p 3000:3000 \
Expand Down Expand Up @@ -120,12 +138,12 @@ verify() {
exit 1
fi

echo "SUCCESS $success"
echo "SUCCESS"
docker rm -f meteor-docker-test >/dev/null || true
}

test_version() {
change_version $1
change_version "$1"

build_app
test_bundle
Expand All @@ -136,16 +154,28 @@ test_version() {
verify

build_app_directory
test_built_docker $1
test_built_docker "$1"
verify
}

test_version "--release=1.2.1"
test_version "--release=1.3.5.1"
# test_version "--release=1.4"
# test_version "--release=1.4.4.5"
test_version "--release=1.5.4.1"
test_version "--release=1.6"
test_versions() {
echo "--- Testing Docker Image $DOCKER_IMAGE ---"

test_version "--release=1.2.1"
test_version "--release=1.3.5.1"
# test_version "--release=1.4"
# test_version "--release=1.4.4.5"
test_version "--release=1.5.4.1"
test_version "--release=1.6"

# Latest version
test_version
}

DOCKER_IMAGE="zodern/meteor"
NPM_OPTIONS=""
test_versions

# Latest version
test_version
DOCKER_IMAGE="zodern/meteor:root"
NPM_OPTIONS="--unsafe-perm"
test_versions

0 comments on commit ba558d7

Please sign in to comment.