Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

started working on dockerization #3028

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# syntax=docker/dockerfile:1
FROM ruby:3.1.3
WORKDIR /crimethinc
COPY . .
RUN apt-get update -qq && apt-get install -y nodejs postgresql-client

RUN gem install bundler --conservative && gem install os && bundle install

ENTRYPOINT ["rails", "server"]

EXPOSE 3000
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,21 @@ Drop the database, rebuild it, and fill it with seed data.

***

## Docker

### Build it
```sh
docker build -t crimethinc .
```

### Run it

This runs the website rails server and postgres server in two separate containers. This is the recommended way to do things instead of running two seperate services in a single container.

```sh
docker compose up
```

## How to guides…

- [Add a new language to `/languages`](/blob/main/docs/languages.md)
Expand Down
3 changes: 3 additions & 0 deletions config/secrets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
# Make sure the secrets in this file are kept private
# if you're sharing your code publicly.

docker:
secret_key_base: 806f80029116e5db4d4c906d25b9050fd7b844aaf23756b39e50694556ce3f0143783eac22cdca409f6983223ddd631a5047b1dacc06b10544b663ebca818c5d

development:
secret_key_base: 3274374298988534e80a29e9804457a23549d92d44e8ac094e2b12af80482f0c518fb8190ec395b7d5d9041076aa8198bb9692eb0145b44c15ce73eaeb0df46e

Expand Down
20 changes: 20 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
version: '3'
services:
db:
image: postgres
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You probably want to specify a version of the postgres image since data format are not necessary compatible between version, so if you redeploy and a new version has been release it may not boot because the format have change, and we need to migrate the data first.

volumes:
- ./tmp/db:/var/lib/postgresql/data
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if there's a way to specify this volume at runtime or set it to a more generic path, but we don't want production data to be keep in a tmp directory. The best place would probably be something like ~/crimethinc/data where assuming crimethinc has its own user on the host machine.

environment:
- POSTGRES_HOST_AUTH_METHOD=trust
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's how I setup my postgres database in local, but I don't know the best practice related to production and security. Myabe it's better to have a separate password for the database.

ports:
- 5432:5432
web:
image: crimethinc:latest
ports:
- "3000:3000"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, if you don't setup another docker-compose service to front the Crimethinc. Web app like nginx, haproxy or anything else that can be used as a reverse proxy, you'll need to expose the port 3000 to the port 443 of the host machine. But if you do so, it'll also mean you need to handle SSL certificate.

links:
- db
environment:
- RAILS_ENV=${RAILS_ENV}
extra_hosts:
- "host.docker.internal:host-gateway"
4 changes: 4 additions & 0 deletions script/bootstrap
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,9 @@ echo '==> Installing bundler…'
gem install bundler
echo

echo '==> Installing os...'
gem install os
echo

echo '==> All done! Your system is now bootstrapped.'
echo '==> Next up: ./script/setup'
7 changes: 5 additions & 2 deletions script/setup
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

require 'pathname'
require 'fileutils'
require 'os'
include FileUtils

# path to your application root.
Expand All @@ -19,8 +20,10 @@ chdir APP_ROOT do
system! 'gem install bundler --conservative'
system('bundle check') || system!('bundle install')

puts '==> Starting postgresql'
system! 'brew services start postgresql'
if OS.mac? then
puts '==> Starting postgresql'
system! 'brew services start postgresql'
end

puts '==> Preparing database'
system! 'bundle exec rails db:create'
Expand Down