Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
352a10c
make sure keys are readable
timothy-spencer Jun 10, 2024
9ac6f5d
remove build-essential in a way that will not bloat the image
timothy-spencer Jun 11, 2024
68859a5
yarn install needs build-essential too it seems
timothy-spencer Jun 11, 2024
560d6aa
add make for asset stuff
timothy-spencer Jun 11, 2024
8964ab5
add some network debugging
timothy-spencer Jun 17, 2024
0924cb7
tracepath is not apparently a thing
timothy-spencer Jun 17, 2024
1fc2d49
add more debug
timothy-spencer Jun 17, 2024
92d27a4
use proper netcat
timothy-spencer Jun 17, 2024
ce32d07
remove network debugging tools
timothy-spencer Jun 17, 2024
70b4177
changelog: Internal, Platform Automation, Update production idp image…
timothy-spencer Jun 17, 2024
fee5936
fix pwned_passwords.txt
timothy-spencer Jun 17, 2024
ee4a8a4
add puma header
Jun 18, 2024
92d37a1
trigger another build
timothy-spencer Jun 20, 2024
4dcb3ff
move gem build and large files out into a multi-stage build
timothy-spencer Jun 26, 2024
7c0159e
Update dockerfiles/idp_prod.Dockerfile
timothy-spencer Jun 26, 2024
1e2d210
try removing some sqlite stuff
timothy-spencer Jun 26, 2024
5a18996
move everything up and just copy rails root over
timothy-spencer Jun 26, 2024
f124d00
change where bundle install gets run and make sure it's configured pr…
timothy-spencer Jun 26, 2024
b5c8097
we need curl for healthchecks
timothy-spencer Jun 26, 2024
36f9268
remove suid/sgid from binaries
timothy-spencer Jun 29, 2024
32283fd
add service_providers.yml and related files
timothy-spencer Jul 16, 2024
aecc5b5
forgot to wire the env vars up to args
timothy-spencer Jul 16, 2024
8a24005
trigger build
timothy-spencer Jul 16, 2024
9041fe3
forgot to copy keys we generated over
timothy-spencer Jul 19, 2024
0aaf75f
try using readonly deploy key
timothy-spencer Jul 19, 2024
13ec4b8
get the host fingerprint, map the key in as an arg
timothy-spencer Jul 19, 2024
2b71b59
change perms on key so it works
timothy-spencer Jul 19, 2024
3f85789
just noticed that the service_provider stuff wasn't in the build dir
timothy-spencer Jul 19, 2024
8fd25a6
move config copy to where workdir works
timothy-spencer Jul 20, 2024
c87f906
some debugging
timothy-spencer Jul 20, 2024
18d83fa
try full path
timothy-spencer Jul 22, 2024
91dd66b
I was totally missing that COPY was coming from the local filesystem,…
timothy-spencer Jul 22, 2024
21192b1
don't overwrite the identity-idp-config files with localdev ones
timothy-spencer Jul 22, 2024
09bc2d4
exclude node_modules
timothy-spencer Jul 23, 2024
29c35f4
be more specific about node_modules
timothy-spencer Jul 23, 2024
52b110a
testing
Jul 19, 2024
21ded89
revert
Aug 1, 2024
14acf63
remove package restrictions in builder
timothy-spencer Jul 24, 2024
80f8cb1
try some debugging of the seeder error
timothy-spencer Jul 26, 2024
b6fd69e
forgot to assign error to a variable
timothy-spencer Jul 26, 2024
84656cf
logger needs more log-ness to actually log I think
timothy-spencer Jul 26, 2024
72588ab
get all exceptions
timothy-spencer Jul 26, 2024
d56ed58
did Agency.destroy_all and it doesn't have this issue
timothy-spencer Jul 29, 2024
363535f
fix --no-install-recommends
Aug 1, 2024
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
2 changes: 2 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ build-idp-image:
--build-arg "ARG_CI_COMMIT_SHA=${CI_COMMIT_SHA}"
--build-arg "LARGE_FILES_TOKEN=${LARGE_FILES_TOKEN}"
--build-arg "LARGE_FILES_USER=${LARGE_FILES_USER}"
--build-arg "SERVICE_PROVIDERS_KEY=${SERVICE_PROVIDERS_KEY}"


check_changelog:
stage: test
Expand Down
207 changes: 136 additions & 71 deletions dockerfiles/idp_prod.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,42 +1,31 @@
FROM ruby:3.3.1-slim
#########################################################################
# This is a multi-stage build. This stage just builds and downloads
# gems and yarn stuff and large files. We have it so that we can
# avoid having build-essential and the large-files token be in the
# main image.
#########################################################################
FROM ruby:3.3.1-slim as builder

