From f800f60168e1551b0b41f6c63393568906290fe6 Mon Sep 17 00:00:00 2001 From: Monique Rio Date: Fri, 13 Dec 2024 15:26:55 -0500 Subject: [PATCH 1/5] Following the python-starter * uses ruby-slim * starts with a base image which development and production build from * production stage does not include development and test gems * UID and GID are in the .env file so there's a match for development * including Gemfile.lock because it's fine --- .gitignore | 1 + Dockerfile | 42 +++++++++++++++++------- Gemfile.lock | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++++ compose.yml | 6 ++-- env.example | 2 ++ init.sh | 5 +++ 6 files changed, 132 insertions(+), 15 deletions(-) create mode 100644 Gemfile.lock diff --git a/.gitignore b/.gitignore index c9f016a..443bfd6 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ .cache .bundle .env +vendor/ diff --git a/Dockerfile b/Dockerfile index 94744df..11b52a8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,29 +1,47 @@ -FROM ruby:3.2 AS development +################################################################################ +# BASE +################################################################################ +FROM ruby:3.3-slim AS base -ARG UNAME=app ARG UID=1000 ARG GID=1000 -## Install Vim (optional) -#RUN apt-get update -yqq && apt-get install -yqq --no-install-recommends \ -# vim-tiny + +RUN apt-get update -yqq && apt-get install -yqq --no-install-recommends \ + build-essential RUN gem install bundler -RUN groupadd -g ${GID} -o ${UNAME} -RUN useradd -m -d /app -u ${UID} -g ${GID} -o -s /bin/bash ${UNAME} -RUN mkdir -p /gems && chown ${UID}:${GID} /gems +RUN groupadd -g ${GID} -o app +RUN useradd -m -d /app -u ${UID} -g ${GID} -o -s /bin/bash app -USER $UNAME -ENV BUNDLE_PATH /gems +ENV BUNDLE_PATH /app/vendor/bundle WORKDIR /app CMD ["tail", "-f", "/dev/null"] -FROM development AS production +################################################################################ +# DEVELOPMENT # +################################################################################ +FROM base AS development + +RUN apt-get update -yqq && apt-get install -yqq --no-install-recommends \ + vim-tiny + +USER app + +################################################################################ +# PRODUCTION # +################################################################################ +FROM base AS production + +ENV BUNDLE_WITHOUT=development:test COPY --chown=${UID}:${GID} . /app -RUN bundle install + +USER app + +RUN bundle install diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..eef3df7 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,91 @@ +GEM + remote: https://rubygems.org/ + specs: + ast (2.4.2) + byebug (11.1.3) + coderay (1.1.3) + diff-lcs (1.5.1) + docile (1.4.1) + json (2.9.0) + language_server-protocol (3.17.0.3) + lint_roller (1.1.0) + method_source (1.1.0) + parallel (1.26.3) + parser (3.3.6.0) + ast (~> 2.4.1) + racc + pry (0.14.2) + coderay (~> 1.1) + method_source (~> 1.0) + pry-byebug (3.10.1) + byebug (~> 11.0) + pry (>= 0.13, < 0.15) + racc (1.8.1) + rainbow (3.1.1) + regexp_parser (2.9.3) + rspec (3.13.0) + rspec-core (~> 3.13.0) + rspec-expectations (~> 3.13.0) + rspec-mocks (~> 3.13.0) + rspec-core (3.13.2) + rspec-support (~> 3.13.0) + rspec-expectations (3.13.3) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.13.0) + rspec-mocks (3.13.2) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.13.0) + rspec-support (3.13.2) + rubocop (1.69.2) + json (~> 2.3) + language_server-protocol (>= 3.17.0) + parallel (~> 1.10) + parser (>= 3.3.0.2) + rainbow (>= 2.2.2, < 4.0) + regexp_parser (>= 2.9.3, < 3.0) + rubocop-ast (>= 1.36.2, < 2.0) + ruby-progressbar (~> 1.7) + unicode-display_width (>= 2.4.0, < 4.0) + rubocop-ast (1.37.0) + parser (>= 3.3.1.0) + rubocop-performance (1.23.0) + rubocop (>= 1.48.1, < 2.0) + rubocop-ast (>= 1.31.1, < 2.0) + ruby-progressbar (1.13.0) + simplecov (0.22.0) + docile (~> 1.1) + simplecov-html (~> 0.11) + simplecov_json_formatter (~> 0.1) + simplecov-html (0.13.1) + simplecov-lcov (0.8.0) + simplecov_json_formatter (0.1.4) + standard (1.43.0) + language_server-protocol (~> 3.17.0.2) + lint_roller (~> 1.0) + rubocop (~> 1.69.1) + standard-custom (~> 1.0.0) + standard-performance (~> 1.6) + standard-custom (1.0.2) + lint_roller (~> 1.0) + rubocop (~> 1.50) + standard-performance (1.6.0) + lint_roller (~> 1.1) + rubocop-performance (~> 1.23.0) + unicode-display_width (3.1.2) + unicode-emoji (~> 4.0, >= 4.0.4) + unicode-emoji (4.0.4) + +PLATFORMS + ruby + x86_64-linux + +DEPENDENCIES + pry + pry-byebug + rspec + simplecov + simplecov-lcov + standard + +BUNDLED WITH + 2.5.23 diff --git a/compose.yml b/compose.yml index 1b9a381..764380b 100644 --- a/compose.yml +++ b/compose.yml @@ -3,11 +3,11 @@ services: build: context: . target: development + args: + UID: ${UID:-1000} + GID: ${GID:-1000} volumes: - .:/app - - gem_cache:/gems env_file: - .env -volumes: - gem_cache: diff --git a/env.example b/env.example index 675d573..82429e9 100644 --- a/env.example +++ b/env.example @@ -1 +1,3 @@ +UID=YOUR_UID +GID=YOUR_GID SEKRET="aweflweif;wltgi5t13o5i" diff --git a/init.sh b/init.sh index f55f8bb..43a73f1 100755 --- a/init.sh +++ b/init.sh @@ -3,6 +3,11 @@ if [ -f ".env" ]; then else echo "🌎 .env does not exist. Copying .env-example to .env" cp env.example .env + YOUR_UID=$(id -u) + YOUR_GID=$(id -g) + echo "🙂 Setting your UID (${YOUR_UID}) and GID (${YOUR_UID}) in .env" + docker run --rm -v ./.env:/.env alpine echo "$(sed s/YOUR_UID/${YOUR_UID}/ .env)" >.env + docker run --rm -v ./.env:/.env alpine echo "$(sed s/YOUR_GID/${YOUR_GID}/ .env)" >.env fi if [ -f ".git/hooks/pre-commit" ]; then From 6e75e3ef516a6807258fe73551f80f6395b84a1a Mon Sep 17 00:00:00 2001 From: Monique Rio Date: Fri, 13 Dec 2024 20:48:38 +0000 Subject: [PATCH 2/5] adds dev-container starter --- .devcontainer/devcontainer.json | 12 ++++++++++++ .gitignore | 6 ++++++ 2 files changed, 18 insertions(+) create mode 100644 .devcontainer/devcontainer.json diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..f9e440e --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,12 @@ +{ + "name": "Existing Docker Compose (Extend)", + "dockerComposeFile": [ + "../compose.yml", + ], + "service": "app", + "workspaceFolder": "/app", + "features": { + "ghcr.io/devcontainers/features/git:1": {}, + "ghcr.io/devcontainers/features/sshd:1": {} + } +} \ No newline at end of file diff --git a/.gitignore b/.gitignore index 443bfd6..eb9197c 100644 --- a/.gitignore +++ b/.gitignore @@ -3,5 +3,11 @@ .irb_history .cache .bundle + +.ruby-lsp +.vscode-server +.ssh +.gitconfig + .env vendor/ From 81738103b810e06ba8151796ef762803609c9425 Mon Sep 17 00:00:00 2001 From: Monique Rio Date: Fri, 13 Dec 2024 23:08:52 +0000 Subject: [PATCH 3/5] adding files for dev-containers with ruby-lsp --- .devcontainer/devcontainer.json | 11 ++++++++++- .gitignore | 2 ++ Dockerfile | 14 ++++++++++++-- Gemfile | 1 + Gemfile.lock | 11 +++++++++++ 5 files changed, 36 insertions(+), 3 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index f9e440e..96c0137 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,12 +1,21 @@ { "name": "Existing Docker Compose (Extend)", "dockerComposeFile": [ - "../compose.yml", + "../compose.yml" ], "service": "app", "workspaceFolder": "/app", "features": { "ghcr.io/devcontainers/features/git:1": {}, "ghcr.io/devcontainers/features/sshd:1": {} + }, + "customizations": { + "vscode": { + "extensions": [ + "ms-azuretools.vscode-docker", + "shopify.ruby-extensions-pack", + "testdouble.vscode-standard-ruby" + ] + } } } \ No newline at end of file diff --git a/.gitignore b/.gitignore index eb9197c..2ef0aba 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,8 @@ .vscode-server .ssh .gitconfig +.local +.dotnet .env vendor/ diff --git a/Dockerfile b/Dockerfile index 11b52a8..89fd65d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,20 +10,29 @@ ARG GID=1000 RUN apt-get update -yqq && apt-get install -yqq --no-install-recommends \ build-essential -RUN gem install bundler RUN groupadd -g ${GID} -o app RUN useradd -m -d /app -u ${UID} -g ${GID} -o -s /bin/bash app +ENV GEM_HOME=/gems +ENV PATH="$PATH:/gems/bin" +RUN mkdir -p /gems && chown ${UID}:${GID} /gems + ENV BUNDLE_PATH /app/vendor/bundle +# Change to app and back so that bundler created files in /gmes are owned by the +# app user +USER app +RUN gem install bundler +USER root + WORKDIR /app CMD ["tail", "-f", "/dev/null"] ################################################################################ -# DEVELOPMENT # +# DEVELOPMENT # ################################################################################ FROM base AS development @@ -39,6 +48,7 @@ FROM base AS production ENV BUNDLE_WITHOUT=development:test + COPY --chown=${UID}:${GID} . /app USER app diff --git a/Gemfile b/Gemfile index e8f2191..ea4a70f 100644 --- a/Gemfile +++ b/Gemfile @@ -13,4 +13,5 @@ end group :development do gem "standard" + gem "ruby-lsp" end diff --git a/Gemfile.lock b/Gemfile.lock index eef3df7..b6c3802 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -9,11 +9,13 @@ GEM json (2.9.0) language_server-protocol (3.17.0.3) lint_roller (1.1.0) + logger (1.6.3) method_source (1.1.0) parallel (1.26.3) parser (3.3.6.0) ast (~> 2.4.1) racc + prism (1.2.0) pry (0.14.2) coderay (~> 1.1) method_source (~> 1.0) @@ -22,6 +24,8 @@ GEM pry (>= 0.13, < 0.15) racc (1.8.1) rainbow (3.1.1) + rbs (3.7.0) + logger regexp_parser (2.9.3) rspec (3.13.0) rspec-core (~> 3.13.0) @@ -51,6 +55,11 @@ GEM rubocop-performance (1.23.0) rubocop (>= 1.48.1, < 2.0) rubocop-ast (>= 1.31.1, < 2.0) + ruby-lsp (0.22.1) + language_server-protocol (~> 3.17.0) + prism (>= 1.2, < 2.0) + rbs (>= 3, < 4) + sorbet-runtime (>= 0.5.10782) ruby-progressbar (1.13.0) simplecov (0.22.0) docile (~> 1.1) @@ -59,6 +68,7 @@ GEM simplecov-html (0.13.1) simplecov-lcov (0.8.0) simplecov_json_formatter (0.1.4) + sorbet-runtime (0.5.11691) standard (1.43.0) language_server-protocol (~> 3.17.0.2) lint_roller (~> 1.0) @@ -83,6 +93,7 @@ DEPENDENCIES pry pry-byebug rspec + ruby-lsp simplecov simplecov-lcov standard From 4e55dfab6a7f520f9b34869b934f1df49c30bef9 Mon Sep 17 00:00:00 2001 From: Monique Rio Date: Mon, 3 Feb 2025 21:50:36 +0000 Subject: [PATCH 4/5] adds an 'autoformat' option to vscode workspace settings --- .vscode/settings.json | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..82c2291 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "standardRuby.autofix": true +} \ No newline at end of file From 0de910269a7479ef16cb8291f15eeae436861805 Mon Sep 17 00:00:00 2001 From: Monique Rio Date: Mon, 3 Feb 2025 22:07:14 +0000 Subject: [PATCH 5/5] changes from pry-byebug to debug gem --- .gitignore | 1 + Dockerfile | 3 ++- Gemfile | 3 +-- Gemfile.lock | 30 ++++++++++++++++++------------ 4 files changed, 22 insertions(+), 15 deletions(-) diff --git a/.gitignore b/.gitignore index 2ef0aba..9f513b7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ .bash_history .idea .irb_history +.rdbg_history .cache .bundle diff --git a/Dockerfile b/Dockerfile index 89fd65d..8cae0f4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,7 +8,8 @@ ARG GID=1000 RUN apt-get update -yqq && apt-get install -yqq --no-install-recommends \ - build-essential + build-essential \ + libtool RUN groupadd -g ${GID} -o app diff --git a/Gemfile b/Gemfile index ea4a70f..09f2c95 100644 --- a/Gemfile +++ b/Gemfile @@ -1,8 +1,7 @@ source "https://rubygems.org" group :development, :test do - gem "pry" - gem "pry-byebug" + gem "debug" end group :test do diff --git a/Gemfile.lock b/Gemfile.lock index b6c3802..53b9b85 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -2,31 +2,37 @@ GEM remote: https://rubygems.org/ specs: ast (2.4.2) - byebug (11.1.3) - coderay (1.1.3) + date (3.4.1) + debug (1.9.2) + irb (~> 1.10) + reline (>= 0.3.8) diff-lcs (1.5.1) docile (1.4.1) + io-console (0.8.0) + irb (1.14.2) + rdoc (>= 4.0.0) + reline (>= 0.4.2) json (2.9.0) language_server-protocol (3.17.0.3) lint_roller (1.1.0) logger (1.6.3) - method_source (1.1.0) parallel (1.26.3) parser (3.3.6.0) ast (~> 2.4.1) racc prism (1.2.0) - pry (0.14.2) - coderay (~> 1.1) - method_source (~> 1.0) - pry-byebug (3.10.1) - byebug (~> 11.0) - pry (>= 0.13, < 0.15) + psych (5.2.1) + date + stringio racc (1.8.1) rainbow (3.1.1) rbs (3.7.0) logger + rdoc (6.9.0) + psych (>= 4.0.0) regexp_parser (2.9.3) + reline (0.6.0) + io-console (~> 0.5) rspec (3.13.0) rspec-core (~> 3.13.0) rspec-expectations (~> 3.13.0) @@ -81,6 +87,7 @@ GEM standard-performance (1.6.0) lint_roller (~> 1.1) rubocop-performance (~> 1.23.0) + stringio (3.1.2) unicode-display_width (3.1.2) unicode-emoji (~> 4.0, >= 4.0.4) unicode-emoji (4.0.4) @@ -90,8 +97,7 @@ PLATFORMS x86_64-linux DEPENDENCIES - pry - pry-byebug + debug rspec ruby-lsp simplecov @@ -99,4 +105,4 @@ DEPENDENCIES standard BUNDLED WITH - 2.5.23 + 2.6.3