• Stars
    star
    191
  • Rank 195,573 (Top 4 %)
  • Language
    Elixir
  • Created almost 5 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

MiniRepo allows self-hosting of Hex packages.

MiniRepo

⚠️ MiniRepo is deprecated in favour of an offical self-hosting solution from the Hex team, mix hex.registry build (available from Hex v0.21+).

MiniRepo allows self-hosting of Hex packages.

Features:

  • Pluggable storage. MiniRepo ships with following adapters:

    • Local filesystem

    • S3

  • Mirroring

  • Publishing packages via HTTP API

  • Hosting of multiple repositories and mirrors

    MiniRepo exposes following URLs for API and repository access:

    • http://some_url/api/

    • http://some_url/repos/

Learn more about Hex specifications here.

Setup

Clone and install dependencies:

git clone [email protected]:wojtekmach/mini_repo.git
cd mini_repo
mix deps.get

Start a development server:

iex -S mix

By default, the development server is configured with two repositories:

  • test_repo is a custom repository

  • hexpm_mirror is a mirror of the official Hex.pm repository, configured to only fetch package decimal.

Both repositories are configured to store files locally. See config/dev.exs for more information.

Make sure to also read "Deployment with releases" section below.

Usage

Once you have the MiniRepo server running, here is how you can use it with Mix or Rebar3.

Usage with Mix

Let's create a new package and publish it to our test_repo repository:

$ mix new foo
$ cd foo

Make following changes to that package's mix.exs:

  def project() do
    [
      app: :foo,
      version: "0.1.0",
      elixir: "~> 1.9",
      start_permanent: Mix.env() == :prod,
      deps: deps(),
      description: "Some description",
      package: package(),
      hex: hex(),
    ]
  end

  defp deps() do
    []
  end

  defp package() do
    [
      licenses: ["Apache-2.0"],
      links: %{}
    ]
  end

  defp hex() do
    [
      api_url: "http://localhost:4000/api/repos/test_repo",
      # make sure to change it, see `auth_token` in config/releases.exs
      api_key: "secret"
    ]
  end

Now publish the package:

$ mix hex.publish package

Finally, let's use this package from another project.

First, configure Hex to use the custom repository:

$ cd /path/to/mini_repo
$ mix hex.repo add test_repo http://localhost:4000/repos/test_repo --public-key priv/test_repo_public.pem

Now, create a new Mix project:

$ mix new bar
$ cd bar

And configure the dependency, note the repo configuration option.

  defp deps() do
    [
      {:foo, "~> 0.1", repo: "test_repo"}
    ]
  end

Since the development server includes a hexpm_mirror repo, let's try that too:

$ HEX_MIRROR_URL=http://localhost:4000/repos/hexpm_mirror mix hex.package fetch decimal 1.8.0

See Hex.pm guide on publishing packages and Hex docs, in particular mix help hex.config, for more information.

Usage with Rebar3

Let's create a new package and publish it to our test_repo repository:

$ rebar3 new lib baz
$ cd baz

Now, let's configure Rebar3 to use our custom repo, put the following into your global rebar3 configuration:

%% ~/.config/rebar3/rebar.config
{plugins, [rebar3_hex]}.
{hex, [
  {repos, [
    #{
      name => <<"test_repo">>,

      %% make sure to change it, see `auth_token` in config/releases.exs
      api_key => <<"secret">>,
      api_url => <<"http://localhost:4000/api/repos/test_repo">>,
      api_repository => undefined,

      repo_url => <<"http://localhost:4000/repos/test_repo">>,
      repo_organization => undefined,
      repo_public_key => <<"-----BEGIN RSA PUBLIC KEY-----
MIIBCgKCAQEAxfUmzcCs9+rHvGiTvethBN0dVNgvJKss2z48mMjgOd9owiBMvHWQ
wBSncGgZHbahVJbz3bRfvKVAi1mgWx1233MlWJHR+qc2iQyXKW35cYsUOJtGAgmM
10kLvKhxKXdMgJASb02logFVuz2Ov3a/blHGDSqH6HCXok7tUY6ZwRIv7+zsQTga
ttpaLngmgGA2vPUQjUHIDSR6+j65szripj7BLyzqfncCcZK0nKYalBkwcXbrOln0
FucLkxYiy1saxxJlfHQ9W7j9YmjbZDDmSgnbJfi2/WpOgclptthYNA9+OYbz9peD
X9EXqozUvq0yXdgoqOnUfzYTrFOHg/MIHQIDAQAB
-----END RSA PUBLIC KEY-----">>
    }
  ]}
]}.

