This repository has been archived by the owner on May 3, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 369
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #513 from alxbl/update-docker
Update docker image
- Loading branch information
Showing
4 changed files
with
82 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
source 'https://rubygems.org' | ||
|
||
ruby "2.3.3" | ||
ruby "2.3.5" | ||
|
||
gem 'sinatra' | ||
gem 'haml' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# 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` | ||
|
||
``` | ||
# Create a new container called "serpico" and run it in the foreground | ||
docker run --name serpico -p 8443:8443 -v"$(pwd)":/Serpico/db -it serpico | ||
# Stop the container when you no longer need it | ||
docker stop serpico | ||
# Start it again when you need it. It will keep its state. | ||
docker start 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`. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|