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

Updates Dockerfile to prepare for production #66

Merged
merged 54 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from 42 commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
e6308b4
initial commit for k8s support
Sep 20, 2023
6de8c61
executor
Sep 20, 2023
9071f84
syntax
Sep 20, 2023
ae96235
target production
Sep 20, 2023
a1310c6
adds database config
Sep 20, 2023
8168685
Merge branch 'k8s' into APPINT-192
bryanlopezrr Feb 8, 2024
aae1d01
working dockerfile
bryanlopezrr Feb 16, 2024
77100bf
working docker compose
bryanlopezrr Feb 16, 2024
1ad67d8
adding setup script, modifying docker file, docker-compose file and a…
bryanlopezrr Feb 16, 2024
51610df
adding comments to script
bryanlopezrr Feb 16, 2024
8ac9dea
adding vault message to README
bryanlopezrr Feb 16, 2024
e4a00dd
renaming local setup script
bryanlopezrr Feb 16, 2024
99982f1
changing permissions in /app for rubocop to work?
bryanlopezrr Feb 16, 2024
f29cf8f
Adding dependency to Gemfile, updating writable permissions in Docker…
bryanlopezrr Feb 19, 2024
0d0f886
updating path in pipeline build
bryanlopezrr Feb 19, 2024
f177646
modifying the path for the code coverage report and build dependency
bryanlopezrr Feb 19, 2024
f080428
testing adding gemcove to build
bryanlopezrr Feb 19, 2024
c097262
testing adding gemcove to build
bryanlopezrr Feb 19, 2024
6894a99
testing another variation
bryanlopezrr Feb 19, 2024
2d459cf
modifying docker image, docker compose, removing rspec from build config
bryanlopezrr Feb 20, 2024
61eafbe
refactoring the Dockerfile
bryanlopezrr Feb 20, 2024
fb985a2
Attempting to fix rubocop due to insufficient permissions
bryanlopezrr Feb 20, 2024
d3833d7
changing permissions on Gemfiles
bryanlopezrr Feb 20, 2024
a3d2412
upgrading Dockerfile
bryanlopezrr Feb 20, 2024
9bcfefb
refactoring dockerfile, updating circle ci config, updating docker-co…
bryanlopezrr Feb 20, 2024
4df5d34
set bundle path
Feb 20, 2024
726857e
run apt-get as root
Feb 20, 2024
864ea68
updates dockerignore
Feb 20, 2024
bc5e9b1
change order
Feb 20, 2024
b0d233c
try this
Feb 20, 2024
b2a4e28
fdsa
Feb 20, 2024
b1567e1
try these
Feb 20, 2024
38e1d88
bundle
Feb 20, 2024
48bbac1
test adding bundle config
Feb 20, 2024
36b92e7
testing out modifying a configuration within ruby for push during ci …
bryanlopezrr Feb 21, 2024
786883b
adding a dummy credential key to test cicd for publishing the docker …
bryanlopezrr Feb 21, 2024
58e7772
adding dummy secret key
bryanlopezrr Feb 21, 2024
0b0dbf6
Refactoring dockerfile to map scholarsphere and other feedback
bryanlopezrr Feb 21, 2024
6e7b7a2
reverting precompile configuration to false as originally set up
bryanlopezrr Feb 21, 2024
f41779a
reverting mysql version from 10.3 to 10.2
bryanlopezrr Feb 21, 2024
1018f73
removing dummy credentials file
bryanlopezrr Feb 21, 2024
8235b03
lint dockerfile, remove unnecessary steps.
Feb 21, 2024
4da6391
reverting Gemfiles to what is on the master branch
bryanlopezrr Feb 21, 2024
957c167
fix rspec script
Feb 21, 2024
08fa1e9
adds missing config
whereismyjetpack Apr 30, 2024
e74f3c6
needs sftp
whereismyjetpack May 2, 2024
d004059
Add hostname so script can run in multiple environments
jrpatterson May 3, 2024
9584552
Variable change
jrpatterson May 3, 2024
47ed2d9
Merge pull request #70 from psu-libraries/lionpath-by-env
whereismyjetpack May 3, 2024
5d56ee0
Variable Name fixup
jrpatterson May 3, 2024
5688874
Consistent variable names
jrpatterson May 6, 2024
da5ca20
Revert this one
jrpatterson May 6, 2024
f699772
Match to yaml config
jrpatterson May 6, 2024
3b61779
Merge pull request #71 from psu-libraries/lionpath-by-env
jrpatterson May 6, 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 .bundle/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
BUNDLE_PATH: "vendor/bundle"
56 changes: 32 additions & 24 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,30 @@
version: 2.1

