diff --git a/Dockerfile b/Dockerfile index 153788483..55a1268fa 100644 --- a/Dockerfile +++ b/Dockerfile @@ -38,17 +38,15 @@ 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 && \ @@ -56,16 +54,16 @@ RUN --mount=type=cache,target=/usr/local/bundle/ \ 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 diff --git a/Makefile b/Makefile index c2520be79..e23c0f59f 100644 --- a/Makefile +++ b/Makefile @@ -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 . diff --git a/docker-compose.yml b/docker-compose.yml index 776930009..eb449e81e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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