From f7ff0621c5d7d5cef2576d1695993ba1cea120ae Mon Sep 17 00:00:00 2001 From: Oli Evans Date: Tue, 14 May 2019 11:46:17 +0100 Subject: [PATCH 1/6] feat: script to compare fresh install time A quick test to compare the first install time of a module via ipfs-npm against npm License: MIT Signed-off-by: Oli Evans --- .dockerignore | 2 ++ .npmignore | 2 ++ Dockerfile | 14 ++++++++++++++ test/perf/docker-race.sh | 37 +++++++++++++++++++++++++++++++++++++ 4 files changed, 55 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100755 test/perf/docker-race.sh diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..651665bb --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +node_modules +.git diff --git a/.npmignore b/.npmignore index 2c3dbec0..69f28be0 100644 --- a/.npmignore +++ b/.npmignore @@ -2,3 +2,5 @@ test dist img ci +.dockerignore +Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..7920192b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,14 @@ +# Build ipfs-npm from src +FROM node:10.15.3 +MAINTAINER olizilla + +WORKDIR /opt/npm-on-ipfs + +# Create a docker cache layer for just the deps. This means less rebuilding if +# only the source code changes +COPY package.json /opt/npm-on-ipfs +RUN npm install --quiet + +# Copy +COPY ./src /opt/npm-on-ipfs/src +RUN npm link diff --git a/test/perf/docker-race.sh b/test/perf/docker-race.sh new file mode 100755 index 00000000..45ef64e7 --- /dev/null +++ b/test/perf/docker-race.sh @@ -0,0 +1,37 @@ +#!/usr/bin/env bash + +# Compare the first install times of a module via npm and ipfs-npm. +# Using Docker here to ensure we are using fresh caches for each run. +# +# Usage: +# +# ./docker-race.sh [npm module] +# +# NOTE: On first run this will create a local image called ipfs-npm, from the +# Dockerfile at the root of this project. To update it with the latest source, +# rebuild the image: +# +# docker build -t ipfs-npm . +# +# or simply delete it and let the script re-build it +# +# docker image rm ipfs-npm -f +# +MODULE=${1:-iim} +IMAGE=ipfs-npm + +if $(docker image ls | grep -q $IMAGE) +then + echo "found ipfs-npm Docker image" +else + echo "building docker image for ipfs-npm, this will take a moment" + docker build -t $IMAGE ../../ +fi + +echo "" +echo "---- ipfs-npm flavour ----" +time docker run $IMAGE ipfs-npm install -g $MODULE + +echo "" +echo "---- npm flavour ----" +time docker run node:10.15.3 npm install -g $MODULE From 174eda2dfded6a13c55434d104d7a2164b54abf3 Mon Sep 17 00:00:00 2001 From: Oli Evans Date: Wed, 15 May 2019 09:22:22 +0100 Subject: [PATCH 2/6] chore: fix comment. more named variables License: MIT Signed-off-by: Oli Evans --- Dockerfile | 4 ++-- test/perf/docker-race.sh | 11 ++++++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index 7920192b..f364a252 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -# Build ipfs-npm from src +# Build ipfs-npm from src. Used in test/perf/docker-race.sh FROM node:10.15.3 MAINTAINER olizilla @@ -9,6 +9,6 @@ WORKDIR /opt/npm-on-ipfs COPY package.json /opt/npm-on-ipfs RUN npm install --quiet -# Copy +# Copy the src dir to the image, and add `ipfs-npm` to the PATH. COPY ./src /opt/npm-on-ipfs/src RUN npm link diff --git a/test/perf/docker-race.sh b/test/perf/docker-race.sh index 45ef64e7..c9381a93 100755 --- a/test/perf/docker-race.sh +++ b/test/perf/docker-race.sh @@ -18,20 +18,21 @@ # docker image rm ipfs-npm -f # MODULE=${1:-iim} -IMAGE=ipfs-npm +IPFS_NPM_IMAGE=ipfs-npm +REFERENCE_IMAGE=node:10.15.3 -if $(docker image ls | grep -q $IMAGE) +if $(docker image ls | grep -q $IPFS_NPM_IMAGE) then echo "found ipfs-npm Docker image" else echo "building docker image for ipfs-npm, this will take a moment" - docker build -t $IMAGE ../../ + docker build -t $IPFS_NPM_IMAGE ../../ fi echo "" echo "---- ipfs-npm flavour ----" -time docker run $IMAGE ipfs-npm install -g $MODULE +time docker run $IPFS_NPM_IMAGE ipfs-npm install -g $MODULE echo "" echo "---- npm flavour ----" -time docker run node:10.15.3 npm install -g $MODULE +time docker run $REFERENCE_IMAGE npm install -g $MODULE From 44b3348718bf33d88c81b7cbedd3039f4dcd87e6 Mon Sep 17 00:00:00 2001 From: Oli Evans Date: Wed, 15 May 2019 11:04:56 +0100 Subject: [PATCH 3/6] Update test/perf/docker-race.sh prefix relative path to docker build step Co-Authored-By: Marcin Rataj --- test/perf/docker-race.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/perf/docker-race.sh b/test/perf/docker-race.sh index c9381a93..42e58174 100755 --- a/test/perf/docker-race.sh +++ b/test/perf/docker-race.sh @@ -26,7 +26,7 @@ then echo "found ipfs-npm Docker image" else echo "building docker image for ipfs-npm, this will take a moment" - docker build -t $IPFS_NPM_IMAGE ../../ + docker build -t $IPFS_NPM_IMAGE $(dirname "$0")/../../ fi echo "" From 31847800696a4ca20b49d70d9d863b8828c0bd38 Mon Sep 17 00:00:00 2001 From: Oli Evans Date: Wed, 15 May 2019 11:05:39 +0100 Subject: [PATCH 4/6] fix: rm containers after use No need to keep container around after the test, as it will slowly eat up disk space. If you've already did run it multiple times: see last 10 containers via docker ps -a | head -10 remove image and all stale containers that use it docker rmi ipfs-npm -f It also makes sense to disable NAT and just use host network interfaces directly, bringing test closer to reality. This should run in ephemeral container with no NAT: Co-Authored-By: Marcin Rataj --- test/perf/docker-race.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/perf/docker-race.sh b/test/perf/docker-race.sh index 42e58174..b505ff36 100755 --- a/test/perf/docker-race.sh +++ b/test/perf/docker-race.sh @@ -31,7 +31,7 @@ fi echo "" echo "---- ipfs-npm flavour ----" -time docker run $IPFS_NPM_IMAGE ipfs-npm install -g $MODULE +time docker run --rm --net=host $IPFS_NPM_IMAGE ipfs-npm install -g $MODULE echo "" echo "---- npm flavour ----" From b2f58a55fb518e6ea6352e3f614b5de6429b4322 Mon Sep 17 00:00:00 2001 From: Oli Evans Date: Wed, 15 May 2019 11:05:55 +0100 Subject: [PATCH 5/6] fix: rm containers after use No need to keep container around after the test, as it will slowly eat up disk space. If you've already did run it multiple times: see last 10 containers via docker ps -a | head -10 remove image and all stale containers that use it docker rmi ipfs-npm -f It also makes sense to disable NAT and just use host network interfaces directly, bringing test closer to reality. This should run in ephemeral container with no NAT: Co-Authored-By: Marcin Rataj --- test/perf/docker-race.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/perf/docker-race.sh b/test/perf/docker-race.sh index b505ff36..39875b31 100755 --- a/test/perf/docker-race.sh +++ b/test/perf/docker-race.sh @@ -35,4 +35,4 @@ time docker run --rm --net=host $IPFS_NPM_IMAGE ipfs-npm install -g $MODULE echo "" echo "---- npm flavour ----" -time docker run $REFERENCE_IMAGE npm install -g $MODULE +time docker run --rm --net=host $REFERENCE_IMAGE npm install -g $MODULE From 6a0d227470baf0ffd631c1de76257c3f0e68247d Mon Sep 17 00:00:00 2001 From: Oli Evans Date: Wed, 15 May 2019 11:23:32 +0100 Subject: [PATCH 6/6] fix: fail on error License: MIT Signed-off-by: Oli Evans --- test/perf/docker-race.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/test/perf/docker-race.sh b/test/perf/docker-race.sh index 39875b31..8c3e9e11 100755 --- a/test/perf/docker-race.sh +++ b/test/perf/docker-race.sh @@ -17,6 +17,7 @@ # # docker image rm ipfs-npm -f # +set -eu MODULE=${1:-iim} IPFS_NPM_IMAGE=ipfs-npm REFERENCE_IMAGE=node:10.15.3