Skip to content

Commit

Permalink
docker one more time
Browse files Browse the repository at this point in the history
  • Loading branch information
michelson committed Aug 10, 2023
1 parent 5b24492 commit 8e8c7eb
Show file tree
Hide file tree
Showing 3 changed files with 166 additions and 47 deletions.
22 changes: 15 additions & 7 deletions .docker-files/node.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
set -x


# Add NodeJS to sources list
# curl -sL https://deb.nodesource.com/setup_$NODE_MAJOR.x | bash -
curl -fsSL https://deb.nodesource.com/setup_19.x | bash -
# curl -sL https://deb.nodesource.com/setup_18.x | bash -

curl -fsSL https://deb.nodesource.com/setup_stable.x | bash - &&\
apt-get install -y nodejs

#curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
#echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
# apt-get install -y nodejs #to install Node.js 18.x and npm

#17 10.80 ## You may also need development tools to build native addons:
#apt-get install gcc g++ make
#17 10.80 ## To install the Yarn package manager, run:
#curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | gpg --dearmor | sudo tee /usr/share/keyrings/yarnkey.gpg >/dev/null
#echo "deb [signed-by=/usr/share/keyrings/yarnkey.gpg] https://dl.yarnpkg.com/debian stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
#apt-get update && apt-get install yarn

#npm install --global yarn

#apt update
#apt -y install yarn
#corepack enable
#echo yarn -v

npm install -g yarn
# yarn install
24 changes: 19 additions & 5 deletions .docker-files/pg.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
set +x

# Add PostgreSQL to sources list
curl -sSL https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - \
&& echo 'deb http://apt.postgresql.org/pub/repos/apt/ buster-pgdg main' $PG_MAJOR > /etc/apt/sources.list.d/pgdg.list
#curl -sSL https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - \
# && echo 'deb http://apt.postgresql.org/pub/repos/apt/ buster-pgdg main' $PG_MAJOR > /etc/apt/sources.list.d/pgdg.list

# Install PostgreSQL client and libs
apt-get update -qq && \
DEBIAN_FRONTEND=noninteractive apt-get install -yq libpq-dev \
postgresql-client-$PG_MAJOR
#apt-get update -qq && \
# DEBIAN_FRONTEND=noninteractive apt-get install -yq libpq-dev \
# postgresql-client-$PG_MAJOR


# Create the file repository configuration:
sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'

# Import the repository signing key:
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -

# Update the package lists:
apt-get update

# Install the latest version of PostgreSQL.
# If you want a specific version, use 'postgresql-12' or similar instead of 'postgresql':
apt-get -yq install postgresql
167 changes: 132 additions & 35 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,57 +1,154 @@
# Make sure it matches the Ruby version in .ruby-version and Gemfile
# Find eligible builder and runner images on Docker Hub. We use Ubuntu/Debian instead of
# Alpine to avoid DNS resolution issues in production.
#
# https://hub.docker.com/r/hexpm/elixir/tags?page=1&name=ubuntu
# https://hub.docker.com/_/ubuntu?tab=tags
#
#
# This file is based on these images:
#
# - https://hub.docker.com/r/hexpm/elixir/tags - for the build image
# - https://hub.docker.com/_/debian?tab=tags&page=1&name=bullseye-20220801-slim - for the release image
# - https://pkgs.org/ - resource for finding needed packages
# - Ex: hexpm/elixir:1.13.4-erlang-25.0.4-debian-bullseye-20220801-slim
#
ARG RUBY_VERSION=3.2.0
FROM ruby:$RUBY_VERSION
ARG OTP_VERSION=25.0.4
ARG DISTRO=ubuntu
ARG DEBIAN_VERSION=bionic-20210930
ARG DEFAULT_LOCALE=en

# Install libvips for Active Storage preview support
RUN apt-get update -qq && \
apt-get install -y build-essential libvips && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* /usr/share/doc /usr/share/man
ARG PG_MAJOR=14
ARG NODE_MAJOR=18
ARG YARN_VERSION=1.13.0

ARG BUILDER_IMAGE="ruby:$RUBY_VERSION-slim-buster"
ARG RUNNER_IMAGE="${DISTRO}:${DEBIAN_VERSION}"

COPY --from=mwader/static-ffmpeg:4.1.4-2 /ffmpeg /ffprobe /usr/local/bin/
FROM ${BUILDER_IMAGE} as builder


