Skip to content

Commit 151df3c

Browse files
author
js-jslog
committed
Create a developer user
It is preferable that we don't constantly use the root user while inside containers created from this image. This is the first commit on the path to achieving this. I have increased the major version since it will require new instructions to start the containers with permissions mapped to the host operating system. Without following these new instructions the user will encounter permissions issues. I have not yet figured out how to do this mapping though so this version is not ready to be tagged just yet.
1 parent f536dd1 commit 151df3c

File tree

1 file changed

+55
-51
lines changed

1 file changed

+55
-51
lines changed

Dockerfile

Lines changed: 55 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,7 @@ ARG HTTP_PROXY=$HTTP_PROXY
66
ARG HTTPS_PROXY=$HTTPS_PROXY
77

88
ENV TERM=xterm-256color
9-
ENV NVM_DIR=/usr/local/nvm
109
ENV NODE_VERSION=10.15.1
11-
ENV NODE_PATH=$NVM_DIR/versions/node/v$NODE_VERSION/lib/node_modules
12-
ENV PATH=$NVM_DIR/versions/node/v$NODE_VERSION/bin:$PATH
13-
14-
# Create a developer folder in the home directory
15-
# TODO: actually create a user with a home folder
16-
# - need to investigate how to change UID and GID
17-
# at container creation time
18-
RUN mkdir -p /home/developer/
1910

