-
Notifications
You must be signed in to change notification settings - Fork 6
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 #155 from rubyforgood/dev-docker-compose
Basic developer tooling for running the app in Docker
- Loading branch information
Showing
4 changed files
with
144 additions
and
7 deletions.
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,25 @@ | ||
# syntax = docker/dockerfile:1 | ||
|
||
# Make sure RUBY_VERSION matches the Ruby version in .ruby-version and Gemfile | ||
ARG RUBY_VERSION=3.2.3 | ||
FROM ruby:$RUBY_VERSION-slim as base | ||
|
||
# Rails app lives here | ||
WORKDIR /rails | ||
|
||
# Install packages needed to build gems | ||
RUN apt-get update -qq && \ | ||
apt-get install --no-install-recommends -y \ | ||
build-essential libpq-dev curl \ | ||
nodejs npm | ||
RUN npm install -g yarn | ||
|
||
COPY Gemfile Gemfile.lock ./ | ||
RUN bundle install | ||
|
||
COPY package.json yarn.lock ./ | ||
RUN yarn | ||
|
||
# Start the server by default, this can be overwritten at runtime | ||
EXPOSE 3000 | ||
CMD ["./bin/rails", "console"] |
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
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,17 @@ | ||
#!/bin/sh | ||
|
||
# if first argument is help or -h or --help, show help | ||
if [ "$1" = "help" ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]; then | ||
echo "Usage: $0 [command]" | ||
echo " command: command to run in the stocks container" | ||
echo | ||
echo "Examples:" | ||
echo " bin/dc rails db:migrate # run migrations" | ||
echo " bin/dc rails test # run tests" | ||
echo " bin/dc rails console # start Rails console" | ||
echo " bin/dc rails generate model Boop name:string # generate a Rails model" | ||
exit 0 | ||
fi | ||
|
||
echo "\033[2m> docker compose run stocks $@\033[0m" | ||
docker compose run --rm --no-deps stocks $@ |
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,78 @@ | ||
--- | ||
version: "3.9" | ||
services: | ||
redis: | ||
image: redis:7.0 | ||
ports: | ||
- 6379 | ||
healthcheck: | ||
test: ["CMD", "redis-cli", "--raw", "incr", "ping"] | ||
volumes: | ||
- redis:/data | ||
|
||
db: | ||
image: postgres:15 | ||
restart: always | ||
environment: | ||
PGUSER: sif | ||
POSTGRES_USER: sif | ||
POSTGRES_PASSWORD: password | ||
POSTGRES_DB: sif | ||
ports: | ||
- 5432 | ||
healthcheck: | ||
test: ["CMD-SHELL", "pg_isready", "--database", "stocks_in_the_future_development" ] | ||
interval: 10s | ||
volumes: | ||
- postgres:/var/lib/postgresql/data | ||
|
||
stocks: | ||
build: | ||
dockerfile: Dockerfile.dev | ||
context: . | ||
image: stocks:dev | ||
depends_on: | ||
db: | ||
condition: service_healthy | ||
redis: | ||
condition: service_started | ||
healthcheck: | ||
test: ["CMD", "curl", "-f", "http://localhost:${APP_PORT:-3000}"] | ||
command: "bin/docker-entrypoint bin/rails server -b 0.0.0.0 -p ${APP_PORT:-3000}" | ||
entrypoint: bin/docker-entrypoint | ||
ports: | ||
- "${APP_PORT:-3000}:${APP_PORT:-3000}" | ||
volumes: | ||
- .:/rails | ||
- bundler:/usr/local/bundle | ||
- node_modules:/rails/node_modules | ||
environment: | ||
RAILS_ENV: development | ||
DATABASE_URL: postgresql://sif:password@db/ | ||
BROWSERSLIST_IGNORE_OLD_DATA: true | ||
|
||
stocks-js: | ||
image: node:lts-alpine | ||
working_dir: /rails | ||
tty: true | ||
command: sh -c "yarn install && yarn build --watch" | ||
volumes: | ||
- .:/rails | ||
- node_modules:/rails/node_modules | ||
|
||
stocks-css: | ||
image: node:lts-alpine | ||
environment: | ||
BROWSERSLIST_IGNORE_OLD_DATA: true | ||
working_dir: /rails | ||
tty: true | ||
command: sh -c "yarn install && yarn build:css --watch=forever" | ||
volumes: | ||
- .:/rails | ||
- node_modules:/rails/node_modules | ||
|
||
volumes: | ||
redis: | ||
postgres: | ||
bundler: | ||
node_modules: |