title | theme | revealOptions | ||
---|---|---|---|---|
SPARC in a bottle |
night |
|
Containerizing SPARCRequest
I have no relevant personal/professional/financial relationship with products or companies presented today.
$ finger -s benton
Email Name Idle Login Office
[email protected] Erik Benton 28d Aug 31 OHSU OCTRI CRI Apps
Clinical Research Informatics - Applications
Oregon Clinical & Translational Research Institute
Oregon Health & Science University
(What is a container?)
- Not a Virtual Machine
- Virtualizes the OS and network but not hardware
- Keeps things smaller, faster and portable
Note: Containers are a method of packaging an application and its dependencies into a single artifact that can be run on any system.
As opposed to a VM containers rely on the underlying host OS, making them more lightweight and quicker to run. Better resource allocation where as a hypervisor must partition its resources to each VM, containers use only the resources necessary
Security: VMs have more stringent security controls due to the complete independence of resource, but containers if run correctly can offer many of the same protections
- Image - Executable package that contains all the necessary components of an application
- Container - A running instance of an image
Docker
Note: Main developers/drivers of container technologies. Started in 2013 provided tools to take advantage of a number of Linux kernel features to make containers a reality and easy to use by a wide audience.
Consistency of environment and dependencies
Better resource utilization
Ease of deployment
Simplify developer experience
Note: Stack is not consistent with our other tools. Packaging as an image makes it easier to run with all the necessary tools included
Simplify packaging and deployment to servers
Environment isolation
Two image build processes
- octri.ohsu.edu/sparc-request-base
- octri.ohsu.edu/sparc-request
octri.ohsu.edu/sparc-request-base
FROM ruby:2.5
ARG SPARC_VERSION=3.7.1
ENV LANG=en_US.UTF-8
# Add dependencies for Rails and the Paperclip gem
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg \
| apt-key add - && \
echo "deb https://dl.yarnpkg.com/debian/ stable main" \
| tee /etc/apt/sources.list.d/yarn.list && \
apt-get update && \
apt-get install -y \
ghostscript \
imagemagick \
yarn \
&& rm -rf /var/lib/apt/lists/*
RUN curl -L -o sparc-request.tgz \
https://github.com/sparc-request/sparc-request/archive/release-${SPARC_VERSION}.tar.gz && \
tar xvf sparc-request.tgz && \
mv sparc-request-release-${SPARC_VERSION} /sparc && \
rm sparc-request.tgz
WORKDIR /sparc
RUN gem install bundler && \
bundle install --without="development test" && \
yarn install
EXPOSE 3000
CMD ["rails", "s", "-b", "0.0.0.0"]
Note:
- Base image has no customization just vanilla build instructions
- Checkout tag from Github
octri.ohsu.edu/sparc-request
FROM octri.ohsu.edu/sparc_request_base:3.7.1
COPY ./deps/sparc/assets/images/blank_logo.jpg /sparc/app/assets/images/logos/blank_logo.jpg
COPY ./deps/sparc/assets/images/octri_logo.jpg /sparc/app/assets/images/logos/octri_logo.jpg
COPY ./deps/sparc/database.yml /sparc/config/database.yml
COPY ./deps/sparc/development.rb /sparc/config/environments/development.rb
COPY ./deps/sparc/staging.rb /sparc/config/environments/staging.rb
COPY ./deps/sparc/production.rb /sparc/config/environments/production.rb
COPY ./deps/sparc/locales/*.yml /sparc/config/locales/
COPY ./deps/sparc/reports/*.rb /sparc/app/lib/reports/
COPY ./deps/sparc/tasks/*.rake /sparc/lib/tasks/
COPY ./deps/sparc/remote_service_notifier_job.rb /sparc/app/jobs/remote_service_notifier_job
...
Note: Maintain a development branch. Mostly back-ports of fixes, reports, localization files, etc.
Jenkins CI
- Build base image
- Build OCTRI image
- Merge all changes to main branch prior to release
- Job builds main branch
- Deploy to production
Note:
- OCTRI image is built with every commit to the
development
branch - Maintaining separate
development
andmaster
branches allows us to maintain versions and cherry-pick commits into our production instance
Kubernetes
Note: Beyond simply running the container we use a container orchestration system, in this case a Kubernetes cluster, which runs on both VMs and physical systems. This ensures that the application is available and scaled appropriately.
External configuration is crucial
SPARCRequest is opinionated
Delayed Jobs require their own container
Ruby on Rails make customization "easy"
Note:
-
All configuration should be available to be set in the environment - a number of the configuration files required customization to use environment variables hence we maintain a set of patches to correct this
-
SPARC must be run from the root context of a domain - much of the coffee script is context aware and thus prevents alternative deployment approaches.
-
The delayed_jobs required its own container, because of various factors in the app it stopped working for us as a Cron - required by upgrade to 3.6 - delays in emails and calculations
-
Because Ruby/Rails we are successfully able to customize our images to run in our environment.
Packaging in a container helps insulate our changes and requirements from the original SPARC software allow us to adjust SPARC to our needs rather than forcing the original SPARC code to adapt to us. It means we don't have to pollute our systems with a bunch of dependencies that we have to manage over time and allows us to use an immutable version of SPARC directly from the source.
- https://en.wikipedia.org/wiki/Docker_(software)
- https://www.docker.com/resources/what-container
- https://stackoverflow.com/questions/16047306/how-is-docker-different-from-a-virtual-machine
- https://docs.docker.com/engine/faq/#what-does-docker-technology-add-to-just-plain-lxc
- Title background credit: doomlordvekk, Plasma, used under the Creative Commons license