# Copy Installers
RUN mkdir -p /docker-files
COPY .docker-files/ /docker-files
RUN chmod +x /docker-files/*.sh

# Install Dependencies
RUN /docker-files/deps.sh

# Install PostgreSQL
# RUN /docker-files/pg.sh

RUN apt-get install -y postgresql-client

# Install NodeJS, Yarn
RUN /docker-files/node.sh

# install build dependencies
RUN apt-get update -y && apt-get install -y build-essential git \
&& apt-get clean && rm -f /var/lib/apt/lists/*_*

# prepare build dir
WORKDIR /app

ENV LANG=C.UTF-8 BUNDLE_JOBS=4 BUNDLE_RETRY=3

# Upgrade RubyGems and install required Bundler version
RUN gem update --system && \
gem install bundler:$BUNDLER_VERSION

# Change permissions for GEM_HOME
RUN chmod -R 777 $GEM_HOME

# Add docker user
RUN adduser --disabled-password --gecos "" docker && adduser docker staff

COPY --from=realies/audiowaveform /usr/local/bin/audiowaveform /usr/local/bin/
# Create and change app directory permissions
RUN mkdir /usr/src/app
RUN chown -R docker:docker /usr/src/app


# Rails app lives here
WORKDIR /rails
# set build ENV
ENV RAILS_ENV="prod"
ENV DEFAULT_LOCALE $DEFAULT_LOCALE

# Set production environment
ENV RAILS_LOG_TO_STDOUT="1" \
RAILS_SERVE_STATIC_FILES="true" \
RAILS_ENV="production" \
BUNDLE_WITHOUT="development"

# Install application gems
COPY Gemfile Gemfile.lock ./
RUN bundle install
# install mix dependencies
COPY mix.exs mix.lock ./
RUN mix deps.get --only $MIX_ENV
RUN mkdir config

# Copy application code
COPY . .
# copy compile-time config files before we compile dependencies
# to ensure any relevant config change will trigger the dependencies
# to be re-compiled.
# Bundler install gems
WORKDIR /tmp
COPY Gemfile Gemfile.lock /tmp/
RUN bundle install -j ${BUNDLE_JOBS} --retry ${BUNDLE_RETRY}
# Clean up APT when done
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* && \
truncate -s 0 /var/log/*log

# Precompile bootsnap code for faster boot times
RUN bundle exec bootsnap precompile --gemfile app/ lib/
# Ensure setuid and setgid permissions are removed
RUN find / -perm /6000 -type f -exec chmod a-s {} \; || true

# Precompiling assets for production without requiring secret RAILS_MASTER_KEY
# RUN SECRET_KEY_BASE_DUMMY=1 bundle exec rails assets:precompile
# Change user and set workdir
USER docker
WORKDIR /usr/src/app

RUN curl -fsSL https://deb.nodesource.com/setup_19.x | bash -
RUN apt-get install -y nodejs
# Copy app source into container
COPY --chown=docker:docker . /usr/src/app/

RUN npm install -g yarn

RUN echo yarn -v

RUN npm install

# Precompile assets - production only
# Clean up temp files and Yarn cache folder
RUN NODE_OPTIONS="--max-old-space-size=2048" \
RAILS_ENV=${APP_ENV} \
DB_ADAPTER=nulldb \
SECRET_KEY_BASE=`bin/rake secret` \
bundle exec rails assets:precompile --trace \
&& echo "done!"
&& rm -rf /usr/src/app/node_modules /usr/src/app/tmp/cache/* /tmp/* \
&& yarn cache clean

# start a new build stage so that the final image will only contain
# the compiled release and other runtime necessities
FROM ${RUNNER_IMAGE}


RUN apt-get update -y && apt-get install -y libstdc++6 openssl \
libncurses5 locales \
imagemagick

COPY --from=mwader/static-ffmpeg:4.1.4-2 /ffmpeg /ffprobe /usr/local/bin/

# Audiowaveform
RUN apt install software-properties-common -y && \
apt-get update && \
add-apt-repository ppa:chris-needham/ppa && \
apt-get update && \
apt-get install audiowaveform -y

RUN apt-get clean && rm -f /var/lib/apt/lists/*_*

# Set the locale
RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && locale-gen

ENV LANG "en_US.UTF-8"
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8

#WORKDIR "/app"
#RUN chown nobody /app

# set runner ENV
# ENV MIX_ENV="prod"

# Only copy the final release from the build stage
# COPY --from=builder --chown=nobody:root /app/_build/${MIX_ENV}/rel/rauversion ./

# Entrypoint prepares the database.
ENTRYPOINT ["/rails/bin/docker-entrypoint"]
#USER nobody

# Start the server by default, this can be overwritten at runtime
EXPOSE 3000
CMD ["./bin/rails", "server"]
#CMD ["/app/bin/server"]

0 comments on commit 8e8c7eb

Please sign in to comment.