Skip to content

Commit

Permalink
further improve the dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
mortbauer committed Feb 16, 2024
1 parent 5ce976f commit fc4618d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 11 deletions.
14 changes: 6 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,34 +38,32 @@ RUN --mount=type=cache,target=/usr/local/bundle/ \
bundle config build.nokogiri "--use-system-libraries" && \
bundle config set --local without 'development test' && \
bundle install -j 4 && \
# apt-get purge -y --auto-remove $buildDeps && \
# rm -Rf /var/lib/apt/lists/* /var/cache/apt/* ~/.gemrc ~/.bundle && \
bundle exec whenever >crontab


FROM builder as compiler

# compile assets with temporary mysql server
RUN --mount=type=cache,target=/usr/local/bundle/ \
export DATABASE_URL=mysql2://localhost/temp?encoding=utf8 && \
export SECRET_KEY_BASE=thisisnotimportantnow && \
export DEBIAN_FRONTEND=noninteractive && \
/etc/init.d/mariadb start && \
mariadb -e "CREATE DATABASE temp" && \
cp config/app_config.yml.SAMPLE config/app_config.yml && \
cp config/cable.yml.SAMPLE config/cable.yml && \
cp config/database.yml.MySQL_SAMPLE config/database.yml && \
cp config/storage.yml.SAMPLE config/storage.yml && \
RAILS_ENV=production bundle exec rake db:setup assets:precompile && \
rm -Rf tmp/* && \
/etc/init.d/mariadb stop && \
rm -Rf /run/mysqld /tmp/* /var/tmp/* /var/lib/mysql /var/log/mysql* && \
cp -r /usr/local/bundle /bundle
# apt-get purge -y --auto-remove mariadb-server && \
# rm -Rf /var/lib/apt/lists/* /var/cache/apt/*

FROM builder as app
COPY --from=compiler /bundle /usr/local/bundle
COPY --from=compiler /usr/src/app/public /usr/src/app/public
COPY --from=compiler /usr/src/app/config /usr/src/app/config

# Make relevant dirs and files writable for app user
RUN mkdir -p tmp storage && \
rsync -ra /bundle/ /usr/local/bundle/ && \
chown nobody config/app_config.yml && \
chown nobody tmp && \
chown nobody storage
Expand Down
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ image-dev:
docker buildx build --tag ${IMAGE_NAME}:${IMAGE_TAG} --progress=plain --target=builder .

image-prod:
docker buildx build --tag ${IMAGE_NAME}:${IMAGE_TAG} --progress=plain .
# docker buildx build --tag ${IMAGE_NAME}:${IMAGE_TAG} --no-cache --progress=plain .
docker buildx build --tag ${IMAGE_NAME}:${IMAGE_TAG} --no-cache --progress=plain --target=app .
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ services:
- ${PWD}/dev_config/app_config.yml:/usr/src/app/config/app_config.yml
- ${PWD}/dev_config/storage.yml:/usr/src/app/config/storage.yml
# - ${PWD}/app:/usr/src/app/app
# - ${PWD}/production_dev.rb:/usr/src/app/config/environments/production.rb
# - ${PWD}/dev_config/environments:/usr/src/app/config/environments/
environment:
# - DATABASE_URL=mysql2://root:secret@mariadb/development?encoding=utf8mb4
- REDIS_URL=redis://redis:6379
Expand Down

0 comments on commit fc4618d

Please sign in to comment.