Split development and production Docker setup

This commit is contained in:
Andreas Nedbal 2023-03-26 17:16:59 +02:00
parent f0e60d4ce8
commit f155d7eb6b
9 changed files with 102 additions and 54 deletions

View file

@ -7,7 +7,8 @@
// Update the 'dockerComposeFile' list if you have more compose files or use different names.
// The .devcontainer/docker-compose.yml file contains any overrides you need/want to make.
"dockerComposeFile": [
"../docker-compose.yml"
"../docker-compose.yml",
"../docker-compose.dev.yml"
],
// The 'service' property is the name of the service for the container that VS Code should

View file

@ -1,8 +0,0 @@
#!/bin/bash
set -e
# Remove a potentially pre-existing server.pid for Rails.
rm -f /app/tmp/pids/server.pid
# Then exec the container's main process (what's set as CMD in the Dockerfile).
exec "$@"

4
.gitignore vendored
View file

@ -55,6 +55,10 @@ Thumbs.db
desktop.ini
### Docker ###
docker-compose.yml
### Editors ###
# Emacs

View file

@ -1,3 +1,5 @@
# Container image for a development Retrospring setup
FROM ruby:3.1
USER root
@ -29,9 +31,6 @@ RUN addgroup --gid ${GID} app \
&& chown "${UID}:${GID}" -R /app/ \
&& chown "${UID}:${GID}" -R /cache/
COPY .docker/entrypoint.sh /usr/bin/
RUN chmod +x /usr/bin/entrypoint.sh
USER app:app
ADD Gemfile* /app/
@ -44,7 +43,5 @@ RUN yarn install
COPY . /app
ENTRYPOINT ["entrypoint.sh"]
EXPOSE 3000
CMD ["rails", "server", "-b", "0.0.0.0"]

8
bin/docker Normal file
View file

@ -0,0 +1,8 @@
#!/usr/bin/env sh
if [ ! -e "docker-compose.yml" ]; then
echo "\033[0;31mdocker-compose.yml not found! Please create the file from the example file before continuing.\033[0m"
exit 1
fi
docker compose -f docker-compose.yml "$@"

8
bin/docker-dev Normal file
View file

@ -0,0 +1,8 @@
#!/usr/bin/env sh
if [ ! -e "docker-compose.yml" ]; then
echo "\033[0;33mdocker-compose.yml not found! Copying example file.\033[0m"
cp docker-compose.example.yml docker-compose.yml
fi
docker compose -f docker-compose.yml -f docker-compose.dev.yml "$@"

22
docker-compose.dev.yml Normal file
View file

@ -0,0 +1,22 @@
version: "3.7"
# development docker-compose setup overrides for Retrospring
# debugging support using rdebug-ide and preconfigured DB credentials
services:
web:
build:
context: .
dockerfile: Containerfile.dev
command: bash -c "rm -f tmp/pids/server.pid && rdebug-ide --skip_wait_for_start --host 0.0.0.0 --port 1234 --dispatcher-port 26162 -- bin/rails s -p 3000 -b '0.0.0.0'"
environment:
- DATABASE_URL=postgres://postgres:justask@postgres/justask_development?pool=25
volumes:
- ./:/app
ports:
- 1234:1234
postgres:
environment:
- POSTGRES_PASSWORD=justask
- POSTGRES_DB=justask_development

View file

@ -0,0 +1,56 @@
version: "3.7"
# NOTE: We don't use Docker in production at Retrospring, so this setup is
# provided as-is and might be broken or could be improved.
#
# If you have experience in production docker setups, feel free to
# send in some patches!
services:
web:
image: ghcr.io/retrospring/retrospring:main
command: bundle exec puma -C config/puma.rb -b tcp://0.0.0.0:3000
depends_on:
- postgres
- redis
environment:
# PROD: define a secret key
# - SECRET_KEY_BASE=seeeecret
# PROD: configure your database credentials (alternatively use ./config/database.yml below)
# - DATABASE_URL=postgres://postgres:justask@postgres/justask_development?pool=25
- RAILS_LOG_TO_STDOUT=true
- SPROCKETS_CACHE=/cache
- REDIS_URL=redis://redis:6379
volumes:
# PROD: configure your database credentials (alternatively use DATABASE_URL above)
# - ./config/database.yml:/opt/retrospring/app/config/database.yml
- ./config/sidekiq.yml:/opt/retrospring/app/config/sidekiq.yml
- ./config/justask.yml:/opt/retrospring/app/config/justask.yml
- ./config/initializers/devise.rb:/opt/retrospring/app/config/initializers/devise.rb
- cache:/cache
ports:
- 3000:3000
redis:
image: redis:6.2.10-alpine
ports:
- 6379:6379
volumes:
- redis:/data
postgres:
image: postgres:10.12
ports:
- 5432:5432
# PROD: define database credentials
# environment:
# - POSTGRES_PASSWORD=justask
# - POSTGRES_DB=justask_production
volumes:
- db:/var/lib/postgresql/data
volumes:
# PROD: in order to persist data over a longer period of time, define filesystem mounts for volumes
db:
redis:
cache:

View file

@ -1,40 +0,0 @@
version: "3.7"
services:
web:
build:
context: .
dockerfile: .docker/ruby/Dockerfile
command: bash -c "rm -f tmp/pids/server.pid && rdebug-ide --skip_wait_for_start --host 0.0.0.0 --port 1234 --dispatcher-port 26162 -- bin/rails s -p 3000 -b '0.0.0.0'"
depends_on:
- postgres
- redis
environment:
- SPROCKETS_CACHE=/cache
- DATABASE_URL=postgres://postgres:justask@postgres/justask_development?pool=25
- REDIS_URL=redis://redis:6379
volumes:
- ./:/app
- cache:/cache
ports:
- 3000:3000
- 1234:1234
redis:
image: redis:6.2.10-alpine
ports:
- 6379:6379
postgres:
image: postgres:10.12
ports:
- 5432:5432
environment:
POSTGRES_PASSWORD: justask
POSTGRES_DB: justask_development
volumes:
- db:/var/lib/postgresql/data
volumes:
db:
cache: