From ebaaf3f6811c11f5407482628df40198d97c4b83 Mon Sep 17 00:00:00 2001 From: Juan Picado Date: Tue, 8 Nov 2022 07:29:19 +0100 Subject: [PATCH] feat: docker image refactor a new internal binary run (#3475) --- .npmignore | 42 ------------------------------------------ Dockerfile | 35 ++++++++++++++++++++++++++--------- package.json | 1 + 3 files changed, 27 insertions(+), 51 deletions(-) delete mode 100644 .npmignore diff --git a/.npmignore b/.npmignore deleted file mode 100644 index 07c682c1f..000000000 --- a/.npmignore +++ /dev/null @@ -1,42 +0,0 @@ - -## npm -npm-debug.log -yarn-error.log -node_modules -verdaccio-*.tgz -docker-compose.yaml -Dockerfile -crowdin.yaml -scripts/ -src/ -/.* -.vscode/ -.circleci/ -debug/ -docker-examples/ -reports/ -## assets and website -assets/ - -## docs -docs/ -wiki/ - -## flow -flow-typed/ -types/ - -# jest -coverage/ -test-storage* -test/ -__mocks__/ -jestEnvironment.js -test/jest.e2e.config.js -test/jest.config.functional.js -jest.config.js - -# misc -contrib/ -storage_default_storage/ -docker-bin/ diff --git a/Dockerfile b/Dockerfile index b1846fd52..68ef1f21c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,15 +15,19 @@ RUN apk --no-cache add openssl ca-certificates wget && \ WORKDIR /opt/verdaccio-build COPY . . +## build the project and create a tarball of the project for later +## global installation RUN yarn config set npmRegistryServer $VERDACCIO_BUILD_REGISTRY && \ yarn config set enableProgressBars true && \ - yarn config set enableTelemetry false && \ - yarn config set enableGlobalCache false && \ yarn config set enableScripts false && \ - yarn install --immutable && \ - yarn code:docker-build && \ - yarn cache clean && \ - yarn workspaces focus --production + yarn install && \ + yarn code:docker-build +## pack the project +RUN yarn pack --out verdaccio.tgz \ + && mkdir -p /opt/tarball \ + && mv /opt/verdaccio-build/verdaccio.tgz /opt/tarball +## clean up and reduce bundle size +RUN rm -Rf /opt/verdaccio-build FROM node:18.12.0-alpine LABEL maintainer="https://github.com/verdaccio/verdaccio" @@ -38,16 +42,29 @@ ENV PATH=$VERDACCIO_APPDIR/docker-bin:$PATH \ WORKDIR $VERDACCIO_APPDIR +# https://github.com/Yelp/dumb-init RUN apk --no-cache add openssl dumb-init RUN mkdir -p /verdaccio/storage /verdaccio/plugins /verdaccio/conf -COPY --from=builder /opt/verdaccio-build . +COPY --from=builder /opt/tarball . + +USER root +# install verdaccio as a global package so is fully handled by npm +# ensure none dependency is being missing and is prod by default +RUN npm install -g $VERDACCIO_APPDIR/verdaccio.tgz \ + ## clean up cache + && npm cache clean --force \ + && rm -Rf .npm/ \ + && rm $VERDACCIO_APPDIR/verdaccio.tgz \ + # yarn is not need it after this step + && rm -Rf /opt/yarn-v1.22.19/ ADD conf/docker.yaml /verdaccio/conf/config.yaml +ADD docker-bin $VERDACCIO_APPDIR/docker-bin 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 $VERDACCIO_APPDIR/docker-bin && \ + chmod -R +x /usr/local/lib/node_modules/verdaccio/bin/verdaccio $VERDACCIO_APPDIR/docker-bin && \ chown -R $VERDACCIO_USER_UID:root /verdaccio/storage && \ chmod -R g=u /verdaccio/storage /etc/passwd @@ -59,4 +76,4 @@ VOLUME /verdaccio/storage ENTRYPOINT ["uid_entrypoint"] -CMD node -r ./.pnp.js $VERDACCIO_APPDIR/bin/verdaccio --config /verdaccio/conf/config.yaml --listen $VERDACCIO_PROTOCOL://0.0.0.0:$VERDACCIO_PORT +CMD verdaccio --config /verdaccio/conf/config.yaml --listen $VERDACCIO_PROTOCOL://0.0.0.0:$VERDACCIO_PORT diff --git a/package.json b/package.json index 8ca5cc5a8..0570653b9 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ "type": "opencollective", "url": "https://opencollective.com/verdaccio" }, + "files": ["./build", "./index.js", "./conf/"], "dependencies": { "@verdaccio/commons-api": "10.2.0", "@verdaccio/local-storage": "10.3.1",