n4bb12 / verdaccio-github-oauth-ui

📦🔐 GitHub OAuth plugin for Verdaccio
https://verdaccio.org
MIT License
73 stars 45 forks source link

Bug on plugin load #142

Closed emmanuelm41 closed 2 years ago

emmanuelm41 commented 2 years ago

Bug Report

After adding the plugin to the base docker image on Dockerfile and trying to run the new image, the following error appears.

 warn --- config file  - /verdaccio/conf/config.yaml
[github-oauth-ui] Version: verdaccio-github-oauth-ui@3.2.0
 error--- error loading a plugin github-oauth-ui: TypeError: Cannot read property 'replace' of undefined
    at getMajorVersion (/opt/verdaccio/.yarn/$$virtual/verdaccio-github-oauth-ui-virtual-9d25d7ba2e/0/cache/verdaccio-github-oauth-ui-npm-3.2.0-4b8c0d5db8-ee0a13eb08.zip/node_modules/verdaccio-github-oauth-ui/dist/server.js:843:29)
    at new Verdaccio (/opt/verdaccio/.yarn/$$virtual/verdaccio-github-oauth-ui-virtual-9d25d7ba2e/0/cache/verdaccio-github-oauth-ui-npm-3.2.0-4b8c0d5db8-ee0a13eb08.zip/node_modules/verdaccio-github-oauth-ui/dist/server.js:1786:54)
    at new Plugin (/opt/verdaccio/.yarn/$$virtual/verdaccio-github-oauth-ui-virtual-9d25d7ba2e/0/cache/verdaccio-github-oauth-ui-npm-3.2.0-4b8c0d5db8-ee0a13eb08.zip/node_modules/verdaccio-github-oauth-ui/dist/server.js:2680:22)
    at /opt/verdaccio/build/lib/plugin-loader.js:125:32
    at Array.map (<anonymous>)
    at loadPlugin (/opt/verdaccio/build/lib/plugin-loader.js:62:37)
    at Auth._loadPlugin (/opt/verdaccio/build/lib/auth.js:56:38)
    at new Auth (/opt/verdaccio/build/lib/auth.js:46:25)
    at defineAPI (/opt/verdaccio/build/api/index.js:43:16)
    at _default (/opt/verdaccio/build/api/index.js:130:10)

Versions

Version
node.js on docker
verdaccio 5.x
verdaccio-github-oauth-ui (Plugin) 3.2.0
verdaccio-github-oauth-ui (CLI) -

Expected behavior

Verdaccio should work.

Observed behaviour

Steps to reproduce

1) On branch 5.x, use this docker file to generate the image (I just added one line to install de plugin)

FROM --platform=${BUILDPLATFORM:-linux/amd64} node:14.18.1-alpine as builder

ENV NODE_ENV=production \
    VERDACCIO_BUILD_REGISTRY=https://registry.npmjs.org  \
    HUSKY_SKIP_INSTALL=1 \
    CI=true \
    HUSKY_DEBUG=1

RUN apk --no-cache add openssl ca-certificates wget && \
    apk --no-cache add g++ gcc libgcc libstdc++ linux-headers make python2 && \
    wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub && \
    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

WORKDIR /opt/verdaccio-build
COPY . .

RUN yarn config set npmRegistryServer $VERDACCIO_BUILD_REGISTRY && \
    yarn config set enableProgressBars true && \
    yarn config set enableTelemetry true && \
    yarn config set enableGlobalCache false && \
    yarn install && \
    yarn code:docker-build && \
    yarn cache clean && \
    yarn workspaces focus --production

FROM node:14.18.1-alpine
LABEL maintainer="https://github.com/verdaccio/verdaccio"

ENV VERDACCIO_APPDIR=/opt/verdaccio \
    VERDACCIO_USER_NAME=verdaccio \
    VERDACCIO_USER_UID=10001 \
    VERDACCIO_PORT=4873 \
    VERDACCIO_PROTOCOL=http
ENV PATH=$VERDACCIO_APPDIR/docker-bin:$PATH \
    HOME=$VERDACCIO_APPDIR

WORKDIR $VERDACCIO_APPDIR

RUN apk --no-cache add openssl dumb-init

RUN mkdir -p /verdaccio/storage /verdaccio/plugins /verdaccio/conf

RUN yarn add verdaccio-github-oauth-ui

COPY --from=builder /opt/verdaccio-build .

ADD conf/docker.yaml /verdaccio/conf/config.yaml

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 && \
    chown -R $VERDACCIO_USER_UID:root /verdaccio/storage && \
    chmod -R g=u /verdaccio/storage /etc/passwd

USER $VERDACCIO_USER_UID

EXPOSE $VERDACCIO_PORT

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

2) Set parameters on config.yaml to enable the plugin (add your own GitHub credentials)

middlewares:
  github-oauth-ui:
    enabled: true
  audit:
    enabled: true

auth:
  github-oauth-ui:
    client-id: xxxx
    client-secret: xxxx
    org: xxxx

3) Run the image like any other container

emmanuelm41 commented 2 years ago

For future references, it fails on that branch, but works on 5.3.2 branch