Skip to content

Commit

Permalink
Fixes #35593 - Use CentOS 8 Stream for container
Browse files Browse the repository at this point in the history
Currently the container image is based on Fedora 33, but that's long
EOL. Current Fedora versions have Ruby 3.1, but we're unable to use
that. Changing it to CentOS 8 Stream is the closest match and also close
to what we run in production.

It also updates to PostgreSQL 12 which we use in production.

To make docker-compose.yml compatible with podman-compose the port is
changed to a string.

It should be noted that since 36be84a
no assets are served anymore so effectively the UI can no longer be
used. It now uses the RAILS_SERVE_STATIC_FILES env var that the
container already set.

(cherry picked from commit 060eb9b)
  • Loading branch information
ekohl committed Jan 28, 2023
1 parent 9dc1c46 commit 84813d8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 18 deletions.
31 changes: 16 additions & 15 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
# Base container that is used for both building and running the app
FROM registry.fedoraproject.org/fedora-minimal:33 as base
FROM quay.io/centos/centos:stream8 as base
ARG RUBY_VERSION="2.7"
ARG NODEJS_VERSION="12"
ENV FOREMAN_FQDN=foreman.example.com
ENV FOREMAN_DOMAIN=example.com

RUN \
echo -e "[nodejs]\nname=nodejs\nstream=${NODEJS_VERSION}\nprofiles=\nstate=enabled\n" > /etc/dnf/modules.d/nodejs.module && \
echo -e "[ruby]\nname=ruby\nstream=${RUBY_VERSION}\nprofiles=\nstate=enabled\n" > /etc/dnf/modules.d/ruby.module && \
microdnf install -y postgresql-libs ruby{,gems} rubygem-{rake,bundler} npm nc hostname \
# needed for VNC/SPICE websockets
python2-numpy && \
microdnf clean all
dnf module enable ruby:${RUBY_VERSION} nodejs:${NODEJS_VERSION} -y && \
dnf install -y postgresql-libs ruby{,gems} rubygem-{rake,bundler} npm nc hostname && \
dnf clean all

ARG HOME=/home/foreman
WORKDIR $HOME
Expand All @@ -33,22 +30,25 @@ ENV FOREMAN_APIPIE_LANGS=en
ENV BUNDLER_SKIPPED_GROUPS="test development openid libvirt journald facter console"

RUN \
microdnf install -y redhat-rpm-config git \
dnf install -y redhat-rpm-config git-core \
gcc-c++ make bzip2 gettext tar \
libxml2-devel libcurl-devel ruby-devel \
postgresql-devel && \
microdnf clean all
dnf clean all

ENV DATABASE_URL=nulldb://nohost

ARG HOME=/home/foreman
USER 1001
WORKDIR $HOME
COPY --chown=1001:0 . ${HOME}/
# Adding missing gems, for tzdata see https://bugzilla.redhat.com/show_bug.cgi?id=1611117
RUN echo gem '"tzinfo-data"' > bundler.d/container.rb
RUN bundle install --without "${BUNDLER_SKIPPED_GROUPS}" \
--binstubs --clean --path vendor --jobs=5 --retry=3 && \
RUN bundle config set --local without "${BUNDLER_SKIPPED_GROUPS}" && \
bundle config set --local clean true && \
bundle config set --local path vendor && \
bundle config set --local jobs 5 && \
bundle config set --local retry 3
RUN bundle install && \
bundle binstubs --all && \
rm -rf vendor/ruby/*/cache/*.gem && \
find vendor/ruby/*/gems -name "*.c" -delete && \
find vendor/ruby/*/gems -name "*.o" -delete
Expand All @@ -61,7 +61,8 @@ RUN npm install --no-optional && \
./node_modules/webpack/bin/webpack.js --config config/webpack.config.js && npm run analyze && \
# cleanups
rm -rf public/webpack/stats.json ./node_modules vendor/ruby/*/cache vendor/ruby/*/gems/*/node_modules bundler.d/nulldb.rb db/schema.rb && \
bundle install --without "${BUNDLER_SKIPPED_GROUPS}" assets
bundle config without "${BUNDLER_SKIPPED_GROUPS} assets" && \
bundle install

USER 0
RUN chgrp -R 0 ${HOME} && \
Expand All @@ -84,7 +85,7 @@ COPY --from=builder --chown=1001:0 ${HOME}/.bundle/config ${HOME}/.bundle/config
COPY --from=builder --chown=1001:0 ${HOME}/Gemfile.lock ${HOME}/Gemfile.lock
COPY --from=builder --chown=1001:0 ${HOME}/vendor/ruby ${HOME}/vendor/ruby
COPY --from=builder --chown=1001:0 ${HOME}/public ${HOME}/public
RUN echo gem '"tzinfo-data"' > bundler.d/container.rb && rm -rf bundler.d/nulldb.rb bin/spring
RUN rm -rf bundler.d/nulldb.rb bin/spring

RUN date -u > BUILD_TIME

Expand Down
2 changes: 1 addition & 1 deletion config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# config.action_dispatch.rack_cache = true

# Disable Rails's static asset server (Apache or nginx will already do this).
config.public_file_server.enabled = false
config.public_file_server.enabled = ENV.fetch('RAILS_SERVE_STATIC_FILES', false) == 'true'

# Compress JavaScripts and CSS.
config.assets.js_compressor = :uglifier
Expand Down
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ services:
- POSTGRES_DATABASE=foreman
- PGDATA=/var/lib/postgresql/data/pgdata
hostname: db.example.com
image: postgres:10
image: postgres:12
ports:
- 5432
- '5432'
restart: always
healthcheck:
test: ["CMD-SHELL", "nc -z 127.0.0.1 5432 || exit 1"]
Expand Down

0 comments on commit 84813d8

Please sign in to comment.