-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Initial attempt at running in Docker. It works, but I think assets might be handled differently. * Add chromium to image and precompile assets - I know this can slow things down, but it should solve the asset delivery issue I was having * Use PG14 * Add ENV vars and healthcheck for db. Add SASS service. * Update app name; add db port; * Use service name postgres instead of db * add docker instructions to readme
- Loading branch information
1 parent
0e60a29
commit fb85ab0
Showing
4 changed files
with
93 additions
and
11 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
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,20 +1,41 @@ | ||
--- | ||
version: '3.8' | ||
services: | ||
postgres: | ||
image: postgres:14 | ||
volumes: | ||
- postgres-data:/var/lib/postgresql/data | ||
environment: | ||
POSTGRES_USER: ${DATABASE_USERNAME} | ||
POSTGRES_PASSWORD: ${DATABASE_PASSWORD} | ||
POSTGRES_DB: pet_rescue_development | ||
|
||
POSTGRES_DB: petrescue_development | ||
POSTGRES_USER: ${DATABASE_USERNAME:-postgres} | ||
POSTGRES_PASSWORD: ${DATABASE_PASSWORD:-password} | ||
ports: | ||
- 5432 | ||
|
||
healthcheck: | ||
test: ["CMD-SHELL", "pg_isready", "-U", "bwoa", "-d", "pet_rescue_development"] | ||
test: ["CMD-SHELL", "pg_isready -U ${DATABASE_USERNAME:-postgres} -d petrescue_development"] | ||
interval: 10s | ||
|
||
app: | ||
build: . | ||
command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -b '0.0.0.0'" | ||
volumes: | ||
- .:/petrescue | ||
ports: | ||
- "3000:3000" | ||
depends_on: | ||
postgres: | ||
condition: service_healthy | ||
environment: | ||
DATABASE_URL: postgres://${DATABASE_USERNAME:-postgres}:${DATABASE_PASSWORD:-password}@postgres:5432/petrescue_development | ||
RAILS_ENV: development | ||
|
||
sass: | ||
build: . | ||
command: bundle exec rails dartsass:watch | ||
volumes: | ||
- db:/var/lib/postgresql/data | ||
- .:/petrescue | ||
depends_on: | ||
app: | ||
condition: service_started | ||
|
||
volumes: | ||
db: | ||
postgres-data: |
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,37 @@ | ||
# Use the official Ruby image as a base | ||
FROM ruby:3.3.0-slim | ||
|
||
# Install dependencies | ||
RUN apt-get update -qq && apt-get install -y \ | ||
nodejs \ | ||
postgresql-client \ | ||
build-essential \ | ||
libpq-dev \ | ||
chromium-driver | ||
|
||
# Set up working directory | ||
WORKDIR /petrescue | ||
|
||
# Copy Gemfile and Gemfile.lock before other files to leverage Docker's caching mechanism | ||
COPY Gemfile /petrescue/Gemfile | ||
COPY Gemfile.lock /petrescue/Gemfile.lock | ||
|
||
# Install gems | ||
RUN gem install bundler && bundle install | ||
|
||
# Copy the rest of the application code | ||
COPY . /petrescue | ||
|
||
# Precompile assets (optional for development, but useful for production) | ||
RUN bundle exec rails assets:precompile | ||
|
||
# Add a script to be executed every time the container starts. | ||
COPY entrypoint.sh /usr/bin/ | ||
RUN chmod +x /usr/bin/entrypoint.sh | ||
|
||
# Expose port 3000 to the Docker host | ||
EXPOSE 3000 | ||
|
||
# Start the Rails server | ||
ENTRYPOINT ["entrypoint.sh"] | ||
CMD ["rails", "server", "-b", "0.0.0.0"] |
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,8 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
# Remove a potentially pre-existing server.pid for Rails. | ||
rm -f /petrescue/tmp/pids/server.pid | ||
|
||
# Then exec the container's main process (what's set as CMD in the Dockerfile). | ||
exec "$@" |