Engineering/DevOps

private Nexus로 npm repository 관리하기

망고v 2023. 8. 29. 11:03

Nexus 구성

Nexus 설치 (Docker)

➜ docker pull sonatype/nexus3
Using default tag: latest
latest: Pulling from sonatype/nexus3
57168402cb72: Pull complete
ccdb07e91e21: Pull complete
713b05c4ae12: Pull complete
da83a81c238e: Pull complete
16447e7f6d34: Pull complete
3f3e8a0af04e: Pull complete
564f69aa8faf: Pull complete
Digest: sha256:919ec9845bd0432ff345044f50b3b1696d92321b458ecd942dbdc7908192ea16
Status: Downloaded newer image for sonatype/nexus3:latest
docker.io/sonatype/nexus3:latest

Nexus 실행

➜ docker run -d -p 8081:8081 --name nexus -e NEXUS_CONTEXT=nexus sonatype/nexus3
631c22da76ec8f23b15d188c1e2343a6c05bb0e4a16aabce51067c1b7e8de593

 

Nexus 접근 확인

http://localhost:8081/nexus

admin 계정의 password는 로그인창에서 친절하게 /nexus-data/admin.password 파일을 확인하라고 하니 참고해서 로그인하면 된다.

 

 

npm Repository 구성

Blob Store 생성

 

Repository 생성

npm(hosted) 선택 & npm-private 생성

npm(group) 선택 & npm-group 생성

생성된 Repository는 Format npm으로 아래 이미지와 같고 URL copy Click하여 URL 복사

 

Local 환경 구성

npm 프로젝트 package.json 수정

{
..생략..
  "private": false,
  "publishConfig": {
    "registry": "http://localhost:8081/nexus/repository/npm-private/"
  },
..생략..

 

Local PC .npmrc 파일 생성

➜  echo -n 'admin:{{nexus패스워드}}' | openssl base64
{{인증값}}

➜  cat ~/.npmrc
registry=http://localhost:8081/nexus/repository/npm-private/
//localhost:8081/nexus/repository/npm-private/:_auth={{인증값}}

npm 프로젝트 / 경로: npm publish

➜  npm publish
..생략..
npm notice === Tarball Details ===
npm notice name:          react-web
npm notice version:       1.0.0
npm notice filename:      react-web-1.0.0.tgz
npm notice package size:  279.8 MB
npm notice unpacked size: 397.3 MB
npm notice shasum:        31097c7a2df87cb8ebc6d981e4bd9037ef3c616a
npm notice integrity:     sha512-ZT6+jBWw0fgwF[...]ucZJ4Lx8qynYA==
npm notice total files:   3958
npm notice
npm notice Publishing to http://localhost:8081/nexus/repository/npm-private/ with tag latest and default access
+ react-web@1.0.0

 

Nexus Upload 확인

 

npm 프로젝트의 node_modules 폴더 이하 package들을 private하게 관리하고 싶다면 해당 폴더에서 publish해서 사용하면 private 환경에서 Build 가능