2011
# Replace shell with bash so we can source files
2112
RUN rm /bin/sh && ln -s /bin/bash /bin/sh
@@ -43,72 +34,85 @@ RUN apt-get update && apt-get install -y -q --no-install-recommends \
4334
postgresql postgresql-contrib \
4435
&& rm -rf /var/lib/apt/lists/*
4536

46-
# Install vim and customise
47-
COPY dotfiles/.vimrc /root/.vimrc
37+
# Install docker ce so that host docker instances can be manipulated from this env
38+
RUN apt-get update && apt-get install -y -q --no-install-recommends \
39+
apt-transport-https \
40+
ca-certificates \
41+
curl \
42+
gnupg-agent \
43+
software-properties-common
44+
45+
RUN curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
46+
RUN add-apt-repository \
47+
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
48+
$(lsb_release -cs) \
49+
stable"
50+
51+
RUN apt-get update && apt-get install -y -q --no-install-recommends \
52+
docker-ce \
53+
docker-ce-cli \
54+
containerd.io
55+
56+
# Install vim 8
4857
RUN add-apt-repository ppa:jonathonf/vim -y \
4958
&& apt update \
5059
&& apt install vim -y
5160

52-
RUN rm -r /root/.vim || true \
53-
&& curl -fLo ~/.vim/autoload/plug.vim --create-dirs \
61+
# Create developer user under which all development within the container
62+
# will be performed
63+
RUN useradd --create-home --shell /bin/bash developer
64+
USER developer
65+
66+
# Install users vim customisations. This requires that the .vimrc
67+
# file is copied much earlier than the other dotfiles
68+
COPY --chown=developer:developer dotfiles/.vimrc /home/developer/.vimrc
69+
RUN curl -fLo ~/.vim/autoload/plug.vim --create-dirs \
5470
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim \
5571
&& vim +PlugInstall +qall
5672

5773
# Install nvm with node and npm
58-
RUN curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.1/install.sh | bash \
59-
&& . $NVM_DIR/nvm.sh \
74+
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.2/install.sh | bash \
75+
&& . /home/developer/.nvm/nvm.sh \
6076
&& nvm install $NODE_VERSION \
6177
&& nvm alias default $NODE_VERSION \
6278
&& nvm use default
79+
RUN source ~/.bashrc
80+
81+
# Have to manually include the node folder on the path to make
82+
# the following installs possible.
83+
# It gets set automatically by the time we start the container,
84+
# but for some reason it's not ready at this point.
85+
ENV PATH="/home/developer/.nvm/versions/node/v${NODE_VERSION}/bin/:${PATH}"
6386

6487
# Install npm packages
65-
RUN source /root/.bashrc
6688
RUN npm install -g eslint \
6789
&& npm install -g eslint-config-airbnb-base \
6890
&& npm install -g eslint-plugin-import \
91+
&& npm install -g yo \
6992
&& npm install -g jest \
7093
&& npm install -g rxjs \
7194
&& npm install -g typescript \
7295
&& npm install -g http-server
7396

7497
# Copy global dotfiles
75-
COPY dotfiles/.gitconfig /root/.gitconfig
76-
COPY dotfiles/.bash_aliases /root/.bash_aliases
77-
COPY dotfiles/.eslintrc.json /root/.eslintrc.json
78-
COPY dotfiles/jest.config.js /home/developer/jest.config.js
79-
RUN source /root/.bashrc
80-
81-
# Install docker ce so that host docker instances can be manipulated from this env
82-
RUN apt-get update && apt-get install -y -q --no-install-recommends \
83-
apt-transport-https \
84-
ca-certificates \
85-
curl \
86-
gnupg-agent \
87-
software-properties-common
88-
89-
RUN curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
90-
RUN add-apt-repository \
91-
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
92-
$(lsb_release -cs) \
93-
stable"
94-
95-
RUN apt-get update && apt-get install -y -q --no-install-recommends \
96-
docker-ce \
97-
docker-ce-cli \
98-
containerd.io
98+
COPY --chown=developer:developer dotfiles/.gitconfig /home/developer/.gitconfig
99+
COPY --chown=developer:developer dotfiles/.bash_aliases /home/developer/bash_aliases
100+
COPY --chown=developer:developer dotfiles/.eslintrc.json /home/developer/eslintrc.json
101+
COPY --chown=developer:developer dotfiles/jest.config.js /home/developer/jest.config.js
102+
RUN source ~/.bashrc
99103

100104
# Copy project templates with local dotfiles
101-
COPY templates/tdd/ /home/developer/templates/tdd/
102-
COPY dotfiles/jest.config.js /home/developer/templates/tdd/.
103-
COPY dotfiles/.gitignore /home/developer/templates/tdd/.
104-
COPY dotfiles/.eslintrc.json /home/developer/templates/tdd/.
105+
COPY --chown=developer:developer templates/tdd/ /home/developer/templates/tdd/
106+
COPY --chown=developer:developer dotfiles/jest.config.js /home/developer/templates/tdd/.
107+
COPY --chown=developer:developer dotfiles/.gitignore /home/developer/templates/tdd/.
108+
COPY --chown=developer:developer dotfiles/.eslintrc.json /home/developer/templates/tdd/.
105109

106-
COPY templates/express-app/ /home/developer/templates/express-app/
107-
COPY dotfiles/.gitignore /home/developer/templates/express-app/.
108-
COPY dotfiles/.eslintrc.json /home/developer/templates/express-app/.
110+
COPY --chown=developer:developer templates/express-app/ /home/developer/templates/express-app/
111+
COPY --chown=developer:developer dotfiles/.gitignore /home/developer/templates/express-app/.
112+
COPY --chown=developer:developer dotfiles/.eslintrc.json /home/developer/templates/express-app/.
109113

110-
COPY templates/webpack-es6/ /home/developer/templates/webpack-es6/
111-
COPY dotfiles/.gitignore /home/developer/templates/webpack-es6/.
112-
COPY dotfiles/.eslintrc.json /home/developer/templates/webpack-es6/.
114+
COPY --chown=developer:developer templates/webpack-es6/ /home/developer/templates/webpack-es6/
115+
COPY --chown=developer:developer dotfiles/.gitignore /home/developer/templates/webpack-es6/.
116+
COPY --chown=developer:developer dotfiles/.eslintrc.json /home/developer/templates/webpack-es6/.
113117

114-
LABEL version="1.1.7"
118+
LABEL version="2.1.1"

0 commit comments

Comments
 (0)