Skip to content

Commit b155b53

Browse files
committed
Running in docker using compose
1 parent 9005890 commit b155b53

File tree

6 files changed

+85
-7
lines changed

6 files changed

+85
-7
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ erl_crash.dump
2323
# variables.
2424
/config/prod.secret.exs
2525
registry/data/docker
26+
pgdata

README.md

+35-5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ Beanie is still very much WIP and experimental. Feedback is welcome!
1212

1313
## Setup
1414

15+
### Running locally
16+
1517
The usual Phoenix workflow applies here. This assumes you have
1618
Elixir, Phoenix, and Postgres installed. Eventually I will make a
1719
Dockerfile for this and post the image on Dockerhub to make this
@@ -29,7 +31,7 @@ The included [docker-compose.yml](docker-compose.yml) can launch a
2931
simple registry locally.
3032

3133
```
32-
docker-compose up -d
34+
docker-compose up -d registry
3335
```
3436

3537
Configure the repository via [config/config.exs](config/config.exs).
@@ -42,14 +44,42 @@ config :beanie,
4244
```
4345

4446
**NOTE** If you change your registry, you should reset the database by
45-
calling
47+
calling `mix ecto.reset`.
48+
49+
### Running in docker
50+
51+
Pull the images by running `docker-compose pull`. Then lanuch the
52+
registry and postgres databases:
4653

4754
```
48-
mix ecto.drop
49-
mix ecto.create
50-
mix ecto.migrate
55+
docker-compose up -d registry
56+
docker-compose up -d postgres
57+
```
58+
59+
Build the node modules and your static assets:
60+
61+
```
62+
docker-compose run --rm node npm install
63+
docker-compose run --rm node ./node_modules/brunch/bin/brunch build
5164
```
5265

66+
Build the application:
67+
68+
```
69+
rm -rf deps _build
70+
docker-compose run --rm mix deps.get
71+
docker-compose run --rm mix compile
72+
docker-compose run --rm mix phoenix.digest
73+
```
74+
75+
Then run it:
76+
77+
```
78+
docker-compose up web
79+
```
80+
81+
### Creating images in the local repository
82+
5383
For development, you can build and push some small images using
5484
[test_image/tiny.Dockerfile](test_image/tiny.Dockerfile). The image
5585
will contain the file message.txt, so if you want to change the image,

config/prod.exs

+13-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,16 @@ config :beanie, Beanie.Endpoint,
1717
cache_static_manifest: "priv/static/manifest.json"
1818

1919
# Do not print debug messages in production
20-
config :logger, level: :info
20+
config :logger, level: :debug
21+
22+
# Configure your database
23+
config :beanie, Beanie.Repo,
24+
adapter: Ecto.Adapters.Postgres,
25+
username: "postgres",
26+
password: "postgres",
27+
database: "beanie_prod",
28+
hostname: "postgres",
29+
pool_size: 10
2130

2231
# ## SSL Support
2332
#
@@ -56,6 +65,9 @@ config :logger, level: :info
5665
# config :beanie, Beanie.Endpoint, server: true
5766
#
5867

68+
config :beanie,
69+
docker_registry: [:at_url, ["https://registry:5000", "testuser", "testpasswd"]]
70+
5971
# Finally import the config/prod.secret.exs
6072
# which should be versioned separately.
6173
import_config "prod.secret.exs"

docker-compose.yml

+29
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,32 @@ registry:
1212
- ./registry/data:/var/lib/registry
1313
- ./registry/auth:/auth
1414
- ./registry/certs:/certs
15+
postgres:
16+
image: postgres:9.5.4
17+
environment:
18+
PGDATA: /pgdata
19+
POSTGRES_DB: beanie_prod
20+
ports:
21+
- 5432
22+
volumes:
23+
- ./pgdata:/pgdata
24+
node:
25+
image: node:6.5.0
26+
command: /bin/true
27+
working_dir: /beanie
28+
volumes:
29+
- ./:/beanie
30+
web:
31+
image: trenpixster/elixir:1.3.2
32+
command: mix phoenix.server
33+
working_dir: /beanie
34+
environment:
35+
MIX_ENV: prod
36+
PORT: 80
37+
ports:
38+
- 80
39+
volumes:
40+
- ./:/beanie
41+
links:
42+
- postgres
43+
- registry

lib/beanie/registry_api/registry.ex

+6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
defmodule Beanie.RegistryAPI.Registry do
22
defstruct(location: nil, user: nil, password: nil, http_client: HTTPotion)
33

4+
require Logger
5+
46
alias Beanie.RegistryAPI.Registry
57

68
def at_url(location, user \\ nil, password \\ nil) do
@@ -22,10 +24,14 @@ defmodule Beanie.RegistryAPI.Registry do
2224
end
2325

2426
def get(registry = %Registry{}, path) do
27+
url = url(registry, path)
28+
Logger.debug("Fetching registry url #{url}")
29+
2530
response = registry.http_client.get!(
2631
url(registry, path),
2732
[basic_auth: {registry.user, registry.password}]
2833
)
34+
Logger.debug("Got '#{response.body}' from #{url}")
2935
Poison.decode!(response.body)
3036
end
3137
end

web/models/repository.ex

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ defmodule Beanie.Repository do
1414
"""
1515
def changeset(struct, params \\ %{}) do
1616
struct
17-
|> cast(params, [:description])
17+
|> cast(params, [:description, :name])
1818
end
1919
end

0 commit comments

Comments
 (0)