0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Verdaccio+Docker+EC2 その2-(b) s3 plugin

Posted at

今回仕事で任されたタスクをもう一度最初から作っていきます。

Project

同僚がFrontendチームで使うというVerdaccioを何の前知識もなくDockerizeして使えるようにしていく。元々同僚の頭の中では形があったようだが詳細は全く説明されず、最後あたりで説明された。。。

最終的に設定するもの

  • docker-compose (Verdaccio, Verdaccio s3 plugin, https-portal)
  • Bitbucket pipeline
  • git hooks - post-receive

Usage
Verdaccioアクセスはhttps://<サイト>

A. Publish a package

  1. チームの誰かがパッケージをパブリッシュする。
  2. このパッケージはS3 bucketへ。
  3. BitBucket Pipelineを通してプロダクションにデプロイ。

B. Add a new user

  1. 新規ユーザーを追加>conf/htpasswdに追加される。
  2. BitBucket Pipelineを通してプロダクションにデプロイ。

今回はその2bの設定

  • Verdaccio (Dockerfile, config.yaml)+s3 plugin
  • EC2 (docker, docker-compose, npm)

その2aと違ってサクッと出来ました。


Spec and Software

  • Amazon Ubuntu Server 18.04
  • Verdaccio
  • Docker

Path

/home/ubuntu
└── verdaccio-s3
    ├── Dockerfile
    ├── conf
    │   ├── config.yaml
    │   └── htpasswd <- adduserで作られる
    ├── docker-compose.yaml
    ├── package.json <- publishで必要
    ├── plugins
    └── storage
        └── @mypackage <- publishで追加される

verdaccio/conf/config.yaml

storage: /verdaccio/storage
auth:
  htpasswd:
    file: /verdaccio/conf/htpasswd
store:
  s3-storage:
    bucket: verdaccio-s3
    #keyPrefix: some-prefix # optional, has the effect of nesting all files in a subdirectory
    region: <region> # optional, will use aws s3's default behavior if not specified
    #endpoint: https://{service}.{region}.amazonaws.com # optional, will use aws s3's default behavior if not specified
    #s3ForcePathStyle: false # optional, will use path style URLs for S3 objects
    accessKeyId: <accessKeyId> # optional, aws accessKeyId for private S3 bucket
    secretAccessKey: <secretAccessKey> # optional, aws secretAccessKey for private S3 bucket
uplinks:
  npmjs:
    url: https://registry.npmjs.org/
packages:
  '@mypackage/*': <- ポイント
    access: $authenticated
    publish: $authenticated
  '@*/*':
    access: $authenticated
    publish: $authenticated
    proxy: npmjs
  '**':
    proxy: npmjs
logs:
  - {type: stdout, format: pretty, level: http}

verdaccio/package.json

適当に作る。
npm init
名前は上のポイントに合わせる
"name": "@mypackage/verdaccio",

References

Tips for EC2

  1. その1を参照してください。

Error Messages

  1. その1を参照してください。

Useful commands

docker-compose up --force-recreate
docker exec -it --user=root verdaccio /bin/sh

Testing

1. docker起動
docker-compose up
expected logging

verdaccio    |  warn --- config file  - /verdaccio/conf/config.yaml
verdaccio    |  warn --- Plugin successfully loaded: verdaccio-s3-storage
verdaccio    |  warn --- Plugin successfully loaded: verdaccio-htpasswd
verdaccio    |  warn --- http address - http://0.0.0.0:4873/ - verdaccio/4.2.0

2. URLにアクセス

3. Add a user 'qqq'
npm adduser --registry http://<IP>:4873
expected logging
req: 'PUT /-/user/org.couchdb.user:qqq'

4. Login on URL as 'qqq'
expected logging
req: 'POST /-/verdaccio/login'
req: 'GET /-/verdaccio/packages'

5. Publish
npm publish --registry http://<IP>:4873
expected logging
req: 'PUT /@mypackage%2fverdaccio'

6. Refresh URL
expected logging
req: 'GET /-/verdaccio/packages'

Screenshot 2019-08-06 at 22.22.11.png

7. Check S3

s3screen.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?