• Stars
    star
    191
  • Rank 202,846 (Top 4 %)
  • Language
    Elixir
  • Created over 5 years ago
  • Updated almost 4 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
955
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
535
star
4

oop

OOP in Elixir!
Elixir
294
star
5

elixir-run

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

github_ecto

Ecto adapter for GitHub API
Elixir
120
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

easyhtml

EasyHTML makes it easy to work with HTML in Elixir.
Elixir
43
star
12

minitest-capybara

**Deprecated** Capybara matchers support for minitest unit & spec
Ruby
41
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
22
star
17

shipit

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

dotfiles

~wojtek
Shell
20
star
19

notebooks

A few example Livebook notebooks.
20
star
20

embedded_record

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

attrs

Yet another attributes on steroids gem
Ruby
17
star
22

ets_ecto

Elixir
16
star
23

phoenix_now

Elixir
14
star
24

easyxml

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

req_s3

Elixir
10
star
26

system_castore

Elixir
9
star
27

php

Elixir
9
star
28

value_inspect

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

que

Elixir
8
star
30

defc

Elixir
8
star
31

app_manifest

Elixir
8
star
32

mix_gen_callback

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

beamup-old

Shell
8
star
34

otp_builds_backup

Shell
7
star
35

req_hex

Elixir
7
star
36

system_target

Elixir
7
star
37

docs_chunks

Erlang
7
star
38

openurl

openurl
Elixir
7
star
39

jsonapi_ecto

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

rustler_playground

Rustler Playground makes it easy to create single-file Rustler applications.
Elixir
6
star
41

global_id

Elixir
6
star
42

beamup

Shell
6
star
43

vim-rename

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

backoff

Elixir
5
star
45

spec

Elixir
5
star
46

req_github_oauth

Elixir
5
star
47

unit

Elixir
5
star
48

bitfield

Elixir
5
star
49

fix

Elixir
5
star
50

poker_elixir

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

nanorepo

Elixir
5
star
52

otp_docs

Shell
5
star
53

poker

Ruby poker library for evaluating hands
C
4
star
54

goth

Elixir
4
star
55

requests

Elixir
3
star
56

fluentx

Elixir
3
star
57

mix_deps_add

Elixir
3
star
58

code_info

Elixir
3
star
59

docker-beam

Dockerfile
3
star
60

kino_req

Elixir
3
star
61

rebar_ex2erl

Erlang
3
star
62

any_value

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

req_examples

Elixir
2
star
64

token_cache

Elixir
2
star
65

fs

Elixir
2
star
66

objc

Elixir
2
star
67

modulesdiff

Compare modules & functions between versions
Elixir
2
star
68

iex_help_open

Elixir
2
star
69

twirp_elixir

Elixir
2
star
70

hex_tar

Erlang
2
star
71

decimal_eval

Elixir
2
star
72

changelog

Print changelog of a Hex package
Elixir
2
star
73

sigil_z

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

mix_zig_cc

Elixir
2
star
75

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
76

minitest-capybara-example

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

spdx

SPDX license list for Elixir
Elixir
2
star
78

macos_examples

Objective-C
1
star
79

automigrate

Elixir
1
star
80

inspect_record

Elixir
1
star
81

dotlocal

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

playground

Elixir
1
star
83

twittr

Experiment
Elixir
1
star
84

exla

Elixir Client for XLA
C++
1
star
85

wx_demo

Elixir
1
star
86

goth_example

Elixir
1
star
87

chatty

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

catd

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

foo

Elixir
1
star
90

wx_examples

Elixir
1
star
91

mr-rebase

A bot that rebases PRs
Elixir
1
star
92

readmexec

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

open

Elixir
1
star
94

hippy

JavaScript
1
star
95

cmark_native

Elixir
1
star
96

phoenix_dashboard_clock

Elixir
1
star
97

rss

Elixir
1
star
98

bandit_mock

Elixir
1
star
99

slow_ex_unit

Elixir
1
star
100

elixirsh

Elixir
1
star