Skip to content

Commit

Permalink
feat(verdaccio): setup production verdaccio
Browse files Browse the repository at this point in the history
  • Loading branch information
anteqkois committed May 25, 2024
1 parent 631fc73 commit 5243b19
Show file tree
Hide file tree
Showing 16 changed files with 3,805 additions and 3,788 deletions.
6 changes: 3 additions & 3 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.scripts
.verdacio
.verdaccio
.vscode
dist
docs
Expand All @@ -12,8 +12,8 @@ tmp
tools
.editorconfig
.dockerignore
.env
.env.*
**.env
**.env.*
!**/.env.prod-build
.eslintignore
.gitignore
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,5 @@ docs/examples/**

.cache
.nx/cache
.verdacio/prod/htpasswd
.verdaccio/prod/htpasswd
.verdaccio/prod/storage
1 change: 0 additions & 1 deletion .npmrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
strict-peer-dependencies=false
auto-install-peers=true
ignore-scripts=true
# registry=http://localhost:4873
2 changes: 1 addition & 1 deletion .verdaccio/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ packages:
proxy: npmjs

# log settings
logs:
log:
type: stdout
format: pretty
level: warn
Expand Down
5 changes: 5 additions & 0 deletions .verdaccio/prod/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Auth

In config file there should be file "htpasswd" which inculde user auth. It can be generated using docker container.

`docker run --rm -v $(pwd)/config:/config --entrypoint htpasswd httpd:2.4 -B -b /config/htpasswd <yourusername> <yourpassword>`
53 changes: 53 additions & 0 deletions .verdaccio/prod/conf/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# path to a directory with all packages
storage: /verdaccio/storage

security:
api:
jwt:
sign:
expiresIn: 365d
notBefore: 1
web:
sign:
expiresIn: 1h

web:
title: Linkerry Package Registry
login: true
# enable: false
metaScripts:
- '<meta name="robots" content="noindex" />'

auth:
# login: true
htpasswd:
file: /verdaccio/conf/htpasswd
max_users: -1
algorithm: bcrypt

# a list of other known repositories we can talk to
uplinks:
npmjs:
url: https://registry.npmjs.org/
maxage: 60m

packages:
'@linkerry/*':
access: $authenticated
publish: $authenticated
'@*/*':
access: $authenticated
publish: $authenticated
proxy: npmjs
'**':
access: $authenticated
publish: $authenticated
proxy: npmjs

log:
type: stdout
format: pretty
level: warn

publish:
allow_offline: true # set offline to true to allow publish offline
1 change: 1 addition & 0 deletions .verdaccio/prod/conf/htpasswd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
local_package_registry:$2y$05$o3qNYY6RKrgllqwsc2nohOAT2C7NheoXv8eLTGFOXRESs2AtwqLT6
64 changes: 0 additions & 64 deletions .verdaccio/prod/config.yml

This file was deleted.

15 changes: 15 additions & 0 deletions .verdaccio/prod/docker-compose.local.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
services:
verdaccio:
image: verdaccio/verdaccio
container_name: verdaccio
ports:
- ${VIRTUAL_PORT}:${VIRTUAL_PORT}
env_file:
- .env
environment:
- VIRTUAL_PORT=${VIRTUAL_PORT}
# - VERDACCIO_APPDIR=/verdaccio/conf
- VERDACCIO_PORT=4873
volumes:
- './storage:/verdaccio/storage'
- './conf:/verdaccio/conf'
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ services:
- LETSENCRYPT_HOST=${LETSENCRYPT_HOST}
- [email protected]
- VIRTUAL_PORT=${VIRTUAL_PORT}
- VERDACCIO_APPDIR=/verdaccio/conf
- VERDACCIO_PORT=4873
volumes:
- './storage:/verdaccio/storage'
- './conf:/verdaccio/conf'
Expand Down
Empty file removed .verdaccio/prod/htpasswd
Empty file.
6 changes: 6 additions & 0 deletions apps/api-gateway/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
strict-peer-dependencies=false
auto-install-peers=true
ignore-scripts=true
# registry=${REGISTRY_USERNAME}:${REGISTRY_PASSWORD}@${REGISTRY_URL}
registry=${REGISTRY_URL}
//${REGISTRY_URL}/:_authToken=${REGISTRY_TOKEN}
13 changes: 13 additions & 0 deletions libs/nest-core/src/lib/package-manager/package-manager.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
import { isEmpty } from '@linkerry/shared'
import { Logger } from '@nestjs/common'
import { exec as execCallback } from 'node:child_process'
import { writeFile } from 'node:fs/promises'
import { join } from 'node:path'
import { promisify } from 'node:util'

const npmrcContent = `
strict-peer-dependencies=false
auto-install-peers=true
ignore-scripts=true
registry=\${REGISTRY_USERNAME}:\${REGISTRY_PASSWORD}@\${REGISTRY_URL}
registry=\${REGISTRY_URL}
//\${REGISTRY_URL}/:_authToken=\${REGISTRY_TOKEN}
`

export const exec = promisify(execCallback)
const logger = new Logger('PackageManager')

Expand Down Expand Up @@ -54,6 +65,8 @@ export const packageManager = {
},

async init({ path }: InitParams): Promise<PackageManagerOutput> {
await writeFile(join(path, '.npmrc'), npmrcContent.trim())

return runCommand(path, 'init')
},

Expand Down
Loading

0 comments on commit 5243b19

Please sign in to comment.