And publish the package specifying the repo:

$ rebar3 hex publish -r test_repo

Finally, let's use this package from another project:

$ rebar3 new lib qux
$ cd qux

Add the dependency to the project's rebar.config:

{erl_opts, [debug_info]}.
{deps, [
  {baz, "0.1.0"}
]}.

And make sure the dependecy was correctly resolved:

$ rebar3 deps
(...)
===> Verifying dependencies...
baz (package 0.1.0)

See Hex.pm guide on publishing packages with Rebar3 and Rebar3 docs for more information.

Deployment with releases

It's recommended to deploy MiniRepo with Elixir releases.

Let's now assemble the release locally:

$ MIX_ENV=prod mix release
* assembling mini_repo-0.1.0 on MIX_ENV=prod
(...)

And start it:

PORT=4000 \
MINI_REPO_URL=http://localhost:4000 \
MINI_REPO_AUTH_TOKEN=secret \
_build/prod/rel/mini_repo/bin/mini_repo start

As you can see, some configuration can be set by adjusting system environment variables, see config/releases.exs

Warning: MiniRepo by default has very basic authorization uses pre-generated public/private keys for repository signing. Make sure to generate your own public/private keys and consider adding authentication that makes sense in your organization.

Also, see mix help release for general information on Elixir releases.

More information

See following modules documentation to learn more about given feature:

Contributing

The goal of MiniRepo is to provide a minimal server that implements Hex specifications. Why minimal? By keeping the project focused on bare minimum we hope it's easy to understand and serves as a good starting point for a more complete solution that makes sense in a given organization. A production grade system should include infrastructure for monitoring, backups, SSL, and more, not to mention features like user management, SSO and such, but that's out of the scope of MiniRepo project.

We welcome anyone to contribute to the project, especially around documentation and guides, but features specific to narrow set of users likely won't be accepted. For a complete and production-grade implementation see source code of Hex.pm, however keep in mind it's optimised for running the public registry for the community and thus have different features and constraints than a self-hosted solution might have.

License

Copyright (c) 2019 Plataformatec Copyright (c) 2020 Dashbit

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.

More Repositories

1

req

Req is a batteries-included HTTP client for Elixir.
Elixir
769
star
2

acme_bank

An example ☂ project
Elixir
748
star
3

mix_install_examples

A collection of simple Elixir scripts that are using Mix.install/2.
Elixir
484
star
4

oop

OOP in Elixir!
Elixir
294
star
5

github_ecto

Ecto adapter for GitHub API
Elixir
120
star
6

elixir-run

Erlang/OTP + Elixir + IEx + Mix in a single executable for Linux/macOS/Windows. Just run Elixir!
Elixir
113
star
7

calendar_interval

Functions for working with calendar intervals
Elixir
66
star
8

hello_beam

Elixir, Erlang, Gleam & LFE code all in the same project!
Erlang
64
star
9

phoenix_example

An example Phoenix app with one-click deployments to different cloud services.
Elixir
62
star
10

rubyfmt

Ruby
46
star
11

minitest-capybara

**Deprecated** Capybara matchers support for minitest unit & spec
Ruby
41
star
12

easyhtml

EasyHTML makes it easy to work with HTML in Elixir.
Elixir
39
star
13

minitest-metadata

Annotate tests with key/value metadata
Ruby
36
star
14

openapi

A proof-of-concept for generating OpenAPI clients in Elixir.
Elixir
28
star
15

calendar_recurrence

Recurrence is an Elixir library for working with recurring dates
Elixir
26
star
16

req_easyhtml

Req plugin for EasyHTML.
Elixir
21
star
17

shipit

ShipIt automates Hex package publishing to avoid common mistakes
Elixir
21
star
18

dotfiles

~wojtek
Shell
20
star
19

embedded_record

Embed objects in a bitmask field. Similar to bitmask-attribute and friends
Ruby
17
star
20

attrs

Yet another attributes on steroids gem
Ruby
17
star
21

ets_ecto

Elixir
16
star
22

easyxml

An experimental easy-to-use XML library for Elixir.
Elixir
13
star
23

