From fc9462afa265664e0ed6a6ad61b9c8a570d2542f Mon Sep 17 00:00:00 2001 From: Ryan McNeil Date: Thu, 18 Apr 2024 12:14:05 -0600 Subject: [PATCH 1/5] Change WORKDIR to /rails and modify useradd --- Dockerfile | 23 ++++++++++++----------- docker-compose.yml | 2 +- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/Dockerfile b/Dockerfile index f4f96e1b9..72b5105c4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,19 +3,20 @@ # # shared build/settings for all child images ### -FROM ruby:3.3.0-slim-bookworm AS base +# Make sure RUBY_VERSION matches the Ruby version in .ruby-version and Gemfile +ARG RUBY_VERSION=3.3.0 +FROM registry.docker.com/library/ruby:$RUBY_VERSION-slim-bookworm as base -ARG userid=309 -SHELL ["/bin/bash", "-c"] -RUN groupadd -g $userid -r gi-bill-data-service && \ - useradd -u $userid -r -g gi-bill-data-service -d /srv/gi-bill-data-service gi-bill-data-service +# Rails app lives here +WORKDIR /rails + +ARG USER_ID=309 + +RUN groupadd -g $USER_ID gi-bill-data-service && \ + useradd -u $USER_ID -g gi-bill-data-service gi-bill-data-service --create-home --shell /bin/bash gi-bill-data-service RUN apt-get update -qq && apt-get install -y \ build-essential git curl wget libpq-dev dumb-init shared-mime-info nodejs cron file -RUN mkdir -p /srv/gi-bill-data-service/src && \ - chown -R gi-bill-data-service:gi-bill-data-service /srv/gi-bill-data-service -WORKDIR /srv/gi-bill-data-service/src - ### # development # @@ -62,7 +63,7 @@ ENV RAILS_ENV="production" ENV PATH="/usr/local/bundle/bin:${PATH}" COPY --from=builder $BUNDLE_APP_CONFIG $BUNDLE_APP_CONFIG -COPY --from=builder --chown=gi-bill-data-service:gi-bill-data-service /srv/gi-bill-data-service/src ./ +COPY --from=builder --chown=gi-bill-data-service:gi-bill-data-service /rails /rails USER gi-bill-data-service ENTRYPOINT ["bash", "-c"] @@ -85,7 +86,7 @@ COPY ./import-va-certs.sh . RUN ./import-va-certs.sh COPY --from=builder $BUNDLE_APP_CONFIG $BUNDLE_APP_CONFIG -COPY --from=builder --chown=gi-bill-data-service:gi-bill-data-service /srv/gi-bill-data-service/src ./ +COPY --from=builder --chown=gi-bill-data-service:gi-bill-data-service /rails /rails USER gi-bill-data-service ENTRYPOINT ["/usr/bin/dumb-init", "--", "./docker-entrypoint.sh"] diff --git a/docker-compose.yml b/docker-compose.yml index 3701219ff..cea7c57a9 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -15,7 +15,7 @@ services: target: development image: "gibct:${DOCKER_IMAGE:-latest}" volumes: - - ".:/srv/gi-bill-data-service/src/:cached" + - ".:/rails/:cached" - dev_bundle:/usr/local/bundle ports: - 3000:3000 From ab9df4c78477e6929761536514cbc29fa87c0f8e Mon Sep 17 00:00:00 2001 From: Ryan McNeil Date: Thu, 18 Apr 2024 12:16:48 -0600 Subject: [PATCH 2/5] remove whoami --- Dockerfile | 2 -- 1 file changed, 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 72b5105c4..fd9b930a5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -79,8 +79,6 @@ FROM base AS production ENV RAILS_ENV="production" ENV PATH="/usr/local/bundle/bin:${PATH}" -RUN whoami - # Download VA Certs COPY ./import-va-certs.sh . RUN ./import-va-certs.sh From 314c9fc8a67c4834cc07eee49dab68233a8a97cc Mon Sep 17 00:00:00 2001 From: Ryan McNeil Date: Thu, 18 Apr 2024 12:42:45 -0600 Subject: [PATCH 3/5] remove extra arg --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index fd9b930a5..259b9959b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,7 +13,7 @@ WORKDIR /rails ARG USER_ID=309 RUN groupadd -g $USER_ID gi-bill-data-service && \ - useradd -u $USER_ID -g gi-bill-data-service gi-bill-data-service --create-home --shell /bin/bash gi-bill-data-service + useradd -u $USER_ID -g gi-bill-data-service --create-home --shell /bin/bash gi-bill-data-service RUN apt-get update -qq && apt-get install -y \ build-essential git curl wget libpq-dev dumb-init shared-mime-info nodejs cron file From 72176246d40f7250eaf7d3f2d054e831f31edb53 Mon Sep 17 00:00:00 2001 From: Ryan McNeil Date: Thu, 18 Apr 2024 14:45:11 -0600 Subject: [PATCH 4/5] chown /rails --- Dockerfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Dockerfile b/Dockerfile index 259b9959b..c1fbc7978 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,6 +17,8 @@ RUN groupadd -g $USER_ID gi-bill-data-service && \ RUN apt-get update -qq && apt-get install -y \ build-essential git curl wget libpq-dev dumb-init shared-mime-info nodejs cron file +RUN chown -R gi-bill-data-service:gi-bill-data-service /rails + ### # development # From 8ddfd7939c72abd261e6aabad498fad1be3cb011 Mon Sep 17 00:00:00 2001 From: Ryan McNeil Date: Fri, 19 Apr 2024 16:20:17 -0600 Subject: [PATCH 5/5] change workdir to /app --- Dockerfile | 10 +++++----- docker-compose.yml | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index e27f9bcdd..af1b45e48 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,7 +8,7 @@ ARG RUBY_VERSION=3.3.0 FROM registry.docker.com/library/ruby:$RUBY_VERSION-slim-bookworm as base # Rails app lives here -WORKDIR /rails +WORKDIR /app ARG USER_ID=309 @@ -17,7 +17,7 @@ RUN groupadd -g $USER_ID gi-bill-data-service && \ RUN apt-get update -qq && apt-get install -y \ build-essential git curl wget libpq-dev dumb-init shared-mime-info nodejs cron file -RUN chown -R gi-bill-data-service:gi-bill-data-service /rails +RUN chown -R gi-bill-data-service:gi-bill-data-service /app ### # development @@ -65,7 +65,7 @@ ENV RAILS_ENV="production" ENV PATH="/usr/local/bundle/bin:${PATH}" COPY --from=builder $BUNDLE_APP_CONFIG $BUNDLE_APP_CONFIG -COPY --from=builder --chown=gi-bill-data-service:gi-bill-data-service /rails /rails +COPY --from=builder --chown=gi-bill-data-service:gi-bill-data-service /app /app USER gi-bill-data-service ENTRYPOINT ["bash", "-c"] @@ -88,10 +88,10 @@ RUN git clone --depth 1 https://github.com/department-of-veterans-affairs/platfo /bin/bash platform-va-ca-certificate/debian-ubuntu/install-certs.sh && \ rm -rf /tmp/* -WORKDIR /rails +WORKDIR /app COPY --from=builder $BUNDLE_APP_CONFIG $BUNDLE_APP_CONFIG -COPY --from=builder --chown=gi-bill-data-service:gi-bill-data-service /rails /rails +COPY --from=builder --chown=gi-bill-data-service:gi-bill-data-service /app /app USER gi-bill-data-service ENTRYPOINT ["/usr/bin/dumb-init", "--", "./docker-entrypoint.sh"] diff --git a/docker-compose.yml b/docker-compose.yml index cea7c57a9..10324f95d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -15,7 +15,7 @@ services: target: development image: "gibct:${DOCKER_IMAGE:-latest}" volumes: - - ".:/rails/:cached" + - ".:/app/:cached" - dev_bundle:/usr/local/bundle ports: - 3000:3000