From add53a1ed0918dacf8664b2da6bc6ff3202331c0 Mon Sep 17 00:00:00 2001 From: Hasarinda Thenuwara Date: Mon, 13 Jul 2026 10:24:25 +0930 Subject: [PATCH] Use thermite to install docker --- .dockerignore | 37 ------------- Dockerfile.tt | 121 ------------------------------------------ bin/docker-entrypoint | 21 -------- template.rb | 3 +- templates/puma.rb | 0 5 files changed, 1 insertion(+), 181 deletions(-) delete mode 100644 .dockerignore delete mode 100644 Dockerfile.tt delete mode 100755 bin/docker-entrypoint mode change 100755 => 100644 templates/puma.rb diff --git a/.dockerignore b/.dockerignore deleted file mode 100644 index 9612375..0000000 --- a/.dockerignore +++ /dev/null @@ -1,37 +0,0 @@ -# See https://docs.docker.com/engine/reference/builder/#dockerignore-file for more about ignoring files. - -# Ignore git directory. -/.git/ - -# Ignore bundler config. -/.bundle - -# Ignore all environment files (except templates). -/.env* -!/.env*.erb - -# Ignore all default key files. -/config/master.key -/config/credentials/*.key - -# Ignore all logfiles and tempfiles. -/log/* -/tmp/* -!/log/.keep -!/tmp/.keep - -# Ignore pidfiles, but keep the directory. -/tmp/pids/* -!/tmp/pids/.keep - -# Ignore storage (uploaded files in development and any SQLite databases). -/storage/* -!/storage/.keep -/tmp/storage/* -!/tmp/storage/.keep - -# Ignore assets. -/node_modules/ -/app/assets/builds/* -!/app/assets/builds/.keep -/public/assets diff --git a/Dockerfile.tt b/Dockerfile.tt deleted file mode 100644 index 3fb696b..0000000 --- a/Dockerfile.tt +++ /dev/null @@ -1,121 +0,0 @@ -# syntax=docker/dockerfile:1 -# check=error=true - -ARG APPLICATION_NAME="<%= @app_name %>" -ARG RUBY_VERSION=3.4 - -FROM ruby:$RUBY_VERSION-slim AS base - -ARG PACKAGES="curl libvips libjemalloc2 postgresql-client" - -# Rails app lives here -WORKDIR /rails - -# Install base packages -RUN apt-get update -qq && \ - DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends $PACKAGES && \ - rm -rf /var/lib/apt/lists /var/cache/apt/archives - -ARG APPLICATION_NAME -ARG APPLICATION_VERSION -ARG APPLICATION_REVISION - -# Set production environment -ENV APPLICATION_NAME="${APPLICATION_NAME}" \ - BUNDLE_DEPLOYMENT="1" \ - BUNDLE_PATH="/usr/local/bundle" \ - BUNDLE_WITHOUT="development:test" \ - EXECJS_RUNTIME="Disabled" \ - RAILS_ENV="production" \ - PUMA_SSL="1" \ - TZ="Australia/Adelaide" - -# Create a rails group and user for non-privileged access -RUN groupadd --system --gid 1000 rails && \ - useradd rails --uid 1000 --gid 1000 --create-home --shell /bin/bash && \ - echo "$APPLICATION_NAME ($APPLICATION_VERSION) [$APPLICATION_REVISION]" > /etc/motd && \ - echo "PS1='\u@\${APPLICATION_NAME}-\${RAILS_ENV}:\w\$ '" >> /etc/bash.bashrc && \ - echo "cat /etc/motd" >> /etc/bash.bashrc - -# Build rails gems and assets in a throw-away build stage to reduce size of final image -FROM base AS build - -# Install packages needed to build gems -ARG BUILD_PACKAGES="build-essential git libcurl4-openssl-dev libpq-dev libyaml-dev pkg-config zlib1g-dev" -RUN apt-get update -qq && \ - apt-get install --no-install-recommends -y $BUILD_PACKAGES && \ - rm -rf /var/lib/apt/lists /var/cache/apt/archives - -# Install application gems -COPY Gemfile Gemfile.lock ./ -RUN bundle install && \ - rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git && \ - bundle exec bootsnap precompile --gemfile - -# Copy application code -COPY --link . . - -# Precompile bootsnap code for faster boot times -RUN bundle exec bootsnap precompile app/ lib/ - -# If set, assets will be compiled into a subdirectory of public/ with this prefix -ARG CDN_ASSET_PREFIX="" - -# Precompile assets for production -RUN DATABASE_URL="postgresql://localhost" \ - SECRET_KEY_BASE_DUMMY=1 \ - ./bin/rails assets:precompile - -# END OF BUILD ## - -# Copy assets to the CDN -FROM amazon/aws-cli:latest AS cdn - -ARG AWS_DEFAULT_REGION="ap-southeast-2" -ARG CDN_ASSET_PREFIX="" -ARG S3_ASSETS_BUCKET="" - -COPY --from=build /rails/public public -RUN --mount=type=secret,id=aws-key-id,env=AWS_ACCESS_KEY_ID \ - --mount=type=secret,id=aws-secret-key,env=AWS_SECRET_ACCESS_KEY \ - --mount=type=secret,id=aws-session-token,env=AWS_SESSION_TOKEN \ - if [ -n "$CDN_ASSET_PREFIX" ] && [ -n "$S3_ASSETS_BUCKET" ]; then \ - aws s3 sync --only-show-errors --cache-control "public, max-age=31536000, immutable" \ - public/$CDN_ASSET_PREFIX s3://$S3_ASSETS_BUCKET/$CDN_ASSET_PREFIX; \ - fi - -# END OF CDN ## - -# Assemble everything into a single layer -FROM base AS assemble - -ARG APPLICATION_VERSION -ARG APPLICATION_REVISION - -COPY --link . . -COPY --from=build /rails/tmp/cache/bootsnap tmp/cache/bootsnap -COPY --from=cdn /aws/public public -RUN echo $APPLICATION_VERSION > VERSION && \ - echo $APPLICATION_REVISION > REVISION && \ - mkdir -p db log ssl storage tmp/pids tmp/sockets && \ - chown -R rails:rails db log ssl storage tmp \ - public # /sitemap.xml.gz - -# Final stage for app image -FROM base - -ARG CDN_ASSET_PREFIX - -# Puma and Rails configuration for a small server setup with puma in single mode with 5 workers -ENV CDN_ASSET_PREFIX=$CDN_ASSET_PREFIX \ - WEB_CONCURRENCY=0 \ - RAILS_MAX_THREADS=5 - -# Assemble layers -COPY --from=build --link "${BUNDLE_PATH}" "${BUNDLE_PATH}" -COPY --from=assemble --link /rails . - -USER 1000:1000 -EXPOSE 4443 -ENTRYPOINT ["/rails/bin/docker-entrypoint"] -CMD ["./bin/rails", "server"] diff --git a/bin/docker-entrypoint b/bin/docker-entrypoint deleted file mode 100755 index e4f6b65..0000000 --- a/bin/docker-entrypoint +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash -e - -# Enable jemalloc for reduced memory usage and latency. -if [ -z "${LD_PRELOAD+x}" ]; then - LD_PRELOAD=$(find /usr/lib -name libjemalloc.so.2 -print -quit) - export LD_PRELOAD -fi - -# If running the rails server then create or migrate existing database -if [ "${@: -2:1}" == "./bin/rails" ] && [ "${@: -1:1}" == "server" ]; then - ./bin/rails db:prepare - - # create a self-signed certificate for puma - mkdir -p ~/.ssl - openssl req -x509 -newkey rsa:2048 -nodes -days 730 \ - -subj '/CN=docker/' \ - -keyout ~/.ssl/docker.key \ - -out ~/.ssl/docker.crt -fi - -exec "${@}" diff --git a/template.rb b/template.rb index e91b8c4..6278d2a 100644 --- a/template.rb +++ b/template.rb @@ -247,8 +247,7 @@ def install_koi end def add_docker - template("Dockerfile", force: true) - template(".dockerignore", force: true) + run("rails g thermite:install:docker --force") end def configure_git diff --git a/templates/puma.rb b/templates/puma.rb old mode 100755 new mode 100644