Introduction

自分でローカルにNugetのサーバーを運用していたのは前からだったんだけど、dockerをきちんと使い始める前の「なんとなく」で使っていたため今いちわかっていなかった。
そのため、今一度最初から復習してみる。

何故自分でローカルのNugetサーバーを作るか、というのは

  1. 本家Nugetに公開する前の確認
  2. 本家Nugetには公開できない社内製ライブラリ用

だと思います。私は前者です。

Resolution

dockerで簡単に動作するPHP製のNugetサーバーを使います。

コンテナ作成

1
2
3
4
5
6
7
8
$ docker pull sunside/simple-nuget-server
$ docker run --detach=true ^
--publish <公開ポート>:80 ^
--env NUGET_API_KEY=<秘密キー> ^
--volume <simple-nuget-server用のマウントフォルダ>/database:/var/www/db ^
--volume <simple-nuget-server用のマウントフォルダ>/packages:/var/www/packagefiles ^
--name nuget-server ^
sunside/simple-nuget-server

1
2
3
4
5
6
7
8
$ docker pull sunside/simple-nuget-server
$ docker run --detach=true ^
--publish 5000:80 ^
--env NUGET_API_KEY=hogehoge ^
--volume /D/VirtualMachines/Docker/volume/simple-nuget-server/database:/var/www/db ^
--volume /D/VirtualMachines/Docker/volume/simple-nuget-server/packages:/var/www/packagefiles ^
--name nuget-server ^
sunside/simple-nuget-server

パッケージの追加

1
2
3
4
5
$ nuget push -Source http://localhost:5000 -ApiKey <NUGET_API_KEY> test.nupkg
Pushing test.nupkg to 'http://localhost:5000'...
PUT http://localhost:5000/api/v2/package/
Created http://localhost:5000/api/v2/package/ 417ms
Your package was pushed.

下記は NuGet Package Explorer でローカルのNugetサーバーの一覧を表示してみた例。
追加されたパッケージが見えます。

パッケージの削除

1
2
3
4
5
6
$ nuget delete -Source http://localhost:5000 -ApiKey <NUGET_API_KEY> test <version>
test <version> will be deleted from the 'http://localhost:5000'. Would you like to continue? (y/N) y
警告: Deleting test <version> from the 'http://localhost:5000'.
DELETE http://localhost:5000/api/v2/package/test/<version>
OK http://localhost:5000/api/v2/package/test/<version> 200ms
test <version> was deleted successfully.