diff --git a/Dockerfile b/Dockerfile index cb7e79b08c..6102d08d35 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,92 +1,63 @@ -FROM ubuntu:20.04 +FROM ruby:3.1.4-alpine3.19 AS base +ARG TARGETPLATFORM +ENV LANG=C.UTF-8 \ + LC_ALL=C.UTF-8 \ + TZ=Europe/London \ + RAILS_ROOT=/usr/src/app +RUN apk --no-cache upgrade +RUN apk add --no-cache tzdata +# Only packages required to run Rails in the production environment can be added to `.essentials`. +# postgresql-dev: Required by the postgre gem +# imagemagick, imagemagick-jpeg: Required by the mini_magick gem +# wkhtmltopdf: Required by wicked_pdf and wkhtmltopdf-binary +RUN set -e && \ + apk add --no-cache --virtual .essentials \ + postgresql-client \ + imagemagick \ + imagemagick-jpeg && \ + apk add --no-cache --virtual wkhtmltopdf -ENV TZ Europe/London +WORKDIR $RAILS_ROOT -RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone +FROM base AS development-base +RUN apk add --no-cache --virtual .build-deps build-base postgresql-dev git nodejs yarn -RUN echo "deb http://security.ubuntu.com/ubuntu bionic-security main" >> /etc/apt/sources.list +# Adjust pre-packaged Alpine gems and software to match current version of OpenFoodNetwork +RUN gem install bundler -v '2.4.3' +RUN gem install rake -v '13.2.1' && gem uninstall rake -v '13.0.6' --executables || true -# Install all the requirements -RUN apt-get update && apt-get install -y \ +RUN < .ruby-version - -# Install Rbenv & Ruby -RUN git clone --depth 1 https://github.com/rbenv/rbenv.git ${RBENV_ROOT} && \ - git clone --depth 1 https://github.com/rbenv/ruby-build.git ${RBENV_ROOT}/plugins/ruby-build && \ - echo 'eval "$(rbenv init -)"' >> /etc/profile.d/rbenv.sh && \ - RUBY_CONFIGURE_OPTS=--with-jemalloc rbenv install $(cat .ruby-version) && \ - rbenv global $(cat .ruby-version) - -# Install Postgres -RUN sh -c "echo 'deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main' >> /etc/apt/sources.list.d/pgdg.list" && \ - curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor | tee /etc/apt/trusted.gpg.d/apt.postgresql.org.gpg >/dev/null && \ - apt-get update && \ - apt-get install -yqq --no-install-recommends postgresql-client-10 libpq-dev - - -# trim spaces and line return from .node-version file -COPY .node-version .node-version.raw -RUN cat .node-version.raw | tr -d '\r\t ' > .node-version - -# Install Node and Yarn with Nodenv -RUN git clone --depth 1 https://github.com/nodenv/nodenv.git ${NODENV_ROOT} && \ - git clone --depth 1 https://github.com/nodenv/node-build.git ${NODENV_ROOT}/plugins/node-build && \ - git clone --depth 1 https://github.com/pine/nodenv-yarn-install.git ${NODENV_ROOT}/plugins/nodenv-yarn-install && \ - git clone --depth 1 https://github.com/nodenv/nodenv-package-rehash.git ${NODENV_ROOT}/plugins/nodenv-package-rehash && \ - echo 'eval "$(nodenv init -)"' >> /etc/profile.d/nodenv.sh && \ - nodenv install $(cat .node-version) && \ - nodenv global $(cat .node-version) - -# Install Chrome -RUN wget --quiet -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - && \ - sh -c "echo 'deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main' >> /etc/apt/sources.list.d/google-chrome.list" && \ - apt-get update && \ - apt-get install -fy google-chrome-stable - -# Install Chromedriver -RUN wget https://chromedriver.storage.googleapis.com/2.41/chromedriver_linux64.zip && \ - unzip chromedriver_linux64.zip -d /usr/bin && \ - chmod u+x /usr/bin/chromedriver - -# Copy code and install app dependencies -COPY . /usr/src/app/ - -# Install Bundler -RUN ./script/install-bundler - -# Install front-end dependencies -RUN yarn install - -# Run bundler install in parallel with the amount of available CPUs -RUN bundle install --jobs="$(nproc)" +FROM development-base AS development +COPY . $RAILS_ROOT +COPY Gemfile Gemfile.lock ./ +RUN bundle install --jobs "$(nproc)" +COPY --from=yarn-dependencies $RAILS_ROOT/node_modules ./node_modules diff --git a/docker-compose.yml b/compose.yaml similarity index 88% rename from docker-compose.yml rename to compose.yaml index 7bb7988a8c..50c3a42091 100644 --- a/docker-compose.yml +++ b/compose.yaml @@ -1,5 +1,3 @@ -version: '3' - services: db: image: postgres:10.19 @@ -17,7 +15,9 @@ services: web: tty: true stdin_open: true - build: . + build: + target: development + context: . ports: - 3000:3000 volumes: @@ -37,9 +37,10 @@ services: bash -c "wait-for-it -t 30 db:5432 && rm -f tmp/pids/server.pid && (bundle check || bundle install) && - bundle exec rake db:create && + rake db:create && yarn install && - bundle exec rails s -p 3000 -b '0.0.0.0'" + rake ofn:sample_data && + rails s -p 3000 -b '0.0.0.0'" webpack: build: . command: ./bin/webpack-dev-server @@ -70,7 +71,7 @@ services: command: > bash -c "wait-for-it -t 30 db:5432 && (bundle check || bundle install) && - bundle exec sidekiq -q mailers -q default" + sidekiq -q mailers -q default" volumes: gems: postgres: