Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Newer method #3

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .solargraph.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
include:
- "**/*.rb"
exclude:
- spec/**/*
- vendor/**/*
- ".bundle/**/*"
require: []
domains: []
reporters: []
formatter:
require_paths: []
plugins: []
max_files: 5000
31 changes: 24 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
FROM ruby:3.2 AS development
FROM ruby:3.2 AS base

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

Expand All @@ -10,20 +11,36 @@ 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

WORKDIR /app

CMD ["tail", "-f", "/dev/null"]

FROM development AS production
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

FROM base AS production

COPY --chown=${UID}:${GID} . /app
RUN bundle install

RUN bundle install
13 changes: 5 additions & 8 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
source "https://rubygems.org"

group :development, :test do
gem "marc"
gem "rails"

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
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.

Expand Down
2 changes: 2 additions & 0 deletions bundle_install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#This builds the gems and updates Gemfile.lock
docker compose build && docker compose run --rm app bundle install
7 changes: 3 additions & 4 deletions compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ services:
build:
context: .
target: development
args:
- UID=${UID}
- GID=${UID}
volumes:
- .:/app
- gem_cache:/gems
env_file:
- .env

volumes:
gem_cache:
4 changes: 4 additions & 0 deletions env.example
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
#Set these to your actual UID and GID
UID=YOUR_UID
GID=YOUR_GID

SEKRET="aweflweif;wltgi5t13o5i"
8 changes: 5 additions & 3 deletions init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -14,6 +19,3 @@ fi

echo "🚢 Build docker images"
docker compose build

echo "📦 Installing Gems"
docker compose run --rm app bundle
Loading