diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..f9f3d7ace --- /dev/null +++ b/Dockerfile @@ -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 diff --git a/README.md b/README.md index 8f557a17c..03f83c778 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/config/secrets.yml b/config/secrets.yml index 7754895ff..a2c5f33e5 100644 --- a/config/secrets.yml +++ b/config/secrets.yml @@ -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 diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 000000000..86ead4289 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,20 @@ +version: '3' +services: + db: + image: postgres + volumes: + - ./tmp/db:/var/lib/postgresql/data + environment: + - POSTGRES_HOST_AUTH_METHOD=trust + ports: + - 5432:5432 + web: + image: crimethinc:latest + ports: + - "3000:3000" + links: + - db + environment: + - RAILS_ENV=${RAILS_ENV} + extra_hosts: + - "host.docker.internal:host-gateway" diff --git a/script/bootstrap b/script/bootstrap index 9c383bbf0..6d469f614 100755 --- a/script/bootstrap +++ b/script/bootstrap @@ -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' diff --git a/script/setup b/script/setup index 09ce1c5b4..f4fcc956e 100755 --- a/script/setup +++ b/script/setup @@ -5,6 +5,7 @@ require 'pathname' require 'fileutils' +require 'os' include FileUtils # path to your application root. @@ -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'