Skip to content
This repository has been archived by the owner on May 3, 2020. It is now read-only.

Commit

Permalink
feat(#388): Updated docker image. Closes #388
Browse files Browse the repository at this point in the history
  • Loading branch information
alxbl committed Oct 5, 2018
1 parent 990d37e commit 90b0f2c
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM ruby:2.3.5
MAINTAINER Serpico

ENV SRP_ROOT /Serpico
WORKDIR $SRP_ROOT
COPY . $SRP_ROOT

RUN bundle install

# Allow DB to be on a shared volume
VOLUME ["$SRP_ROOT/db"]
EXPOSE 8443

CMD ["bash", "scripts/docker.sh"]
49 changes: 49 additions & 0 deletions docs/docker.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Running Inside Docker

The included `Dockerfile` allows to run Serpico inside docker from any system
that supports containers.

By default, Serpico listens on 8443, you can expose it as `443` if you would
like by using `docker run -p 443:8443 ...`

The image needs to first be built.

1. Build the image
2. Map the database location in docker-compose or at `docker run` time.
3. If the database doesn't exist, it will be created with defaults

## Creating the image

This will create a container with the current state of your repository.
The database is not created at this point, and this image is safe for
distribution.

```
docker build -t serpico .
```

The Dockerfile exposes a `VOLUME` at `/Serpico/db` to allow mounting an
external database through `docker-compose` or `docker run -v`.


## Running with `docker run`

```
# In the foreground
docker run --rm -p 8443 -v"$(pwd)":/Serpico/db -it serpico
```

This will store the database locally at `$PWD/master.db` Please note that the
path to the database on the host [must be absolute][1].

[1]: https://docs.docker.com/engine/reference/run/#volume-shared-filesystems

## Caveats

This is a work in progress, so a few things are currently not supported.

- Running a new container with an existing `master.db` will not work because
`first_time.rb` will not run, and there won't be any certificates for SSL.
- `config.json` is not exposed to the host so customization requires rebuilding
the image or accessing it with `docker exec bash`.

12 changes: 12 additions & 0 deletions scripts/docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/bash
# This script is used as the entry point for the docker image.
# It will initialize the database if it isn't already present.

if [ ! -f "$SRP_ROOT/db/master.db" ]; then
echo "First run detected. Initializing database..."
ruby "$SRP_ROOT/scripts/first_time.rb"
fi

# CMD ["ruby", "serpico.rb"]
ruby serpico.rb

0 comments on commit 90b0f2c

Please sign in to comment.