forked from verdaccio/verdaccio
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(docker): multistage build / support for running as random uid
- refactor docker image to use builder multistage pattern - separate storage directories - verdaccio code directories are not user writeable - add generic support for random user uid on environments where the startup user for docker is randomized (e.g. openshift)
- Loading branch information
1 parent
5982515
commit 4862acd
Showing
6 changed files
with
53 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,59 @@ | ||
FROM node:10.7-alpine | ||
LABEL maintainer="https://github.com/verdaccio/verdaccio" | ||
FROM node:10.3-alpine as builder | ||
|
||
RUN apk --no-cache add wget openssl && \ | ||
wget -O /usr/local/bin/dumb-init https://github.com/Yelp/dumb-init/releases/download/v1.2.0/dumb-init_1.2.0_amd64 && \ | ||
chmod +x /usr/local/bin/dumb-init && \ | ||
apk del openssl && \ | ||
apk --no-cache add ca-certificates wget && \ | ||
apk --no-cache add g++ gcc libgcc libstdc++ linux-headers make python && \ | ||
RUN apk --no-cache add openssl ca-certificates wget && \ | ||
wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://raw.githubusercontent.com/sgerrand/alpine-pkg-glibc/master/sgerrand.rsa.pub && \ | ||
wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.25-r0/glibc-2.25-r0.apk && \ | ||
wget -q https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.25-r0/glibc-2.25-r0.apk && \ | ||
apk add glibc-2.25-r0.apk | ||
|
||
ENV APPDIR /usr/local/app | ||
|
||
WORKDIR $APPDIR | ||
|
||
ADD . $APPDIR | ||
WORKDIR /opt/verdaccio-build | ||
COPY . . | ||
|
||
ENV NODE_ENV=production | ||
ENV NODE_ENV=production \ | ||
VERDACCIO_BUILD_REGISTRY=https://registry.npmjs.org/ | ||
|
||
RUN npm config set registry http://registry.npmjs.org/ && \ | ||
yarn global add -s [email protected] && \ | ||
RUN yarn config set registry $VERDACCIO_BUILD_REGISTRY && \ | ||
yarn install --production=false && \ | ||
yarn lint && \ | ||
yarn code:docker-build && \ | ||
yarn build:webui && \ | ||
yarn cache clean && \ | ||
yarn install --production=true --pure-lockfile | ||
|
||
|
||
|
||
FROM node:10.3-alpine | ||
LABEL maintainer="https://github.com/verdaccio/verdaccio" | ||
|
||
RUN apk --no-cache add openssl dumb-init | ||
|
||
RUN mkdir -p /verdaccio/storage /verdaccio/plugins /verdaccio/conf | ||
|
||
ENV VERDACCIO_APPDIR=/opt/verdaccio | ||
WORKDIR $VERDACCIO_APPDIR | ||
|
||
COPY --from=builder /opt/verdaccio-build . | ||
|
||
ADD conf/docker.yaml /verdaccio/conf/config.yaml | ||
|
||
RUN addgroup -S verdaccio && adduser -S -G verdaccio verdaccio && \ | ||
chown -R verdaccio:verdaccio "$APPDIR" && \ | ||
chown -R verdaccio:verdaccio /verdaccio | ||
ENV PATH=${VERDACCIO_APPDIR}/bin:${PATH} \ | ||
HOME=${VERDACCIO_APPDIR} \ | ||
VERDACCIO_USER_NAME=verdaccio \ | ||
VERDACCIO_USER_UID=10001 | ||
|
||
RUN adduser -u ${VERDACCIO_USER_UID} -S -D -h ${VERDACCIO_APPDIR} -g "${VERDACCIO_USER_NAME} user" -s /sbin/nologin ${VERDACCIO_USER_NAME} && \ | ||
chmod -R +x ${VERDACCIO_APPDIR}/bin && \ | ||
chown -R ${VERDACCIO_USER_UID}:root /verdaccio/storage && \ | ||
chmod -R g=u /verdaccio/storage /etc/passwd | ||
|
||
USER verdaccio | ||
USER $VERDACCIO_USER_UID | ||
|
||
ENV PORT 4873 | ||
ENV PROTOCOL http | ||
ENV VERDACCIO_PORT 4873 | ||
ENV VERDACCIO_PROTOCOL http | ||
|
||
EXPOSE $PORT | ||
EXPOSE $VERDACCIO_PORT | ||
|
||
VOLUME ["/verdaccio"] | ||
VOLUME /verdaccio/storage | ||
|
||
ENTRYPOINT ["/usr/local/bin/dumb-init", "--"] | ||
ENTRYPOINT ["uid_entrypoint"] | ||
|
||
CMD $APPDIR/bin/verdaccio --config /verdaccio/conf/config.yaml --listen $PROTOCOL://0.0.0.0:${PORT} | ||
CMD $VERDACCIO_APPDIR/bin/verdaccio --config /verdaccio/conf/config.yaml --listen $VERDACCIO_PROTOCOL://0.0.0.0:${VERDACCIO_PORT} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/bin/sh | ||
|
||
if ! whoami &> /dev/null; then | ||
if [ -w /etc/passwd ]; then | ||
echo "${VERDACCIO_USER_NAME:-default}:x:$(id -u):0:${VERDACCIO_USER_NAME:-default} user:${HOME}:/sbin/nologin" >> /etc/passwd | ||
fi | ||
fi | ||
|
||
exec /usr/bin/dumb-init -- "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters