Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Consolidate dockerfiles #462

Draft
wants to merge 14 commits into
base: develop
Choose a base branch
from
56 changes: 38 additions & 18 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,27 +1,47 @@
FROM ruby:3.1.6-slim
MAINTAINER Meedan <[email protected]>
LABEL maintainer=[email protected]

# the Rails stage can be overridden from the caller
ENV RAILS_ENV development
# PROD
# ENV RAILS_ENV=production \
# BUNDLE_DEPLOYMENT=true \
# BUNDLE_WITHOUT=development:test

# DEV
ENV RAILS_ENV=development \
SERVER_PORT=3200

# Set a UTF-8 capabable locale
ENV LC_ALL C.UTF-8
ENV LANG C.UTF-8
ENV LANGUAGE C.UTF-8
ENV LC_ALL=C.UTF-8 \
LANG=C.UTF-8 \
LANGUAGE=C.UTF-8

ENV APP=pender

ARG DIRPATH=/app/pender
ARG BUNDLER_VERSION="2.3.5"

# install dependencies
RUN apt-get update -qq && apt-get install -y curl build-essential git graphicsmagick inotify-tools libpq-dev --no-install-recommends
RUN apt-get update && apt-get install -y curl \
build-essential \
git \
libpq-dev --no-install-recommends

# pender user
RUN mkdir -p ${DIRPATH}
RUN useradd ${APP} -s /bin/bash -m
WORKDIR ${DIRPATH}

# install our app
RUN mkdir -p /app
WORKDIR /app
COPY Gemfile Gemfile.lock /app/
RUN gem install bundler -v "2.3.5" --no-document && bundle install --jobs 20 --retry 5
COPY . /app/

# startup
RUN chmod +x /app/docker-entrypoint.sh
RUN chmod +x /app/docker-background.sh
COPY Gemfile Gemfile.lock ./
RUN gem install bundler -v ${BUNDLER_VERSION} --no-document \
&& bundle install --jobs 20 --retry 5
COPY . ./

USER ${APP}

# DEV
# RUN chmod +x ./bin/docker-entrypoint.sh
EXPOSE 3200
ENTRYPOINT ["./bin/docker-entrypoint.sh"]

CMD ["/app/docker-entrypoint.sh"]
# PROD
# EXPOSE 8000
File renamed without changes.
46 changes: 46 additions & 0 deletions bin/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/bash
if [[ -z ${DEPLOY_ENV+x} || -z ${APP+x} ]]; then
echo "DEPLOY_ENV and APP must be in the environment. Exiting."
exit 1
fi

# pender
if [ "${APP}" = 'pender' ] ; then
if [ "${DEPLOY_ENV}" = 'local' ] ; then
bundle exec rake db:create
bundle exec rake db:migrate
SECRET_KEY_BASE=$(bundle exec rake secret)
export SECRET_KEY_BASE
bundle exec rake lapis:api_keys:create_default
else # qa, live etc
bash /opt/bin/create_configs.sh
echo "--- STARTUP COMPLETE ---"
fi

DIRPATH=${PWD}/tmp
PUMA="${DIRPATH}/puma-${DEPLOY_ENV}.rb"
mkdir -p "${DIRPATH}/pids"
cp config/puma.rb "${PUMA}"
cat << EOF >> "${PUMA}"
pidfile '${DIRPATH}/pids/server-${DEPLOY_ENV}.pid'
environment '${DEPLOY_ENV}'
port ${SERVER_PORT}
EOF

if [ "${DEPLOY_ENV}" = 'local' ] ; then
rm -f "${DIRPATH}/pids/server-${DEPLOY_ENV}.pid"
bundle exec puma -C "${PUMA}"
else # qa, live etc
echo "workers 3" >> "${PUMA}"
bundle exec puma -C "${PUMA}" -t 8:32
fi
# pender-background (sidekiq)
elif [ "${APP}" = 'pender-background' ] ; then
if [ "${DEPLOY_ENV}" = 'local' ] ; then
until curl --silent -XGET --fail "http://pender:${SERVER_PORT}"; do printf '.'; sleep 1; done
else # qa, live etc
bash /opt/bin/create_configs.sh
echo "starting sidekiq"
fi
bundle exec sidekiq
fi
2 changes: 1 addition & 1 deletion config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

# Disable serving static files from the `/public` folder by default since
# Apache or NGINX already handles this.
config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?
config.public_file_server.enabled = true

# Compress JavaScripts and CSS.
config.assets.js_compressor = :uglifier
Expand Down
2 changes: 1 addition & 1 deletion config/environments/profile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

# Disable serving static files from the `/public` folder by default since
# Apache or NGINX already handles this.
config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?
config.public_file_server.enabled = true

# Compress JavaScripts and CSS.
config.assets.js_compressor = :uglifier
Expand Down
7 changes: 0 additions & 7 deletions docker-background.sh

This file was deleted.

9 changes: 6 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,26 @@ services:
- "3200:3200"
- "9555:9555"
volumes:
- ".:/app"
- ".:/app/pender"
depends_on:
- postgres
- redis
- minio
environment:
APP: pender
DEPLOY_ENV: local
RAILS_ENV: development
SERVER_PORT: 3200
pender-background:
build: .
command: /app/docker-background.sh
shm_size: 1G
volumes:
- ".:/app"
- ".:/app/pender"
depends_on:
- pender
environment:
APP: pender-background
DEPLOY_ENV: local
RAILS_ENV: development
SERVER_PORT: 3200
otel-collector:
Expand Down
14 changes: 0 additions & 14 deletions docker-entrypoint.sh

This file was deleted.

46 changes: 0 additions & 46 deletions production/Dockerfile

This file was deleted.

23 changes: 0 additions & 23 deletions production/bin/start.sh

This file was deleted.

12 changes: 0 additions & 12 deletions production/bin/start_background.sh

This file was deleted.

7 changes: 0 additions & 7 deletions production/create-dev-key.rb

This file was deleted.

4 changes: 2 additions & 2 deletions test/setup-parallel
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ echo "Setting up parallel databases for RAILS_ENV=${RAILS_ENV}..."

FAIL=0

rm -rf /app/tmp/cache /app/tmp/cache1 /app/tmp/cache2 /app/tmp/cache3
mkdir -p /app/tmp/cache /app/tmp/cache1 /app/tmp/cache2 /app/tmp/cache3
rm -rf tmp/cache tmp/cache1 tmp/cache2 tmp/cache3
mkdir -p tmp/cache tmp/cache1 tmp/cache2 tmp/cache3

bundle exec rake db:create db:migrate &
TEST_ENV_NUMBER=1 bundle exec rake db:create db:migrate &
Expand Down
Loading