Nexmo / nexmo-cli

Nexmo CLI (Command Line Interface)
https://nexmo.com
MIT License
78 stars 52 forks source link

Add a dockerfile #181

Closed aslafy-z closed 5 years ago

aslafy-z commented 5 years ago

Summary

Add a dockerfile for using/building nexmo-cli

Final runtime image size is 25 MB compressed It's available to test on the docker hub: zadki3l/nexmo

Try it now with:

docker run --rm -it zadki3l/nexmo

Other Information

This dockerfile leverage multiple stages builds:

I recommend to append -u "$(id -u):$(id -g)" to the docker run command to keep permissions clean.

Usage

# Build the dev image
docker build -t nexmo:dev --target dev .
# Build the runtime final image
docker build -t nexmo .

# Run dev image (default to `watch:test` script)
docker run --rm -it -u "$(id -u):$(id -g)" -v $PWD/src:/nexmo/src -v $PWD/tests:/nexmo/tests nexmo:dev
# Run dev image (`build` to external folder)
mkdir -p lib
docker run --rm -it -u "$(id -u):$(id -g)" -v $PWD/src:/nexmo/src -v $PWD/lib:/nexmo/lib nexmo:dev npm run build

# Handy dev alias (run from repo folder)
alias nexmo-dev="mkdir -p $PWD/lib; docker run --rm -it -u '$(id -u):$(id -g)' -v $PWD/src:/nexmo/src -v $PWD/tests:/nexmo/tests -v $PWD/lib:/nexmo/lib nexmo:dev npm run"
# and then:
nexmo-dev build
nexmo-dev watch:test
nexmo-dev any-npm-script

# Run prod image (`nexmo-cli -V`)
docker run --rm -it nexmo -V

# Handy production alias
# assuming you have a $HOME/.nexmorc file
# create it with `touch $HOME/.nexmorc` before running this
alias nexmo="docker run --rm -u '$(id -u):$(id -g)' -v $HOME/.nexmorc:/.nexmorc -it nexmo"
# and then:
nexmo
nexmo setup XX XX
nexmo account

Currently prepublish step fail in the docker image (don't know why), will need #187 later.

AlexLakatos commented 5 years ago

this feels a tad bit too complicated. is there any way to make it simpler? and the size smaller than 19 MB?

aslafy-z commented 5 years ago

I could remove the packaging step but as you can see https://hub.docker.com/r/zadki3l/nexmo/tags/, the 'build' image (tag) is bigger than the 'runtime'. The node_modules folder itself is 50MB so making it smaller would be difficult.

Edit: down to 7.5MB by deleting dev dependencies, but it does not reduce final size.

It's already tiny for a docker image!

aslafy-z commented 5 years ago

Will this PR be eligible to hacktoberfest, even if it's not merged by Oct. 30?

aslafy-z commented 5 years ago

I deleted the package step to be more accessible, it increases the release size by 6MB to 25MB compressed.

Not that node:10-alpine is 24MB compressed

lornajane commented 5 years ago

I'm sorry but we won't be accepting this PR. I'm sure it is useful to someone, but it's not something we want to include in our project and support going forward.