From ab9bdb90eb6d9aab65b6c34029e95ed8666fd55a Mon Sep 17 00:00:00 2001 From: Scott J Dickerson Date: Fri, 9 Aug 2024 14:13:38 -0400 Subject: [PATCH] npm-caching-proxy work Signed-off-by: Scott J Dickerson --- hack/npm-caching-proxy/.gitignore | 1 + hack/npm-caching-proxy/Dockerfile_ | 9 +++++ hack/npm-caching-proxy/build_image.sh | 20 +++++++++++ hack/npm-caching-proxy/config/config.yaml | 41 +++++++++++++++++++++++ hack/npm-caching-proxy/run.sh | 19 +++++++++++ 5 files changed, 90 insertions(+) create mode 100644 hack/npm-caching-proxy/.gitignore create mode 100644 hack/npm-caching-proxy/Dockerfile_ create mode 100755 hack/npm-caching-proxy/build_image.sh create mode 100644 hack/npm-caching-proxy/config/config.yaml create mode 100755 hack/npm-caching-proxy/run.sh diff --git a/hack/npm-caching-proxy/.gitignore b/hack/npm-caching-proxy/.gitignore new file mode 100644 index 0000000000..34ff768e38 --- /dev/null +++ b/hack/npm-caching-proxy/.gitignore @@ -0,0 +1 @@ +storage/ diff --git a/hack/npm-caching-proxy/Dockerfile_ b/hack/npm-caching-proxy/Dockerfile_ new file mode 100644 index 0000000000..0a83c14612 --- /dev/null +++ b/hack/npm-caching-proxy/Dockerfile_ @@ -0,0 +1,9 @@ +FROM verdaccio/verdaccio:5 + +ADD config.yaml /verdaccio/conf/config.yaml + +USER root +RUN npm install --global verdaccio-static-token \ + && npm install --global verdaccio-auth-memory + +USER $VERDACCIO_USER_UID diff --git a/hack/npm-caching-proxy/build_image.sh b/hack/npm-caching-proxy/build_image.sh new file mode 100755 index 0000000000..438df26e8c --- /dev/null +++ b/hack/npm-caching-proxy/build_image.sh @@ -0,0 +1,20 @@ +#!/bin/bash -xe + +# +# Build the project's container image using the npm caching proxy that +# has been setup with run.sh +# + +# cd to project root +[[ -e Dockerfile ]] || cd ../.. + +# TODO: Grab the current project config and replace after the run +npm config set registry "http://host.containers.internal:4873" --location=project + # --env "npm_config_registry=http://host.containers.internal:4873" \ + +podman build \ + --pull \ + -t localhost/tackle2-ui:image1 \ + . + +npm config delete registry --location=project diff --git a/hack/npm-caching-proxy/config/config.yaml b/hack/npm-caching-proxy/config/config.yaml new file mode 100644 index 0000000000..612f680006 --- /dev/null +++ b/hack/npm-caching-proxy/config/config.yaml @@ -0,0 +1,41 @@ +# See https://github.com/verdaccio/verdaccio/blob/5.x/conf/docker.yaml +# https://verdaccio.org/docs/configuration + +storage: /verdaccio/storage/data +plugins: /verdaccio/plugins + +web: + title: Verdaccio npm cache + login: false + +auth: + htpasswd: + file: /verdaccio/storage/htpasswd + algorithm: bcrypt + max_users: -1 + +uplinks: + npmjs: + url: https://registry.npmjs.org/ + +packages: + "@*/*": + access: $all + publish: $authenticated + unpublish: $authenticated + proxy: npmjs + + "**": + access: $all + publish: $authenticated + unpublish: $authenticated + proxy: npmjs + +server: + keepAliveTimeout: 60 + +middlewares: + audit: + enabled: true + +log: { type: stdout, format: pretty, level: info } diff --git a/hack/npm-caching-proxy/run.sh b/hack/npm-caching-proxy/run.sh new file mode 100755 index 0000000000..da159eb4be --- /dev/null +++ b/hack/npm-caching-proxy/run.sh @@ -0,0 +1,19 @@ +#!/bin/bash -xe + +# +# userns=keep-id with the uid and gid settings will have podman map +# the uid and gid of the user who runs the container to those uid and +# gid internally so files created on the host belong to the user who +# started the container! +# +podman run \ + -it \ + --rm \ + --name npm-mirror \ + --userns=keep-id:uid=10001,gid=65533 \ + -p 4873:4873 \ + -v ./config:/verdaccio/conf:Z \ + -v ./storage:/verdaccio/storage:Z,U \ + verdaccio/verdaccio:5 \ + $@ +