orbs:
docker: circleci/[email protected]

jobs:
publish:
executor: docker/docker
steps:
- setup_remote_docker
- checkout
- docker/check:
registry: harbor.k8s.libraries.psu.edu
- docker/build:
image: library/fams-tools
registry: harbor.k8s.libraries.psu.edu
use-buildkit: true
tag: "$CIRCLE_SHA1"
extra_build_args: "--target=production"
- docker/push:
image: library/fams-tools
registry: harbor.k8s.libraries.psu.edu
tag: "$CIRCLE_SHA1"
build:
machine: true
steps:
- checkout
- run:
name: "Setup Files and Directories"
command: |
mv config/activity_insight.yml.circleci config/activity_insight.yml &&
mv config/database.yml.circleci config/database.yml &&
mv config/integration_passcode.yml.circleci config/integration_passcode.yml &&
mkdir app/parsing_files &&
mkdir spec/fixtures/post_prints &&
mkdir public/psu &&
mkdir public/log

- run:
name: "Build Container"
command: |
Expand All @@ -31,19 +40,18 @@ jobs:
sleep 10s &&
docker-compose up -d

- run:
name: "Rubocop"
command: |
docker-compose exec web bundle exec rubocop

- run:
name: "Rspec"
command: |
# download test reporter as a static binary
curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > bin/cc-test-reporter
chmod +x bin/cc-test-reporter
# Run tests
docker-compose exec web bundle exec rspec
# Send report to Code Climate
bin/cc-test-reporter format-coverage -t simplecov -o codeclimate.json -p /fams_tools coverage/.resultset.json
bin/cc-test-reporter upload-coverage -i codeclimate.json
docker-compose exec web /app/bin/ci-rspec

workflows:
version: 2
fams:
jobs:
- build
- publish:
requires:
- build
context:
- org-global
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
vendor/cache
vendor/bundle
.git
.repos
.cache
public/psu
public/log
/log/*
Expand Down
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

# Ignore bundler config.
/.bundle
!.bundle/config

# Ignore the default SQLite database.
/db/*.sqlite3
Expand All @@ -17,7 +18,6 @@
!/log/.keep
!/tmp/.keep
config/secrets.yml
config/database.yml
spec/examples.txt

/node_modules
Expand All @@ -40,3 +40,7 @@ spec/examples.txt
/public/post_prints
/coverage
/vendor/bundle/**/*

.env
.cache
.bash_history
66 changes: 48 additions & 18 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,23 +1,53 @@
FROM ruby:3.1.3
FROM harbor.k8s.libraries.psu.edu/library/ruby-3.1.3-node-16:20231225 as base
ARG UID=1001
WORKDIR /app

RUN mkdir /fams_tools
WORKDIR /fams_tools
SHELL ["/bin/bash", "-o", "pipefail", "-c"]

RUN apt-get clean
RUN apt-get update
# For zipping and unzipping
RUN apt-get install -y zip unzip
# Packages for webkit
RUN apt-get install -y g++ libqt5webkit5-dev gstreamer1.0-plugins-base gstreamer1.0-tools gstreamer1.0-x xvfb
RUN useradd -l -u ${UID} app -d /app && \
chown -R app /app

