Minimal self-hosting for Hex packages.
Install with:
$ mix escript.install github wojtekmach/nanorepo
Command line usage:
$ nanorepo
Usage:
nanorepo init REPO
Prepares repository hosting for REPO in the current directory.
You may initialize multiple different repositories in the same base directory.
nanorepo publish REPO TARBALL_PATH
Publishes TARBALL_PATH to REPO.
nanorepo rebuild REPO
Rebuilds the given REPO from it's stored tarballs.
nanorepo server [--port PORT]
Serves files stored in `public/` of the current directory.
Options:
* `--port` - defaults to 4000.
$ mkdir playground
$ cd playground
$ nanorepo init acme
$ curl -O https://repo.hex.pm/tarballs/hex_core-0.6.8.tar
$ nanorepo publish acme hex_core-0.6.8.tar
$ nanorepo serve
In another terminal:
$ mix hex.repo add acme http://localhost:4000/acme --public-key /path/to/playground/acme_public_key.pem
$ mix new example
$ cd example
Add the following to your mix.exs
:
{:hex_core, "~> 0.6.0", repo: "acme"}
Finally, run:
$ mix deps.get
The package should be downloaded from your local web server in the first terminal tab.
$ mkdir playground
$ cd playground
$ nanorepo init acme
$ curl -O https://repo.hex.pm/tarballs/hex_core-0.6.8.tar
$ nanorepo publish acme hex_core-0.6.8.tar
$ nanorepo serve
Add the following to ~/.config/rebar3/rebar.config
:
{plugins, [rebar3_hex]}.
{hex, [
{repos, [
#{
name => <<"acme">>,
repo_url => <<"http://localhost:4000/acme">>,
repo_public_key => <<"">> %% get from /path/to/playground/acme_public_key.pem
}
]}
]}.
In another terminal:
$ rebar3 new lib example
Add the following to your rebar.config
:
{erl_opts, [debug_info]}.
{deps, [
{hex_core, "0.6.8"}
]}.
Finally, run:
$ rebar3 deps
The package should be downloaded from your local web server in the first terminal tab.
First, create a bucket on S3. By default, the files stored on S3 are not publicly accessible. You can enable public access by setting the following bucket policy in your bucket's properties:
{
"Version": "2008-10-17",
"Statement": [
{
"Sid": "AllowPublicRead",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::nanorepo/*"
}
]
}
See AWS S3 documentation for more information, especially around making this secure.
Now, let's install AWS CLI.
Finally, set up nanorepo, publish a package, and sync the repo with S3
$ mkdir playground
$ cd playground
$ nanorepo init acme
$ curl -O https://repo.hex.pm/tarballs/hex_core-0.6.8.tar
$ aws s3 sync public/acme s3://nanorepo
Copyright (c) 2020 Wojciech Mach
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.