# Set environment variables
ENV RAILS_ROOT /app
ENV RAILS_ENV production
ENV NODE_ENV production
ENV RAILS_SERVE_STATIC_FILES true
ENV RAILS_LOG_TO_STDOUT true
ENV RAILS_LOG_LEVEL debug
ENV BUNDLE_PATH /usr/local/bundle
ENV BUNDLE_PATH /app/vendor/bundle
ENV YARN_VERSION 1.22.5
ENV NODE_VERSION 20.10.0
ENV BUNDLER_VERSION 2.5.6
ENV POSTGRES_SSLMODE prefer
ENV POSTGRES_NAME idp
ENV POSTGRES_HOST postgres
ENV POSTGRES_USERNAME postgres
ENV POSTGRES_PASSWORD postgres
ENV POSTGRES_WORKER_SSLMODE prefer
ENV POSTGRES_WORKER_NAME idp-worker-jobs
ENV POSTGRES_WORKER_HOST postgres-worker
ENV POSTGRES_WORKER_USERNAME postgres
ENV POSTGRES_WORKER_PASSWORD postgres
ENV REDIS_IRS_ATTEMPTS_API_URL redis://redis:6379/2
ENV REDIS_THROTTLE_URL redis://redis:6379/1
ENV REDIS_URL redis://redis:6379
ENV ASSET_HOST http://localhost:3000
ENV DOMAIN_NAME localhost:3000
ENV PIV_CAC_SERVICE_URL https://localhost:8443/
ENV PIV_CAC_VERIFY_TOKEN_URL https://localhost:8443/