system_castore

Elixir
9
star
24

value_inspect

Provides implementation of #inspect that is arguably more readable and can be used in irb.
Ruby
9
star
25

que

Elixir
8
star
26

defc

Elixir
8
star
27

mix_gen_callback

Mix task for generating a callback module for a given behaviour
Elixir
8
star
28

app_manifest

Elixir
8
star
29

beamup-old

Shell
8
star
30

system_target

Elixir
7
star
31

docs_chunks

Erlang
7
star
32

openurl

openurl
Elixir
7
star
33

req_s3

Elixir
6
star
34

jsonapi_ecto

Ecto adapter for any JSON API compatible backend
Elixir
6
star
35

req_hex

Elixir
6
star
36

otp_builds

Shell
6
star
37

beamup

Shell
6
star
38

vim-rename

Rename : Rename a buffer within Vim and on disk (by Christian J. Robinson)
Vim Script
6
star
39

backoff

Elixir
5
star
40

spec

Elixir
5
star
41

req_github_oauth

Elixir
5
star
42

unit

Elixir
5
star
43

bitfield

Elixir
5
star
44

fix

Elixir
5
star
45

poker_elixir

An Elixir library to work with Poker hands.
Elixir
5
star
46

nanorepo

Elixir
5
star
47

otp_docs

Shell
5
star
48

poker

Ruby poker library for evaluating hands
C
4
star
49

global_id

Elixir
4
star
50

goth

Elixir
4
star
51

requests

Elixir
3
star
52

fluentx

Elixir
3
star
53

code_info

Elixir
3
star
54

mix_deps_add

Elixir
3
star
55

docker-beam

Dockerfile
3
star
56

kino_req

Elixir
3
star
57

rebar_ex2erl

Erlang
3
star
58

any_value

Collection of helper methods for testing "shape" of the data
Ruby
3
star
59

req_examples

Elixir
2
star
60

fs

Elixir
2
star
61

token_cache

Elixir
2
star
62

objc

Elixir
2
star
63

modulesdiff

Compare modules & functions between versions
Elixir
2
star
64

phoenix_now

Elixir
2
star
65

iex_help_open

Elixir
2
star
66

twirp_elixir

Elixir
2
star
67

hex_tar

Erlang
2
star
68

decimal_eval

Elixir
2
star
69

changelog

Print changelog of a Hex package
Elixir
2
star
70

sigil_z

Handles the ~Z sigil for UTC date times.
Elixir
2
star
71

mix_zig_cc

Elixir
2
star
72

signups

Experimental app showing how one test can be used on many levels: directly using app logic, against Web UI and API.
Ruby
2
star
73

minitest-capybara-example

Example Rails app for https://github.com/wojtekmach/minitest-capybara
Ruby
2
star
74

spdx

SPDX license list for Elixir
Elixir
2
star
75

automigrate

Elixir
1
star
76

macos_examples

Objective-C
1
star
77

dotlocal

Serve your web app as myapp.local with minimal configuration
Elixir
1
star
78

inspect_record

Elixir
1
star
79

playground

Elixir
1
star
80

readmexec

Readmexec grabs commands from your README and runs them.
Ruby
1
star
81

twittr

Experiment
Elixir
1
star
82

exla

Elixir Client for XLA
C++
1
star
83

wx_demo

Elixir
1
star
84

goth_example

Elixir
1
star
85

chatty

Phoenix chat app. Based on: http://www.youtube.com/watch?v=RPs4SHpSThU
Elixir
1
star
86

catd

Polls for changes in some `foo.d/` directory and concatenates all files into one `foo`
Go
1
star
87

foo

Elixir
1
star
88

wx_examples

Elixir
1
star
89

mr-rebase

A bot that rebases PRs
Elixir
1
star
90

open

Elixir
1
star
91

hippy

JavaScript
1
star
92

bandit_mock

Elixir
1
star
93

cmark_native

Elixir
1
star
94

phoenix_dashboard_clock

Elixir
1
star
95

rss

Elixir
1
star
96

slow_ex_unit

Elixir
1
star
97

elixirsh

Elixir
1
star
98

erl_doc_chunks

Erlang
1
star
99

minimal

Elixir
1
star
100

vcr-proxy

VCR::Proxy records and replays your HTTP interactions.
Ruby
1
star