RUN gem install bundler --no-document -v '2.1.4'
# hadolint ignore=DL3008
RUN apt-get update && apt-get install -y --no-install-recommends g++ \
libqt5webkit5-dev \
zip \
unzip \
gstreamer1.0-plugins-base \
gstreamer1.0-tools \
gstreamer1.0-x \
libmariadb-dev \
libmariadbclient-dev \
xvfb \
qt5-default \
&& rm -rf /var/lib/apt/lists/*

COPY Gemfile /fams_tools/Gemfile
COPY Gemfile.lock /fams_tools/Gemfile.lock
whereismyjetpack marked this conversation as resolved.
Show resolved Hide resolved
RUN bundle install
COPY . /fams_tools
USER app
COPY --chown=app Gemfile Gemfile.lock /app/
COPY --chown=app .bundle/config /app/.bundle/config
# in the event that bundler runs outside of docker, we get in sync with it's bundler version
RUN gem install bundler -v "$(grep -A 1 "BUNDLED WITH" Gemfile.lock | tail -n 1)"

COPY entrypoint.sh /usr/bin/
RUN chmod +x /usr/bin/entrypoint.sh
ENTRYPOINT ["entrypoint.sh"]
EXPOSE 3000
# - - - - - - - - - - - -
FROM base as dev
WORKDIR /app
USER app
COPY --chown=app . /app
CMD ["/app/bin/startup"]

# - - - - - - - - - - - -
FROM base as production
WORKDIR /app

COPY --chown=app . /app

RUN bundle install --without development test && \
bundle clean && \
rm -rf /app/.bundle/cache && \
rm -rf /app/vendor/bundle/ruby/*/cache

RUN RAILS_ENV=production \
SECRET_KEY_BASE=rails_bogus_key \
bundle exec rails assets:precompile

USER app
CMD ["/app/bin/startup"]
7 changes: 5 additions & 2 deletions Gemfile
whereismyjetpack marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ gem 'webmock'
# Stream xlsx files
gem 'creek'

# Dependency for bootstrap:
gem 'popper_js', '~> 1.16.1'

# UX framework
gem 'bootstrap', '~> 4.6'

Expand Down Expand Up @@ -99,8 +102,8 @@ group :development, :test do
gem 'rubocop', '= 1.42.0'
gem 'rubocop-rails'
gem 'rubocop-rspec'
# Code coverage
gem 'simplecov', '~> 0.17.0'
# Code coveragee
gem 'simplecov', '~> 0.18.0'
# Use Puma as the app server
# Since passenger is used in production this doesn't need to be
# installed on the RedHat server (it fails anyway)
Expand Down
10 changes: 5 additions & 5 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -353,11 +353,10 @@ GEM
websocket (~> 1.0)
shoulda-matchers (4.0.0.rc1)
activesupport (>= 4.2.0)
simplecov (0.17.1)
simplecov (0.18.5)
docile (~> 1.1)
json (>= 1.8, < 3)
simplecov-html (~> 0.10.0)
simplecov-html (0.10.2)
simplecov-html (~> 0.11)
simplecov-html (0.12.3)
spreadsheet (1.3.0)
ruby-ole
spring (4.1.3)
Expand Down Expand Up @@ -446,6 +445,7 @@ DEPENDENCIES
net-ldap
nio4r (= 2.5.8)
pdf-reader
popper_js (~> 1.16.1)
puma (~> 5.6)
racc (= 1.6.2)
rails (~> 7.0.7.1)
Expand All @@ -458,7 +458,7 @@ DEPENDENCIES
sass-rails (~> 6.0)
selenium-webdriver
shoulda-matchers (= 4.0.0.rc1)
simplecov (~> 0.17.0)
simplecov (~> 0.18.0)
spreadsheet
spring (~> 4)
spring-watcher-listen (~> 2.1.0)
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@ The courses taught data import runs automatically at 00:00 on February 1st, June

