[New] Introduce Docker environment for nvm

Peter Dave Hello 2017-04-02 08:03:32 +08:00 committed by Jordan Harband
parent 0356839d05
commit 3ac49e5ef1
No known key found for this signature in database
GPG Key ID: 64A196AEE0916D55
3 changed files with 153 additions and 0 deletions

17
.dockerignore 100644
View File

@ -0,0 +1,17 @@
HEAD
.cache
v*
alias
# For testing
test/bak
.urchin.log
.urchin_stdout
test/**/test_output
node_modules/
npm-debug.log
.DS_Store
current

105
Dockerfile 100644
View File

@ -0,0 +1,105 @@
# Dockerized nvm development environment
#
# This Dockerfile is for building nvm development environment only,
# not for any distribution/production usage.
#
# Please note that it'll use about 1.2 GB disk space and about 15 minutes to
# build this image, it depends on your hardware.
# Use Ubuntu Trusty Tahr as base image as we're using on Travis CI
# I also tested with Ubuntu 16.04, should be good with it!
From ubuntu:14.04
MAINTAINER Peter Dave Hello <hsu@peterdavehello.org>
# Prevent dialog during apt install
ENV DEBIAN_FRONTEND noninteractive
# Pick a Ubuntu apt mirror site for better speed
# ref: https://launchpad.net/ubuntu/+archivemirrors
ENV UBUNTU_APT_SITE ubuntu.cs.utah.edu
# Disable src package source
RUN sed -i 's/^deb-src\ /\#deb-src\ /g' /etc/apt/sources.list
# Replace origin apt pacakge site with the mirror site
RUN sed -E -i "s/([a-z]+.)?archive.ubuntu.com/$UBUNTU_APT_SITE/g" /etc/apt/sources.list
RUN sed -i "s/security.ubuntu.com/$UBUNTU_APT_SITE/g" /etc/apt/sources.list
# Install apt packages
RUN apt update && \
apt upgrade -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" && \
apt install -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" \
coreutils \
util-linux \
bsdutils \
file \
openssl \
ca-certificates \
ssh \
wget \
patch \
sudo \
htop \
dstat \
vim \
tmux \
curl \
git \
jq \
realpath \
zsh \
ksh \
ghc \
gcc-4.8 \
g++-4.8 \
cabal-install \
build-essential \
bash-completion && \
apt-get clean
# Set locale
RUN locale-gen en_US.UTF-8
# Print tool versions
RUN bash --version | head -n 1
RUN zsh --version
RUN ksh --version || true
RUN dpkg -s dash | grep ^Version | awk '{print $2}'
RUN git --version
RUN curl --version
RUN wget --version
RUN cabal --version
# Add user "nvm" as non-root user
RUN useradd -ms /bin/bash nvm
# Set sudoer for "nvm"
RUN echo 'nvm ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers
# Switch to user "nvm" from now
USER nvm
# Shellcheck
RUN cabal update
RUN cabal install ShellCheck
RUN ~/.cabal/bin/shellcheck --version
RUN echo 'export PATH="~/.cabal/bin/:${PATH}"' >> $HOME/.bashrc
# nvm
COPY . /home/nvm/.nvm/
RUN sudo chown nvm:nvm -R $HOME/.nvm
RUN echo 'export NVM_DIR="$HOME/.nvm"' >> $HOME/.bashrc
RUN echo '[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm' >> $HOME/.bashrc
RUN echo '[ -s "$NVM_DIR/bash_completion" ] && . "$NVM_DIR/bash_completion" # This loads nvm bash_completion' >> $HOME/.bashrc
# nodejs and tools
RUN bash -c 'source $HOME/.nvm/nvm.sh && \
nvm install node && \
npm install -g doctoc urchin && \
npm install --prefix "$HOME/.nvm/"'
# Set WORKDIR to nvm directory
WORKDIR /home/nvm/.nvm
ENTRYPOINT /bin/bash

View File

@ -28,6 +28,7 @@
- [Usage](#usage-1) - [Usage](#usage-1)
- [Compatibility Issues](#compatibility-issues) - [Compatibility Issues](#compatibility-issues)
- [Installing nvm on Alpine Linux](#installing-nvm-on-alpine-linux) - [Installing nvm on Alpine Linux](#installing-nvm-on-alpine-linux)
- [Docker for development environment](#docker-for-development-environment)
- [Problems](#problems) - [Problems](#problems)
- [Mac OS "troubleshooting"](#mac-os-troubleshooting) - [Mac OS "troubleshooting"](#mac-os-troubleshooting)
@ -485,6 +486,36 @@ The Node project has some desire but no concrete plans (due to the overheads of
As a potential alternative, @mhart (a Node contributor) has some [Docker images for Alpine Linux with Node and optionally, npm, pre-installed](https://github.com/mhart/alpine-node). As a potential alternative, @mhart (a Node contributor) has some [Docker images for Alpine Linux with Node and optionally, npm, pre-installed](https://github.com/mhart/alpine-node).
## Docker for development environment
To make the development and testing work easier, we have a Dockerfile for development usage, which is based on Ubuntu 14.04i base image, prepared with essential and useful tools for `nvm` development, to build the docker image of the environment, run the docker command at the root of `nvm` repository:
```sh
$ docker build -t nvm-dev .
```
This will package your current nvm repository with our pre-defiend deveopment environment into a docker image named `nvm-dev`, once it's built with success, validate your image via `docker images`:
```sh
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nvm-dev latest 9ca4c57a97d8 7 days ago 1.22 GB
```
If you got no error message, now you can easily involved in:
```sh
$ docker run -it nvm-dev -h nvm-dev
nvm@nvm-dev:~/.nvm$
```
Please note that it'll take about 15 minutes to build the image and the image size would be about 1.2GB, so it's not sutable for production usage.
For more information and documentation about docker, please refer to its official website:
- https://www.docker.com/
- https://docs.docker.com/
## Problems ## Problems