diff --git a/.dockerignore b/.dockerignore index b2decdb69..fe69a29dd 100644 --- a/.dockerignore +++ b/.dockerignore @@ -41,3 +41,7 @@ Capfile config/deploy config/deploy.rb Gemfile.capistrano* + +Dockerfile +Dockerfile-dev +docker-compose.yml diff --git a/.gitignore b/.gitignore index 185b2f74c..ec1dff9ef 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ public/system public/uploads storage vendor/bundle +swagger # no configuration config/*.yml diff --git a/Dockerfile b/Dockerfile index e8f6a4c00..967de0e47 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,52 +1,75 @@ -FROM ruby:2.7 - -RUN supercronicUrl=https://github.com/aptible/supercronic/releases/download/v0.1.3/supercronic-linux-amd64 && \ - supercronicBin=/usr/local/bin/supercronic && \ - supercronicSha1sum=96960ba3207756bb01e6892c978264e5362e117e && \ - curl -fsSL -o "$supercronicBin" "$supercronicUrl" && \ - echo "$supercronicSha1sum $supercronicBin" | sha1sum -c - && \ - chmod +x "$supercronicBin" +FROM ruby:2.7 as base ENV PORT=3000 \ SMTP_SERVER_PORT=2525 \ - RAILS_ENV=production \ RAILS_LOG_TO_STDOUT=true \ RAILS_SERVE_STATIC_FILES=true WORKDIR /usr/src/app -COPY . ./ - # install dependencies and generate crontab -RUN buildDeps='libmagic-dev' && \ +RUN buildDeps='libmagic-dev nodejs chromium' && \ + export DEBIAN_FRONTEND=noninteractive && \ apt-get update && \ apt-get install --no-install-recommends -y $buildDeps && \ echo 'gem: --no-document' >> ~/.gemrc && \ gem install bundler && \ - bundle config build.nokogiri "--use-system-libraries" && \ - bundle install --deployment --without development test -j 4 && \ - apt-get purge -y --auto-remove $buildDeps && \ - rm -Rf /var/lib/apt/lists/* /var/cache/apt/* ~/.gemrc ~/.bundle && \ - \ - bundle exec whenever >crontab + bundle config build.nokogiri "--use-system-libraries" -# compile assets with temporary mysql server -RUN export DATABASE_URL=mysql2://localhost/temp?encoding=utf8 && \ - export SECRET_KEY_BASE=thisisnotimportantnow && \ - export DEBIAN_FRONTEND=noninteractive && \ - apt-get update && \ - apt-get install -y mariadb-server nodejs && \ - /etc/init.d/mariadb start && \ - mariadb -e "CREATE DATABASE temp" && \ - cp config/app_config.yml.SAMPLE config/app_config.yml && \ + +COPY bin bin +COPY plugins plugins +COPY Gemfile Gemfile.lock docker-entrypoint.sh ./ + +# Development +FROM base as development +ENV RAILS_ENV=development \ + CHROMIUM_FLAGS=--no-sandbox + +RUN bundle install + +COPY . ./ + +# generate api spec file using nulldb adapter +RUN cp config/database.yml.NULLDB_SAMPLE config/database.yml && \ + RAILS_ENV=test DB_ADAPTER=nulldb bundle exec rake rswag:specs:swaggerize && \ + rm config/database.yml + +ENTRYPOINT ["./docker-entrypoint.sh"] +CMD ["./proc-start", "web"] + + +# Production + +FROM base as production + +ENV RAILS_ENV=production + +RUN supercronicUrl=https://github.com/aptible/supercronic/releases/download/v0.1.3/supercronic-linux-amd64 && \ + supercronicBin=/usr/local/bin/supercronic && \ + supercronicSha1sum=96960ba3207756bb01e6892c978264e5362e117e && \ + curl -fsSL -o "$supercronicBin" "$supercronicUrl" && \ + echo "$supercronicSha1sum $supercronicBin" | sha1sum -c - && \ + chmod +x "$supercronicBin" + +RUN bundle config set deployment 'true' && \ + bundle install --without development test + +COPY . ./ +COPY --from=development /usr/src/app/swagger/v1/swagger.yaml /usr/src/app/swagger/v1/swagger.yaml + +# copy sample configs +RUN cp config/app_config.yml.SAMPLE config/app_config.yml && \ cp config/database.yml.MySQL_SAMPLE config/database.yml && \ - cp config/storage.yml.SAMPLE config/storage.yml && \ - 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* && \ - apt-get purge -y --auto-remove mariadb-server && \ - rm -Rf /var/lib/apt/lists/* /var/cache/apt/* + cp config/storage.yml.SAMPLE config/storage.yml + +# precompile assets +RUN SECRET_KEY_BASE=42 bundle exec rake assets:precompile + +# Cleanup +RUN apt-get purge -y --auto-remove $buildDeps && \ + rm -Rf tmp/* /var/lib/apt/lists/* /var/cache/apt/* ~/.gemrc ~/.bundle && \ + bundle exec whenever >crontab # Make relevant dirs and files writable for app user RUN mkdir -p tmp storage && \ @@ -61,6 +84,6 @@ EXPOSE 3000 VOLUME /usr/src/app/storage -# cleanup, and by default start web process from Procfile +# by default start web process from Procfile ENTRYPOINT ["./docker-entrypoint.sh"] CMD ["./proc-start", "web"] diff --git a/Dockerfile-dev b/Dockerfile-dev deleted file mode 100644 index 37dce5f6b..000000000 --- a/Dockerfile-dev +++ /dev/null @@ -1,29 +0,0 @@ -FROM ruby:2.7 - -# Install dependencies -RUN deps='libmagic-dev chromium nodejs' && \ - apt-get update && \ - apt-get install --no-install-recommends -y $deps && \ - rm -Rf /var/lib/apt/lists/* /var/cache/apt/* - -ENV PORT=3000 \ - SMTP_SERVER_PORT=2525 \ - RAILS_ENV=development \ - RAILS_LOG_TO_STDOUT=true \ - RAILS_SERVE_STATIC_FILES=true \ - \ - CHROMIUM_FLAGS=--no-sandbox \ - \ - BUNDLE_PATH=/usr/local/bundle \ - BUNDLE_APP_CONFIG=/usr/local/bundle/config - -WORKDIR /app - -RUN gem install bundler -RUN bundle config build.nokogiri "--use-system-libraries" - -EXPOSE 3000 - -# cleanup, and by default start web process from Procfile -ENTRYPOINT ["./docker-entrypoint.sh"] -CMD ["./proc-start", "web"] diff --git a/docker-compose-dev.yml b/docker-compose-dev.yml index b0a325db4..b272265df 100644 --- a/docker-compose-dev.yml +++ b/docker-compose-dev.yml @@ -10,12 +10,12 @@ services: foodsoft_worker: build: context: . - dockerfile: Dockerfile-dev + target: development platform: linux/x86_64 command: ./proc-start worker volumes: - bundle:/usr/local/bundle - - .:/app + - .:/usr/src/app environment: - DATABASE_URL=mysql2://root:secret@mariadb/development?encoding=utf8mb4 - REDIS_URL=redis://redis:6379