From cc8fe543542703ae2c05dbddbd5944e40764c066 Mon Sep 17 00:00:00 2001 From: Monique Rio Date: Thu, 22 Feb 2024 10:35:17 -0500 Subject: [PATCH 1/4] remove UNAME build arg; add the build args to the compose.yml --- Dockerfile | 19 +++++++++++++------ compose.yml | 3 +++ env.example | 4 ++++ 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index 94744df..189c6d5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,7 @@ -FROM ruby:3.2 AS development +FROM ruby:3.2-slim-bookworm AS development -ARG UNAME=app +# These build args are in your `.env` file, and they exist so that for +# development the user in the container has the same UID and GID as you. ARG UID=1000 ARG GID=1000 @@ -10,11 +11,18 @@ ARG GID=1000 RUN gem install bundler -RUN groupadd -g ${GID} -o ${UNAME} -RUN useradd -m -d /app -u ${UID} -g ${GID} -o -s /bin/bash ${UNAME} +# Add the app group. Map it's GID to the build arg. -o means it's ok if it's a non-unique GID. +RUN groupadd -g ${GID} -o app + +# Add the app user. Map its UID and GID to the build args. Create a /app home +# directory for it. -o means it's ok if it's a non-unique GID. Set the shell to +# bash. +RUN useradd -m -d /app -u ${UID} -g ${GID} -o -s /bin/bash app + +#Make a gems directory and have it owned by the app user and group RUN mkdir -p /gems && chown ${UID}:${GID} /gems -USER $UNAME +USER app ENV BUNDLE_PATH /gems @@ -26,4 +34,3 @@ FROM development AS production COPY --chown=${UID}:${GID} . /app RUN bundle install - diff --git a/compose.yml b/compose.yml index 1b9a381..bcf0d45 100644 --- a/compose.yml +++ b/compose.yml @@ -3,6 +3,9 @@ services: build: context: . target: development + args: + - UID=${UID} + - GID=${UID} volumes: - .:/app - gem_cache:/gems diff --git a/env.example b/env.example index 675d573..81e1593 100644 --- a/env.example +++ b/env.example @@ -1 +1,5 @@ +#Set these to your actual UID and GID +UID=1000 +GID=1000 + SEKRET="aweflweif;wltgi5t13o5i" From 23b4656b9d7833b366f7770986f12e11b00d3a34 Mon Sep 17 00:00:00 2001 From: Monique Rio Date: Thu, 22 Feb 2024 11:27:35 -0500 Subject: [PATCH 2/4] uses cache mount for gems; sets uid and gid on init --- Dockerfile | 10 ++++++++-- Gemfile | 10 ++-------- README.md | 3 +-- compose.yml | 4 ---- env.example | 4 ++-- init.sh | 8 +++++--- 6 files changed, 18 insertions(+), 21 deletions(-) diff --git a/Dockerfile b/Dockerfile index 189c6d5..7e0723e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM ruby:3.2-slim-bookworm AS development +FROM ruby:3.2 AS development # These build args are in your `.env` file, and they exist so that for # development the user in the container has the same UID and GID as you. @@ -26,11 +26,17 @@ USER app ENV BUNDLE_PATH /gems +COPY --chown=${UID}:${GID} Gemfile* /app/ + WORKDIR /app +# cache mount for bundle install so running bundle install won't reinstall +# everything +RUN --mount=type=cache,target=/gems/bundle,uid=${UID},gid=${GID} \ + bundle install + CMD ["tail", "-f", "/dev/null"] FROM development AS production COPY --chown=${UID}:${GID} . /app -RUN bundle install diff --git a/Gemfile b/Gemfile index e8f2191..c2c7dab 100644 --- a/Gemfile +++ b/Gemfile @@ -1,16 +1,10 @@ source "https://rubygems.org" -group :development, :test do +group :development do gem "pry" gem "pry-byebug" -end - -group :test do + gem "standard" gem "rspec" gem "simplecov" gem "simplecov-lcov" end - -group :development do - gem "standard" -end diff --git a/README.md b/README.md index 41eef37..5125b4a 100644 --- a/README.md +++ b/README.md @@ -11,11 +11,10 @@ Run the setup script This will: -* copy `env.example` to `.env` +* copy `env.example` to `.env` and in the env file sets the UID and GID to your values. * enable the precommit hook which wil lint the code before committing. Uncomment those lines in `.git/hooks/precommit` to enable running tests. * build the docker image -* install the gems The script does not overwrite `.env` or `/git/hooks/precommit`. diff --git a/compose.yml b/compose.yml index bcf0d45..2ec2fe1 100644 --- a/compose.yml +++ b/compose.yml @@ -8,9 +8,5 @@ services: - GID=${UID} volumes: - .:/app - - gem_cache:/gems env_file: - .env - -volumes: - gem_cache: diff --git a/env.example b/env.example index 81e1593..353e874 100644 --- a/env.example +++ b/env.example @@ -1,5 +1,5 @@ #Set these to your actual UID and GID -UID=1000 -GID=1000 +UID=YOUR_UID +GID=YOUR_GID SEKRET="aweflweif;wltgi5t13o5i" diff --git a/init.sh b/init.sh index f55f8bb..3bf8288 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" + sed -i s/YOUR_UID/$YOUR_UID/ .env + sed -i s/YOUR_GID/$YOUR_GID/ .env fi if [ -f ".git/hooks/pre-commit" ]; then @@ -14,6 +19,3 @@ fi echo "🚢 Build docker images" docker compose build - -echo "📦 Installing Gems" -docker compose run --rm app bundle From ca4d9dc642be41457bd2fae21e080c338931da92 Mon Sep 17 00:00:00 2001 From: Monique Rio Date: Thu, 22 Feb 2024 13:46:56 -0500 Subject: [PATCH 3/4] new problems are new --- Dockerfile | 16 ++++++++++------ Gemfile | 3 +++ bundle_install.sh | 2 ++ 3 files changed, 15 insertions(+), 6 deletions(-) create mode 100755 bundle_install.sh diff --git a/Dockerfile b/Dockerfile index 7e0723e..0a39e5a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM ruby:3.2 AS development +FROM ruby:3.2 AS base # These build args are in your `.env` file, and they exist so that for # development the user in the container has the same UID and GID as you. @@ -26,17 +26,21 @@ USER app ENV BUNDLE_PATH /gems -COPY --chown=${UID}:${GID} Gemfile* /app/ - WORKDIR /app +CMD ["tail", "-f", "/dev/null"] + +FROM base AS development + +COPY --chown=${UID}:${GID} Gemfile /app/ + # cache mount for bundle install so running bundle install won't reinstall # everything RUN --mount=type=cache,target=/gems/bundle,uid=${UID},gid=${GID} \ bundle install -CMD ["tail", "-f", "/dev/null"] - -FROM development AS production +FROM base AS production COPY --chown=${UID}:${GID} . /app + +RUN bundle install diff --git a/Gemfile b/Gemfile index c2c7dab..448a15b 100644 --- a/Gemfile +++ b/Gemfile @@ -1,5 +1,8 @@ source "https://rubygems.org" +gem "marc" +gem "rails" + group :development do gem "pry" gem "pry-byebug" diff --git a/bundle_install.sh b/bundle_install.sh new file mode 100755 index 0000000..2bf35ac --- /dev/null +++ b/bundle_install.sh @@ -0,0 +1,2 @@ +#This builds the gems and updates Gemfile.lock +docker compose build && docker compose run --rm app bundle install From 93c88fecc08821ff18b808b6391d4661c29f54c9 Mon Sep 17 00:00:00 2001 From: Monique Rio Date: Thu, 22 Feb 2024 17:17:43 -0500 Subject: [PATCH 4/4] add solargraph --- .solargraph.yml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 .solargraph.yml diff --git a/.solargraph.yml b/.solargraph.yml new file mode 100644 index 0000000..44c7a2e --- /dev/null +++ b/.solargraph.yml @@ -0,0 +1,14 @@ +--- +include: +- "**/*.rb" +exclude: +- spec/**/* +- vendor/**/* +- ".bundle/**/*" +require: [] +domains: [] +reporters: [] +formatter: +require_paths: [] +plugins: [] +max_files: 5000