File tree Expand file tree Collapse file tree 4 files changed +94
-0
lines changed
Expand file tree Collapse file tree 4 files changed +94
-0
lines changed Original file line number Diff line number Diff line change 1+ FROM amazonlinux:2
2+
3+ MAINTAINER Alexis N-o
"[email protected] " 4+
5+ ENV DEFAULT_USER=myrmex
6+ ENV NODE_VERSION_10 10.15.3
7+
8+ # Install gcc add utilities to manage users and permissions
9+ RUN yum install -y gcc-c++ util-linux shadow-utils zlib-devel openssl-devel libffi-devel tar
10+
11+ # Install node v10
12+ # Command "node" defaults to v10
13+ RUN cd /opt &&\
14+ curl -O https://nodejs.org/dist/v${NODE_VERSION_10}/node-v${NODE_VERSION_10}-linux-x64.tar.gz &&\
15+ tar xvzf node-v${NODE_VERSION_10}-linux-x64.tar.gz &&\
16+ ln -s /opt/node-v${NODE_VERSION_10}-linux-x64/bin/node /usr/local/bin/node10 &&\
17+ ln -s /opt/node-v${NODE_VERSION_10}-linux-x64/bin/node /usr/local/bin/node &&\
18+ ln -s /opt/node-v${NODE_VERSION_10}-linux-x64/bin/npm /usr/local/bin/npm &&\
19+ /opt/node-v${NODE_VERSION_10}-linux-x64/bin/npm install -g npm@4
20+
21+ # Add a script to modify the UID / GID for the default user if needed
22+ COPY /usr/local/bin/change-uid /usr/local/bin/change-uid
23+ RUN chmod +x /usr/local/bin/change-uid
24+
25+ # Add a non root user
26+ RUN useradd $DEFAULT_USER -m -d /home/$DEFAULT_USER/ -s /bin/bash
27+
28+ # Create working directory
29+ RUN mkdir /data && chown $DEFAULT_USER:$DEFAULT_USER /data
30+ WORKDIR /data
31+
32+ # Add entrypoint
33+ COPY /entrypoint.sh /entrypoint.sh
34+ RUN chmod +x /entrypoint.sh
35+ ENTRYPOINT ["/entrypoint.sh" ]
36+
37+ # Add default command
38+ COPY /cmd.sh /cmd.sh
39+ RUN chmod +x /cmd.sh
40+ CMD ["/cmd.sh" ]
Original file line number Diff line number Diff line change 1+ #! /bin/bash
2+ set -e
3+
4+ su $DEFAULT_USER -c " npm install --production"
Original file line number Diff line number Diff line change 1+ #! /bin/bash
2+ set -e
3+
4+ if [ ` whoami` == " root" ]; then
5+ echo " Using node v10 runtime"
6+
7+ if [ " $HOST_UID " != " " ]; then
8+ # If the user is root and a HOST_UID environment variable exists,
9+ # we change the myrmex user UID and execute the command as the myrmex user
10+ if [ " $HOST_UID " != ` id -u $DEFAULT_USER ` ]; then
11+ echo " Changing $DEFAULT_USER UID to $HOST_UID "
12+ change-uid $HOST_UID $HOST_GID > /dev/null
13+ fi
14+ fi
15+
16+ fi
17+
18+ exec $@
Original file line number Diff line number Diff line change 1+ #! /bin/sh
2+
3+ # Change the "myrmex" user UID and GID
4+
5+ # Retrieve NEW_ ids to apply
6+ USER=" myrmex"
7+ NEW_UID=$1
8+ NEW_GID=$1
9+ if [ $# -eq 2 ]
10+ then
11+ NEW_GID=$2
12+ elif [ $# -ne 1 ]
13+ then
14+ echo " Usage: change-uid NEW_UID [NEW_GID]"
15+ echo " If NEW_GID is not provided, its value will be the same as NEW_UID"
16+ exit 1
17+ fi
18+
19+ # Retrieve OLD_ ids
20+ OLD_UID=` id -u ${USER} `
21+ OLD_GID=` id -g ${USER} `
22+
23+ # Change the user ids
24+ usermod -u ${NEW_UID} ${USER}
25+ groupmod -g ${NEW_GID} ${USER}
26+
27+ # Change the files ownership
28+ /bin/chown --changes --silent --no-dereference --recursive --from=${OLD_UID} ${NEW_UID} /home
29+ /bin/chown --changes --silent --no-dereference --recursive --from=:${OLD_GID} :${NEW_GID} /home
30+
31+ echo " UID and GID changed from ${OLD_UID} :${OLD_GID} to ${NEW_UID} :${NEW_GID} for \" ${USER} \" "
32+ exit 0
You can’t perform that action at this time.
0 commit comments