Skip to content

Commit

Permalink
[WIP]
Browse files Browse the repository at this point in the history
  • Loading branch information
Neal Chambers authored and macanudo527 committed Oct 9, 2024
1 parent 6f2c5b5 commit 91d2433
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 99 deletions.
151 changes: 61 additions & 90 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,92 +1,63 @@
FROM ubuntu:20.04

ENV TZ Europe/London

RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

RUN echo "deb http://security.ubuntu.com/ubuntu bionic-security main" >> /etc/apt/sources.list

# Install all the requirements
RUN apt-get update && apt-get install -y \
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

WORKDIR $RAILS_ROOT

FROM base AS development-base
RUN apk add --no-cache --virtual .build-deps build-base postgresql-dev git nodejs yarn

# 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

RUN <<EOF
set -e
# less: Used for 'rails console'
# vim: Used for 'rails credentials:edit'
# chromium-chromedriver: Used for feature specs
apk add --no-cache --virtual .dev-utils \
bash \
curl \
git \
build-essential \
software-properties-common \
wget \
zlib1g-dev \
libreadline-dev \
libyaml-dev \
libffi-dev \
less \
vim \
zlib-dev \
openssl-dev \
readline-dev \
yaml-dev \
sqlite-dev \
sqlite \
libxml2-dev \
libxslt1-dev \
wait-for-it \
imagemagick \
unzip \
libjemalloc-dev \
libssl-dev \
ca-certificates \
gnupg

# Setup ENV variables
ENV PATH /usr/local/src/rbenv/shims:/usr/local/src/rbenv/bin:/usr/local/src/nodenv/shims:/usr/local/src/nodenv/bin:$PATH
ENV RBENV_ROOT /usr/local/src/rbenv
ENV NODENV_ROOT /usr/local/src/nodenv
ENV CONFIGURE_OPTS --disable-install-doc
ENV BUNDLE_PATH /bundles
ENV LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libjemalloc.so

WORKDIR /usr/src/app

# trim spaces and line return from .ruby-version file
COPY .ruby-version .ruby-version.raw
RUN cat .ruby-version.raw | tr -d '\r\t ' > .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)"
libxslt-dev \
libffi-dev \
vips-dev \
chromium-chromedriver
apk add --no-cache bash curl \
&& curl -o /usr/local/bin/wait-for-it https://raw.githubusercontent.com/vishnubob/wait-for-it/master/wait-for-it.sh \
&& chmod +x /usr/local/bin/wait-for-it
EOF

FROM development-base AS yarn-dependencies
COPY package.json yarn.lock ./
RUN yarn install --frozen-lockfile

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
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ gem "active_model_serializers", "0.8.4"
gem 'activerecord-session_store'
gem 'acts-as-taggable-on'
gem 'angularjs-file-upload-rails', '~> 2.4.1'
gem 'bigdecimal', '3.0.2'
gem 'bigdecimal', '3.1.1'
gem 'bootsnap', require: false
gem 'geocoder'
gem 'gmaps4rails'
Expand Down
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ GEM
base64 (0.2.0)
bcp47_spec (0.2.1)
bcrypt (3.1.20)
bigdecimal (3.0.2)
bigdecimal (3.1.1)
bindata (2.5.0)
bindex (0.8.1)
bootsnap (1.18.3)
Expand Down Expand Up @@ -864,7 +864,7 @@ DEPENDENCIES
angularjs-rails (= 1.8.0)
arel-helpers (~> 2.12)
aws-sdk-s3
bigdecimal (= 3.0.2)
bigdecimal (= 3.1.1)
bootsnap
bugsnag
bullet
Expand Down
14 changes: 8 additions & 6 deletions docker-compose.yml → compose.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: '3'

services:
db:
image: postgres:10.19
Expand All @@ -17,7 +15,9 @@ services:
web:
tty: true
stdin_open: true
build: .
build:
target: development
context: .
ports:
- 3000:3000
volumes:
Expand All @@ -32,14 +32,16 @@ services:
OFN_DB_HOST: db
OFN_REDIS_URL: redis://redis/
OFN_REDIS_JOBS_URL: redis://redis
OFN_REDIS_TEST_URL: redis://redis/3
WEBPACKER_DEV_SERVER_HOST: webpack
command: >
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
Expand Down Expand Up @@ -70,7 +72,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:

0 comments on commit 91d2433

Please sign in to comment.