Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Kagemaru committed Jul 14, 2023
1 parent ebe6e19 commit 62bcafe
Showing 1 changed file with 31 additions and 44 deletions.
75 changes: 31 additions & 44 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,18 @@
ARG RUBY_VERSION="3.2"
ARG BUNDLER_VERSION="2.4.6"
ARG NODEJS_VERSION="16"
ARG YARN_VERSION="1.22.19"
ARG YARN_VERSION

# Packages
ARG BUILD_PACKAGES="libpq-dev npm build-essential"
ARG BUILD_PACKAGES="libpq-dev build-essential"
ARG RUN_PACKAGES="git imagemagick libpq5 libjemalloc-dev libjemalloc2"

# Scripts
ARG PRE_INSTALL_SCRIPT=" \
curl -sL https://deb.nodesource.com/setup_${NODEJS_VERSION}.x -o /tmp/nodesource_setup.sh \
&& bash /tmp/nodesource_setup.sh \
"
ARG INSTALL_SCRIPT="node -v && npm -v && npm install -g yarn && yarn set version ${YARN_VERSION}"
ARG PRE_BUILD_SCRIPT=" \
# The newer ruby images are delivered with Python 3 which breaks the node-sass build
# to counteract this, we build Python 2 ourselves
"
ARG BUILD_SCRIPT="yarn install"
ARG POST_BUILD_SCRIPT=" \
cd frontend \
&& yarn install --no-progress \
&& yarn build-prod \
&& mv -v dist/* ../public \
&& echo \"(built at: $(date '+%Y-%m-%d %H:%M:%S'))\" > /${HOME}/BUILD_INFO \
"
ARG PRE_INSTALL_SCRIPT=""
ARG INSTALL_SCRIPT=""
ARG PRE_BUILD_SCRIPT=""
ARG BUILD_SCRIPT=""
ARG POST_BUILD_SCRIPT="echo \"(built at: $(date '+%Y-%m-%d %H:%M:%S'))\" > /${HOME}/BUILD_INFO"

# Bundler specific
ARG BUNDLE_WITHOUT="development:metrics:test"
Expand All @@ -42,7 +30,7 @@ ARG RAILS_HOST_NAME="unused.example.net"
ARG SECRET_KEY_BASE="needs-to-be-set"

# Runtime ENV vars
ARG HOME=/app-src
ARG HOME="/app-src"
ARG PS1="[\${SENTRY_CURRENT_ENV}] `uname -n`:\${PWD}\$ "
ARG TZ="Europe/Zurich"

Expand Down Expand Up @@ -110,29 +98,13 @@ COPY Gemfile Gemfile.lock ./

RUN bash -vxc "${PRE_BUILD_SCRIPT:-"echo 'no PRE_BUILD_SCRIPT provided'"}"

# TODO: Move to PRE_BUILD_SCRIPT
RUN apt-get install -y --no-install-recommends \
checkinstall libreadline-dev libncursesw5-dev libssl-dev \
libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev
RUN curl https://www.python.org/ftp/python/2.7.18/Python-2.7.18.tgz -o /tmp/python.tgz
RUN mkdir /tmp/python2
RUN tar xzf /tmp/python.tgz -C /tmp/python2
RUN apt-get remove -y python python3
RUN cd /tmp/python2 && mv **/* . && ls -hals
RUN cd /tmp/python2 && ./configure --prefix=/usr/bin
RUN cd /tmp/python2 && make -j8

# Cached ^-----^
RUN apt-get install -y npm
RUN echo $PATH && cd /tmp/python2 && make install -j8

# install gems and build the app
RUN bundle config set --local deployment 'true' \
&& bundle config set --local without ${BUNDLE_WITHOUT} \
&& bundle package \
# && bundle config set --local without ${BUNDLE_WITHOUT} \
# removed, because it has no benefits, since we copy vendor/bundle
# && bundle package \
&& bundle install \
&& bundle clean \
&& bundle exec bootsnap precompile --gemfile
&& bundle exec bootsnap precompile --gemfile app/ lib/

COPY . .

Expand All @@ -151,12 +123,20 @@ RUN bash -vxc "${BUILD_SCRIPT:-"echo 'no BUILD_SCRIPT provided'"}"

RUN bash -vxc "${POST_BUILD_SCRIPT:-"echo 'no POST_BUILD_SCRIPT provided'"}"

RUN bundle exec bootsnap precompile app/ lib/
# RUN bundle exec bootsnap precompile app/ lib/

# TODO: Save artifacts

RUN rm -rf vendor/cache/ .git spec/ node_modules/

#################################
# Frontend Build Stage #
#################################

FROM danlynn/ember-cli:3.28.2 AS frontend-build
WORKDIR /myapp
COPY --from=build /app-src/frontend /myapp
RUN yarn install --frozen-lockfile --no-progress && yarn build-prod

#################################
# Run Stage #
Expand All @@ -178,6 +158,7 @@ ARG RAILS_ENV
# data persisted in the image
ARG PS1
ARG TZ
ARG HOME

ENV HOME="${HOME}" \
PATH="${HOME}/bin:${PATH}" \
Expand Down Expand Up @@ -208,13 +189,15 @@ RUN export DEBIAN_FRONTEND=noninteractive \

# Copy deployment ready source code from build
COPY --from=build ${HOME} ${HOME}
COPY --from=frontend-build /myapp/dist/* ${HOME}/public
WORKDIR ${HOME}

# Create pids folder for puma and
# set group permissions to folders that need write permissions.
# Beware that docker builds on OpenShift produce different permissions
# than local docker builds!
RUN mkdir -p ${HOME}/tmp/pids \
RUN mkdir -p ${HOME}/tmp/pids \
&& mkdir -p ${HOME}/log \
&& chgrp 0 ${HOME} \
&& chgrp -R 0 ${HOME}/tmp \
&& chgrp -R 0 ${HOME}/log \
Expand All @@ -223,11 +206,15 @@ RUN mkdir -p ${HOME}/tmp/pids \
&& chmod -R u+w,g=u ${HOME}/log

# # Install specific versions of dependencies
# RUN gem install bundler:${BUNDLER_VERSION} --no-document

# Use cached gems
RUN bundle config set --local deployment 'true' \
&& bundle config set --local without ${BUNDLE_WITHOUT}
&& bundle config set --local without ${BUNDLE_WITHOUT} \
&& bundle config list \
&& bundle check \
&& exit 1

# RUN bundle install

# These args contain build information. Also see build stage.
# They change with each build, so only define them here for optimal layer caching.
Expand Down

0 comments on commit 62bcafe

Please sign in to comment.