Skip to content

Commit ba558d7

Browse files
committed
Add zodern/meteor:root image
1 parent 694a836 commit ba558d7

File tree

7 files changed

+83
-34
lines changed

7 files changed

+83
-34
lines changed

image/scripts/entry.sh

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ change_user () {
1515

1616
if [ -e /bundle/bundle.tar.gz ]; then
1717
cd /bundle
18+
chown -R app:app *.tar.gz || true
1819
change_user
1920

2021
else

image/scripts/setup_nvm.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
set -e
2-
export NVM_DIR="$HOME/.nvm"
2+
export NVM_DIR="/home/app/.nvm"
33
[ -s "$NVM_DIR/nvm.sh" ]
44
. "$NVM_DIR/nvm.sh"
55

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

99
if [[ $DEBUG_NODE_VERSION == "0" ]]; then

image/scripts/start.sh

+6-3
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,21 @@ if [ -e /bundle/bundle.tar.gz ]; then
66
cd /bundle
77

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

1110
echo "=> Extracting bundle"
12-
tar --no-same-owner -xzf bundle.tar.gz
11+
12+
TAR_OPTIONS=$([ $EUID == 0 ] && echo "" || echo "--no-same-owner")
13+
NPM_OPTIONS=$([ $EUID == 0 ] && echo " --unsafe-perm" || echo "")
14+
15+
tar $TAR_OPTIONS -xzf bundle.tar.gz
1316

1417
cd /bundle/bundle
1518

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

1922
echo "=> Installing npm dependencies"
20-
cd ./programs/server && npm install $NPM_INSTALL_OPTIONS
23+
cd ./programs/server && npm install $NPM_OPTIONS $NPM_INSTALL_OPTIONS
2124

2225
cd ../..
2326
else

image/setup/install_nvm.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ set -e
33

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

6-
export NVM_DIR="$HOME/.nvm"
6+
export NVM_DIR="/home/app/.nvm"
77
[ -s "$NVM_DIR/nvm.sh" ]
88
. "$NVM_DIR/nvm.sh"
99

readme.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ Docker image to run Meteor apps.
1010
- Runs app as non-root user
1111
- Compatible with Meteor up
1212

13+
## Tags
14+
15+
- `zodern/meteor:base`
16+
- `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.
17+
- `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.
18+
1319
## How To Use
1420

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

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

5561
### Built app

root-image/Dockerfile

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
FROM zodern/meteor
2+
LABEL maintainer="zodern"
3+
USER root
4+
ONBUILD USER root
5+
ONBUILD ARG NODE_VERSION='4.8.4'
6+
ONBUILD RUN bash ./scripts/onbuild-node.sh
7+
ONBUILD ENV NODE_PATH=/home/app/.onbuild-node/lib/node_modules
8+
ONBUILD ENV PATH=/home/app/.onbuild-node/bin:$PATH
9+
ENTRYPOINT bash /home/app/scripts/start.sh

tests/test.sh

+57-27
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
set -e
2-
docker build -t zodern/meteor:test ../image
2+
docker build -t zodern/meteor ../image
3+
docker build -t zodern/meteor:root ../root-image
34

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

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

8-
rm -rf /tmp/docker-meteor-tests
9+
sudo rm -rf /tmp/docker-meteor-tests
910
mkdir /tmp/docker-meteor-tests
1011
cp -r ../ /tmp/docker-meteor-tests
1112
cd /tmp/docker-meteor-tests/tests
@@ -17,21 +18,35 @@ mkdir ./app
1718
mkdir ./bundle
1819
mkdir ./archive
1920

21+
# Shows output whe the command fails
22+
hide_output () {
23+
file='./command_logs.txt'
24+
rm -f "$file" || true
25+
set +e
26+
"$@" > "$file" 2>&1
27+
code=$?
28+
set -e
29+
[ "$code" -eq 0 ] || cat "$file"
30+
31+
return "$code"
32+
}
33+
2034
change_version() {
2135
echo "=> Creating app with $1"
2236

2337
cd ..
2438
rm -rf app
25-
meteor create $1 app
39+
hide_output meteor create $1 app
2640
cd app
2741
sleep 1
2842

2943
echo "=> npm install babel-runtime"
30-
meteor npm install babel-runtime -q || true
44+
hide_output meteor npm install babel-runtime -q || true
3145
}
3246

3347
build_app() {
3448
echo "=> Building app"
49+
sudo rm -rf /tmp/docker-meteor-tests/bundle || true
3550
meteor build ../bundle --debug
3651
}
3752

@@ -41,33 +56,35 @@ build_app_directory() {
4156
}
4257

4358
test_bundle() {
59+
echo "=> Testing bundle volume"
4460
mv ../bundle/app.tar.gz ../bundle/bundle.tar.gz
4561

46-
echo "=> Creating docker container"
62+
echo "==> Creating docker container"
4763

4864
docker run \
49-
-v $PWD/../bundle:/bundle \
65+
-v "$PWD"/../bundle:/bundle \
5066
-e "ROOT_URL=http://localhost.com" \
5167
-e "NPM_INSTALL_OPTIONS=--no-bin-links" \
5268
-p 3000:3000 \
5369
-d \
5470
--name meteor-docker-test \
55-
zodern/meteor:test
71+
"$DOCKER_IMAGE"
5672
}
5773

5874
test_bundle_docker() {
75+
echo "=> Testing bundle image"
5976
NODE_VERSION=$(meteor node --version)
6077

61-
echo "=> Creating image"
78+
echo "==> Creating image"
6279
mv ../bundle/app.tar.gz ../bundle/bundle.tar.gz
6380
cd ../bundle
6481

65-
cat <<EOT > Dockerfile
66-
FROM zodern/meteor:test
67-
COPY --chown=app:app ./bundle.tar.gz /bundle/bundle.tar.gz
82+
cat > Dockerfile << EOT
83+
FROM $DOCKER_IMAGE
84+
COPY ./bundle.tar.gz /bundle/bundle.tar.gz
6885
EOT
6986

70-
docker build --build-arg $NODE_VERSION -t zodern/meteor-test .
87+
hide_output docker build --build-arg NODE_VERSION="$NODE_VERSION" -t zodern/meteor-test .
7188
docker run --name meteor-docker-test \
7289
-e "ROOT_URL=http://app.com" \
7390
-p 3000:3000 \
@@ -78,18 +95,19 @@ EOT
7895
}
7996

8097
test_built_docker() {
98+
echo "=> Testing built_app image"
8199
NODE_VERSION=$(meteor node --version)
82100

83-
echo "=> Creating image"
101+
echo "==> Creating image"
84102

85103
cd ../bundle/bundle
86104
cat <<EOT > Dockerfile
87-
FROM zodern/meteor:test
105+
FROM $DOCKER_IMAGE
88106
COPY --chown=app:app . /built_app
89-
RUN cd /built_app/programs/server && npm install
107+
RUN cd /built_app/programs/server && npm install $NPM_OPTIONS
90108
EOT
91109

92-
docker build --build-arg NODE_VERSION=$NODE_VERSION -t zodern/meteor-test .
110+
hide_output docker build --build-arg NODE_VERSION="$NODE_VERSION" -t zodern/meteor-test .
93111
docker run --name meteor-docker-test \
94112
-e "ROOT_URL=http://app.com" \
95113
-p 3000:3000 \
@@ -120,12 +138,12 @@ verify() {
120138
exit 1
121139
fi
122140

123-
echo "SUCCESS $success"
141+
echo "SUCCESS"
124142
docker rm -f meteor-docker-test >/dev/null || true
125143
}
126144

127145
test_version() {
128-
change_version $1
146+
change_version "$1"
129147

130148
build_app
131149
test_bundle
@@ -136,16 +154,28 @@ test_version() {
136154
verify
137155

138156
build_app_directory
139-
test_built_docker $1
157+
test_built_docker "$1"
140158
verify
141159
}
142160

143-
test_version "--release=1.2.1"
144-
test_version "--release=1.3.5.1"
145-
# test_version "--release=1.4"
146-
# test_version "--release=1.4.4.5"
147-
test_version "--release=1.5.4.1"
148-
test_version "--release=1.6"
161+
test_versions() {
162+
echo "--- Testing Docker Image $DOCKER_IMAGE ---"
163+
164+
test_version "--release=1.2.1"
165+
test_version "--release=1.3.5.1"
166+
# test_version "--release=1.4"
167+
# test_version "--release=1.4.4.5"
168+
test_version "--release=1.5.4.1"
169+
test_version "--release=1.6"
170+
171+
# Latest version
172+
test_version
173+
}
174+
175+
DOCKER_IMAGE="zodern/meteor"
176+
NPM_OPTIONS=""
177+
test_versions
149178

150-
# Latest version
151-
test_version
179+
DOCKER_IMAGE="zodern/meteor:root"
180+
NPM_OPTIONS="--unsafe-perm"
181+
test_versions

0 commit comments

Comments
 (0)