diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..96c0137 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,21 @@ +{ + "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": {} + }, + "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 c9f016a..9f513b7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,16 @@ .bash_history .idea .irb_history +.rdbg_history .cache .bundle + +.ruby-lsp +.vscode-server +.ssh +.gitconfig +.local +.dotnet + .env +vendor/ 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 diff --git a/Dockerfile b/Dockerfile index 94744df..8cae0f4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,29 +1,58 @@ -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 gem install bundler +RUN apt-get update -yqq && apt-get install -yqq --no-install-recommends \ + build-essential \ + libtool + + +RUN groupadd -g ${GID} -o app +RUN useradd -m -d /app -u ${UID} -g ${GID} -o -s /bin/bash app -RUN groupadd -g ${GID} -o ${UNAME} -RUN useradd -m -d /app -u ${UID} -g ${GID} -o -s /bin/bash ${UNAME} +ENV GEM_HOME=/gems +ENV PATH="$PATH:/gems/bin" RUN mkdir -p /gems && chown ${UID}:${GID} /gems -USER $UNAME -ENV BUNDLE_PATH /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"] -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 b/Gemfile index e8f2191..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 @@ -13,4 +12,5 @@ end group :development do gem "standard" + gem "ruby-lsp" end diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..53b9b85 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,108 @@ +GEM + remote: https://rubygems.org/ + specs: + ast (2.4.2) + 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) + parallel (1.26.3) + parser (3.3.6.0) + ast (~> 2.4.1) + racc + prism (1.2.0) + 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) + 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-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) + 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) + sorbet-runtime (0.5.11691) + 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) + stringio (3.1.2) + unicode-display_width (3.1.2) + unicode-emoji (~> 4.0, >= 4.0.4) + unicode-emoji (4.0.4) + +PLATFORMS + ruby + x86_64-linux + +DEPENDENCIES + debug + rspec + ruby-lsp + simplecov + simplecov-lcov + standard + +BUNDLED WITH + 2.6.3 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