The contract/grant data import runs on the second Monday of every month at 01:00. The data is obtained from the CSV generated by the SIMS team at this endpoint: https://service.sims.psu.edu/digitalmeasures/dmresults.csv . This integration is also dependent on the CONGRANT.csv backup obtained from this Digital Measures endpoint: https://webservices.digitalmeasures.com/login/service/v4/SchemaData:backup/INDIVIDUAL-ACTIVITIES-University . The backup is used to detect if there are any duplicates in the current Activity Insight system and remove them before the import runs.

## Development
## Development

After running the container, any changes to the code on your local machine will change in the container. Sometimes the rails server needs to be restarted to pick up certain changes. To do this run:

`bundle exec rails restart`

from inside the web container.

## Testing

From within the web container
Expand Down
28 changes: 28 additions & 0 deletions bin/ci-rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash
# script to run rspec as CI would

set -e

export RAILS_ENV=test

# Setup app configuration and ensure directories
cp config/activity_insight.yml.circleci config/activity_insight.yml
# cp config/databse.yml.circleci config/database.yml
cp config/integration_passcode.yml.circleci config/integration_passcode.yml
mkdir app/parsing_files
mkdir spec/fixtures/post_prints
mkdir public/psu
mkdir public/log

## check bundle
bundle check || bundle

## setup databse
bundle exec rails db:create db:migrate


## run rubocop
bundle exec rubocop

## run rspec
bundle exec rspec
15 changes: 15 additions & 0 deletions bin/startup
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash
set -e

if [ -f /vault/secrets/config ]; then
. /vault/secrets/config
fi

if [ "${RAILS_ENV:-development}" != 'production' ]; then
bundle check || bundle
bundle exec rails db:create db:migrate
fi

whereismyjetpack marked this conversation as resolved.
Show resolved Hide resolved
rm -f /app/tmp/pids/server.pid

exec bundle exec rails s -p 3000 -b '0.0.0.0'
4 changes: 2 additions & 2 deletions config/cable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ test:

production:
adapter: redis
url: redis://localhost:6379/1
channel_prefix: ai_integration_production
url: <%= ENV.fetch("REDIS_URI") { "redis://localhost:6379/1" } %>
channel_prefix: <% ENV.fetch("CHANNEL_PREFIX") { "ai_integration_production" } %>
21 changes: 21 additions & 0 deletions config/database.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
default: &default
adapter: mysql2
encoding: utf8mb4
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
username: <%= ENV.fetch("MYSQL_USER") { "root" } %>
password: <%= ENV.fetch("MYSQL_PASSWORD") { "root" } %>
host: <%= ENV.fetch("MYSQL_HOST") { "127.0.0.1" } %>
port: 3306

development:
<<: *default
database: <%= ENV.fetch("MYSQL_DATABASE") { "ai_integration" } %>

production:
<<: *default
database: <%= ENV.fetch("MYSQL_DATABASE") { "ai_integration" } %>


test:
<<: *default
database: <%= ENV.fetch("MYSQL_DATABASE") { "ai_integration" } %>_test
21 changes: 16 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: '3.2'
version: '3.3'
services:
db:
environment:
Expand All @@ -10,8 +10,15 @@ services:
- ai-integration-data:/var/lib/mysql
web:
environment:
# RAILS_ENV: production # The startup script defaults to development, change to production if need be
MYSQL_HOST: db
build: .
MYSQL_PASSWORD: ai_integration
build:
args:
UID: "${UID:-1001}"
context: .
target: dev
whereismyjetpack marked this conversation as resolved.
Show resolved Hide resolved
dockerfile: Dockerfile
ports:
- "3000:3000"
depends_on:
Expand All @@ -22,7 +29,11 @@ services:
- type: bind
consistency: cached
source: .
target: /fams_tools/

target: /app/
networks:
default:
driver: bridge
driver_opts:
com.docker.network.driver.mtu: 1400
volumes:
ai-integration-data:
ai-integration-data: {}
9 changes: 0 additions & 9 deletions entrypoint.sh

This file was deleted.

Loading