# Install dependencies
RUN apt-get update && \
apt-get install -y \
RUN apt-get update -qq && \
apt-get install -y --no-install-recommends \
openssh-client \
git-core \
build-essential \
git-lfs \
curl \
zlib1g-dev \
build-essential \
Comment thread
timothy-spencer marked this conversation as resolved.
libssl-dev \
libreadline-dev \
libyaml-dev \
Expand All @@ -48,9 +37,20 @@ RUN apt-get update && \
software-properties-common \
libffi-dev \
libpq-dev \
xz-utils \
unzip && \
rm -rf /var/lib/apt/lists/*

# get the large files
WORKDIR /
ARG LARGE_FILES_USER
ARG LARGE_FILES_TOKEN
RUN git clone --depth 1 https://$LARGE_FILES_USER:$LARGE_FILES_TOKEN@gitlab.login.gov/lg-public/idp-large-files.git

# Set the working directory
WORKDIR $RAILS_ROOT

# Install Node
RUN curl -fsSLO --compressed "https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION-linux-x64.tar.xz" \
&& tar -xJf "node-v$NODE_VERSION-linux-x64.tar.xz" -C /usr/local --strip-components=1 --no-same-owner \
&& rm "node-v$NODE_VERSION-linux-x64.tar.xz" \
Expand All @@ -59,39 +59,20 @@ RUN curl -fsSLO --compressed "https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE
# Install Yarn
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | gpg --dearmor | tee /usr/share/keyrings/yarn-archive-keyring.gpg >/dev/null
RUN echo "deb [signed-by=/usr/share/keyrings/yarn-archive-keyring.gpg] https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
RUN apt-get update && apt-get install -y yarn=1.22.5-1

# Download RDS Combined CA Bundle
RUN mkdir -p /usr/local/share/aws \
&& curl https://s3.amazonaws.com/rds-downloads/rds-combined-ca-bundle.pem > /usr/local/share/aws/rds-combined-ca-bundle.pem \
&& chmod 644 /usr/local/share/aws/rds-combined-ca-bundle.pem

# Create a new user and set up the working directory
RUN addgroup --gid 1000 app && \
adduser --uid 1000 --gid 1000 --disabled-password --gecos "" app && \
mkdir -p $RAILS_ROOT && \
mkdir -p $BUNDLE_PATH && \
mkdir -p $RAILS_ROOT/tmp/pids && \
mkdir -p $RAILS_ROOT/log

# Setup timezone data
ENV TZ=Etc/UTC
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

# Create the working directory
WORKDIR $RAILS_ROOT
RUN apt-get update -o Dir::Etc::sourcelist=/etc/apt/sources.list.d/yarn.list && apt-get install -y yarn=1.22.5-1

# bundle install
COPY .ruby-version $RAILS_ROOT/.ruby-version
COPY Gemfile $RAILS_ROOT/Gemfile
COPY Gemfile.lock $RAILS_ROOT/Gemfile.lock

RUN bundle config build.nokogiri --use-system-libraries
RUN bundle config set --local deployment 'true'
RUN bundle config set --local path $BUNDLE_PATH
RUN bundle config set --local without 'deploy development doc test'
RUN bundle install --jobs $(nproc)
RUN bundle binstubs --all

# yarn install
COPY package.json $RAILS_ROOT/package.json
COPY yarn.lock $RAILS_ROOT/yarn.lock
RUN yarn install --production=true --frozen-lockfile --cache-folder .yarn-cache
Expand All @@ -116,56 +97,140 @@ COPY ./.browserslistrc ./.browserslistrc
# Copy keys
COPY keys.example $RAILS_ROOT/keys

# Copy big files
ARG LARGE_FILES_USER
ARG LARGE_FILES_TOKEN
RUN mkdir -p $RAILS_ROOT/geo_data && chmod 755 $RAILS_ROOT/geo_data
RUN mkdir -p $RAILS_ROOT/pwned_passwords && chmod 755 $RAILS_ROOT/pwned_passwords
RUN git clone --depth 1 https://$LARGE_FILES_USER:$LARGE_FILES_TOKEN@gitlab.login.gov/lg-public/idp-large-files.git && \
cp idp-large-files/GeoIP2-City.mmdb $RAILS_ROOT/geo_data/ && \
cp idp-large-files/GeoLite2-City.mmdb $RAILS_ROOT/geo_data/ && \
cp idp-large-files/pwned-passwords.txt $RAILS_ROOT/pwned_passwords/ && \
rm -r idp-large-files
RUN mkdir -p /usr/local/share/aws && \
curl https://truststore.pki.rds.amazonaws.com/global/global-bundle.pem > /usr/local/share/aws/rds-combined-ca-bundle.pem

# Copy robots.txt
COPY public/ban-robots.txt $RAILS_ROOT/public/robots.txt

# Copy application.yml.default to application.yml
COPY ./config/application.yml.default.prod $RAILS_ROOT/config/application.yml

# Setup config files
COPY config/agencies.localdev.yml $RAILS_ROOT/config/agencies.yml
COPY config/iaa_gtcs.localdev.yml $RAILS_ROOT/config/iaa_gtcs.yml
COPY config/iaa_orders.localdev.yml $RAILS_ROOT/config/iaa_orders.yml
COPY config/iaa_statuses.localdev.yml $RAILS_ROOT/config/iaa_statuses.yml
COPY config/integration_statuses.localdev.yml $RAILS_ROOT/config/integration_statuses.yml
COPY config/integrations.localdev.yml $RAILS_ROOT/config/integrations.yml
COPY config/partner_account_statuses.localdev.yml $RAILS_ROOT/config/partner_account_statuses.yml
COPY config/partner_accounts.localdev.yml $RAILS_ROOT/config/partner_accounts.yml
COPY certs.example $RAILS_ROOT/certs
COPY config/service_providers.localdev.yml $RAILS_ROOT/config/service_providers.yml

# Precompile assets
RUN bundle exec rake assets:precompile --trace

# get service_providers.yml and related files
ARG SERVICE_PROVIDERS_KEY
RUN echo "$SERVICE_PROVIDERS_KEY" > private_key_file ; chmod 600 private_key_file
RUN GIT_SSH_COMMAND='ssh -i private_key_file -o IdentitiesOnly=yes -o StrictHostKeyChecking=accept-new' git clone --depth 1 git@github.com:18F/identity-idp-config.git
RUN mkdir -p $RAILS_ROOT/config/ $RAILS_ROOT/public/assets/images
RUN cp identity-idp-config/*.yml $RAILS_ROOT/config/
RUN cp -rp identity-idp-config/certs $RAILS_ROOT/
RUN cp -rp identity-idp-config/public/assets/images/sp-logos $RAILS_ROOT/public/assets/images/

# set up deploy.json
ARG ARG_CI_COMMIT_BRANCH="branch_placeholder"
ARG ARG_CI_COMMIT_SHA="sha_placeholder"
RUN mkdir -p $RAILS_ROOT/public/api/
RUN echo "{\"branch\":\"$ARG_CI_COMMIT_BRANCH\",\"git_sha\":\"$ARG_CI_COMMIT_SHA\"}" > $RAILS_ROOT/public/api/deploy.json

# Download RDS Combined CA Bundle
RUN mkdir -p /usr/local/share/aws \
&& curl https://s3.amazonaws.com/rds-downloads/rds-combined-ca-bundle.pem > /usr/local/share/aws/rds-combined-ca-bundle.pem \
&& chmod 644 /usr/local/share/aws/rds-combined-ca-bundle.pem

# Generate and place SSL certificates for puma
RUN openssl req -x509 -sha256 -nodes -newkey rsa:2048 -days 1825 \
-keyout $RAILS_ROOT/keys/localhost.key \
-out $RAILS_ROOT/keys/localhost.crt \
-subj "/C=US/ST=Fake/L=Fakerton/O=Dis/CN=localhost"
-subj "/C=US/ST=Fake/L=Fakerton/O=Dis/CN=localhost" && \
chmod 644 $RAILS_ROOT/keys/localhost.key $RAILS_ROOT/keys/localhost.crt

#########################################################################
# This is the main image.
#########################################################################
FROM ruby:3.3.1-slim

# Set environment variables
ENV RAILS_ROOT /app
ENV RAILS_ENV production
ENV NODE_ENV production
ENV RAILS_SERVE_STATIC_FILES true
ENV RAILS_LOG_TO_STDOUT true
ENV RAILS_LOG_LEVEL debug
ENV BUNDLE_PATH /app/vendor/bundle
ENV BUNDLER_VERSION 2.5.6
ENV POSTGRES_SSLMODE prefer
ENV POSTGRES_NAME idp
ENV POSTGRES_HOST postgres
ENV POSTGRES_USERNAME postgres
ENV POSTGRES_PASSWORD postgres
ENV POSTGRES_WORKER_SSLMODE prefer
ENV POSTGRES_WORKER_NAME idp-worker-jobs
ENV POSTGRES_WORKER_HOST postgres-worker
ENV POSTGRES_WORKER_USERNAME postgres
ENV POSTGRES_WORKER_PASSWORD postgres
ENV REDIS_IRS_ATTEMPTS_API_URL redis://redis:6379/2
ENV REDIS_THROTTLE_URL redis://redis:6379/1
ENV REDIS_URL redis://redis:6379
ENV ASSET_HOST http://localhost:3000
ENV DOMAIN_NAME localhost:3000
ENV PIV_CAC_SERVICE_URL https://localhost:8443/
ENV PIV_CAC_VERIFY_TOKEN_URL https://localhost:8443/
ENV REMOTE_ADDRESS_HEADER X-Forwarded-For

# Install dependencies
RUN apt-get update -qq && \
apt-get install -y --no-install-recommends \
openssh-client \
git-core \
curl \
zlib1g-dev \
libssl-dev \
libreadline-dev \
libyaml-dev \
libxml2-dev \
libxslt1-dev \
libcurl4-openssl-dev \
software-properties-common \
libffi-dev \
libpq-dev \
unzip && \
rm -rf /var/lib/apt/lists/*

# get RDS combined CA bundle
COPY --from=builder /usr/local/share/aws/rds-combined-ca-bundle.pem /usr/local/share/aws/rds-combined-ca-bundle.pem

# Create a new user and set up the working directory
RUN addgroup --gid 1000 app && \
adduser --uid 1000 --gid 1000 --disabled-password --gecos "" app && \
mkdir -p $RAILS_ROOT && \
mkdir -p $RAILS_ROOT/tmp/pids && \
mkdir -p $RAILS_ROOT/log

# Setup timezone data
ENV TZ=Etc/UTC
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

# Create the working directory
WORKDIR $RAILS_ROOT

# set bundler up
RUN bundle config build.nokogiri --use-system-libraries
RUN bundle config set --local deployment 'true'
RUN bundle config set --local path $BUNDLE_PATH
RUN bundle config set --local without 'deploy development doc test'

# Copy big files
RUN mkdir -p $RAILS_ROOT/geo_data && chmod 755 $RAILS_ROOT/geo_data
RUN mkdir -p $RAILS_ROOT/pwned_passwords && chmod 755 $RAILS_ROOT/pwned_passwords
COPY --from=builder /idp-large-files/GeoIP2-City.mmdb $RAILS_ROOT/geo_data/
COPY --from=builder /idp-large-files/GeoLite2-City.mmdb $RAILS_ROOT/geo_data/
COPY --from=builder /idp-large-files/pwned-passwords.txt $RAILS_ROOT/pwned_passwords/pwned_passwords.txt

# copy in all the stuff from the builder image
COPY --from=builder $RAILS_ROOT $RAILS_ROOT

# copy keys in
COPY --from=builder $RAILS_ROOT/keys/localhost.key $RAILS_ROOT/keys/
COPY --from=builder $RAILS_ROOT/keys/localhost.crt $RAILS_ROOT/keys/

# make everything the proper perms after everything is initialized
RUN chown -R app:app $RAILS_ROOT/tmp && \
chown -R app:app $RAILS_ROOT/log && \
find $RAILS_ROOT -type d | xargs chmod 755

# get rid of suid/sgid binaries
RUN find / -perm /4000 -type f | xargs chmod u-s
RUN find / -perm /2000 -type f | xargs chmod g-s

# Expose the port the app runs on
EXPOSE 3000

Expand Down
2 changes: 2 additions & 0 deletions dockerfiles/idp_prod.Dockerfile.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/app/node_modules