mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-11 09:41:40 -05:00
Merge pull request #257 from JoeyEamigh/fix/docker-alternate-postgres-port
Allow alternate Postgres port and DB name in Docker (fixes #88)
This commit is contained in:
commit
291c930218
5 changed files with 63 additions and 49 deletions
25
Dockerfile
25
Dockerfile
|
|
@ -1,18 +1,11 @@
|
|||
FROM ruby:3.3.4-alpine
|
||||
|
||||
ENV APP_PATH /var/app
|
||||
ENV BUNDLE_VERSION 2.5.9
|
||||
ENV BUNDLE_PATH /usr/local/bundle/gems
|
||||
ENV TMP_PATH /tmp/
|
||||
ENV RAILS_LOG_TO_STDOUT true
|
||||
ENV RAILS_PORT 3000
|
||||
|
||||
# Copy entrypoint scripts and grant execution permissions
|
||||
COPY ./dev-docker-entrypoint.sh /usr/local/bin/dev-entrypoint.sh
|
||||
RUN chmod +x /usr/local/bin/dev-entrypoint.sh
|
||||
|
||||
# Copy application files to workdir
|
||||
COPY . $APP_PATH
|
||||
ENV APP_PATH=/var/app
|
||||
ENV BUNDLE_VERSION=2.5.9
|
||||
ENV BUNDLE_PATH=/usr/local/bundle/gems
|
||||
ENV TMP_PATH=/tmp/
|
||||
ENV RAILS_LOG_TO_STDOUT=true
|
||||
ENV RAILS_PORT=3000
|
||||
|
||||
# Install dependencies for application
|
||||
RUN apk -U add --no-cache \
|
||||
|
|
@ -39,7 +32,7 @@ RUN gem install bundler --version "$BUNDLE_VERSION" \
|
|||
# Navigate to app directory
|
||||
WORKDIR $APP_PATH
|
||||
|
||||
COPY Gemfile Gemfile.lock ./
|
||||
COPY Gemfile Gemfile.lock vendor .ruby-version ./
|
||||
|
||||
# Install missing gems
|
||||
RUN bundle config set --local path 'vendor/bundle' \
|
||||
|
|
@ -47,6 +40,10 @@ RUN bundle config set --local path 'vendor/bundle' \
|
|||
|
||||
COPY . ./
|
||||
|
||||
# Copy entrypoint scripts and grant execution permissions
|
||||
COPY ./dev-docker-entrypoint.sh /usr/local/bin/dev-entrypoint.sh
|
||||
RUN chmod +x /usr/local/bin/dev-entrypoint.sh
|
||||
|
||||
EXPOSE $RAILS_PORT
|
||||
|
||||
ENTRYPOINT [ "bundle", "exec" ]
|
||||
|
|
|
|||
|
|
@ -1,39 +1,38 @@
|
|||
FROM ruby:3.3.4-alpine
|
||||
|
||||
ENV APP_PATH /var/app
|
||||
ENV BUNDLE_VERSION 2.5.9
|
||||
ENV BUNDLE_PATH /usr/local/bundle/gems
|
||||
ENV TMP_PATH /tmp/
|
||||
ENV RAILS_LOG_TO_STDOUT true
|
||||
ENV RAILS_PORT 3000
|
||||
ENV APP_PATH=/var/app
|
||||
ENV BUNDLE_VERSION=2.5.9
|
||||
ENV BUNDLE_PATH=/usr/local/bundle/gems
|
||||
ENV TMP_PATH=/tmp/
|
||||
ENV RAILS_LOG_TO_STDOUT=true
|
||||
ENV RAILS_PORT=3000
|
||||
|
||||
# install dependencies for application
|
||||
RUN apk -U add --no-cache \
|
||||
build-base \
|
||||
git \
|
||||
postgresql-dev \
|
||||
postgresql-client \
|
||||
libxml2-dev \
|
||||
libxslt-dev \
|
||||
nodejs \
|
||||
yarn \
|
||||
imagemagick \
|
||||
tzdata \
|
||||
less \
|
||||
# gcompat for nokogiri on mac m1
|
||||
gcompat \
|
||||
&& rm -rf /var/cache/apk/* \
|
||||
&& mkdir -p $APP_PATH
|
||||
|
||||
RUN gem install bundler --version "$BUNDLE_VERSION" \
|
||||
&& rm -rf $GEM_HOME/cache/*
|
||||
|
||||
# copy entrypoint scripts and grant execution permissions
|
||||
COPY ./dev-docker-entrypoint.sh /usr/local/bin/dev-entrypoint.sh
|
||||
COPY ./test-docker-entrypoint.sh /usr/local/bin/test-entrypoint.sh
|
||||
RUN chmod +x /usr/local/bin/dev-entrypoint.sh && chmod +x /usr/local/bin/test-entrypoint.sh
|
||||
|
||||
# install dependencies for application
|
||||
RUN apk -U add --no-cache \
|
||||
build-base \
|
||||
git \
|
||||
postgresql-dev \
|
||||
postgresql-client \
|
||||
libxml2-dev \
|
||||
libxslt-dev \
|
||||
nodejs \
|
||||
yarn \
|
||||
imagemagick \
|
||||
tzdata \
|
||||
less \
|
||||
# gcompat for nokogiri on mac m1
|
||||
gcompat \
|
||||
&& rm -rf /var/cache/apk/* \
|
||||
&& mkdir -p $APP_PATH
|
||||
|
||||
|
||||
RUN gem install bundler --version "$BUNDLE_VERSION" \
|
||||
&& rm -rf $GEM_HOME/cache/*
|
||||
|
||||
# navigate to app directory
|
||||
WORKDIR $APP_PATH
|
||||
|
||||
|
|
|
|||
|
|
@ -11,13 +11,13 @@ default: &default
|
|||
|
||||
development:
|
||||
<<: *default
|
||||
database: dawarich_development
|
||||
database: <%= ENV['DATABASE_NAME'] || 'dawarich_development' %>
|
||||
|
||||
test:
|
||||
<<: *default
|
||||
database: dawarich_test
|
||||
database: <%= ENV['DATABASE_NAME'] || 'dawarich_test' %>
|
||||
|
||||
production:
|
||||
<<: *default
|
||||
database: dawarich_production
|
||||
database: <%= ENV['DATABASE_NAME'] || 'dawarich_production' %>
|
||||
url: <%= ENV['DATABASE_URL'] %>
|
||||
|
|
|
|||
|
|
@ -7,11 +7,18 @@ set -e
|
|||
|
||||
echo "Environment: $RAILS_ENV"
|
||||
|
||||
# set env var defaults
|
||||
DATABASE_HOST=${DATABASE_HOST:-"dawarich_db"}
|
||||
DATABASE_PORT=${DATABASE_PORT:-5432}
|
||||
DATABASE_USERNAME=${DATABASE_USERNAME:-"postgres"}
|
||||
DATABASE_PASSWORD=${DATABASE_PASSWORD:-"password"}
|
||||
DATABASE_NAME=${DATABASE_NAME:-"dawarich_development"}
|
||||
|
||||
# Remove pre-existing puma/passenger server.pid
|
||||
rm -f $APP_PATH/tmp/pids/server.pid
|
||||
|
||||
# Wait for the database to be ready
|
||||
until nc -zv $DATABASE_HOST 5432; do
|
||||
until nc -zv $DATABASE_HOST ${DATABASE_PORT:-5432}; do
|
||||
echo "Waiting for PostgreSQL to be ready..."
|
||||
sleep 1
|
||||
done
|
||||
|
|
@ -21,8 +28,12 @@ gem update --system 3.5.7
|
|||
gem install bundler --version '2.5.9'
|
||||
|
||||
# Create the database
|
||||
echo "Creating database $DATABASE_NAME..."
|
||||
bundle exec rails db:create
|
||||
if [ "$(psql "postgres://$DATABASE_USERNAME:$DATABASE_PASSWORD@$DATABASE_HOST:$DATABASE_PORT" -XtAc "SELECT 1 FROM pg_database WHERE datname='$DATABASE_NAME'")" = '1' ]; then
|
||||
echo "Database $DATABASE_NAME already exists, skipping creation..."
|
||||
else
|
||||
echo "Creating database $DATABASE_NAME..."
|
||||
bundle exec rails db:create
|
||||
fi
|
||||
|
||||
# Run database migrations
|
||||
echo "PostgreSQL is ready. Running database migrations..."
|
||||
|
|
|
|||
|
|
@ -4,8 +4,15 @@ set -e
|
|||
|
||||
echo "Environment: $RAILS_ENV"
|
||||
|
||||
# set env var defaults
|
||||
DATABASE_HOST=${DATABASE_HOST:-"dawarich_db"}
|
||||
DATABASE_PORT=${DATABASE_PORT:-5432}
|
||||
DATABASE_USER=${DATABASE_USER:-"postgres"}
|
||||
DATABASE_PASSWORD=${DATABASE_PASSWORD:-"password"}
|
||||
DATABASE_NAME=${DATABASE_NAME:-"dawarich_development"}
|
||||
|
||||
# Wait for the database to be ready
|
||||
until nc -zv $DATABASE_HOST 5432; do
|
||||
until nc -zv $DATABASE_HOST ${DATABASE_PORT:-5432}; do
|
||||
echo "Waiting for PostgreSQL to be ready..."
|
||||
sleep 1
|
||||
done
|
||||
|
|
|
|||
Loading…
Reference in a new issue