Skip to content

Latest commit

 

History

History
103 lines (72 loc) · 4.14 KB

File metadata and controls

103 lines (72 loc) · 4.14 KB

TUPRESS

  • This site is primarily based on the Book model.
  • We update books daily with metadata from the PressWorks third party application (a Filemaker Pro instance administered by another company).
  • An xml file is generated on their server (which is in the Temple umbrella) and then FTP'd to the production server via a cron job on the server.
  • The rails app then ingests that xml file, creating, books, catalogs, series, subjects, etc...
  • The backend is Administrate by Thoughtbot.
  • It uses AWS for image storage.

Getting started

Load Data

For the local instance:

bundle exec rails sync:pressworks:all[<utf-16 xml file from pressworks>]

For the docker instance:

  • By default the database sync is not run locally. Use make load-data to run it.

The app database needs to be initialized in oder for make load-data to work. If that has not happened, then run make db-init (this only needs to run once).

If using docker-compose:

  • source .env or set LOCAL_BASE_IMAGE manually.
  • run docker-compose up

Turnstile

Forms can be protected with Cloudflare Turnstile. Set both env vars and enable the feature flag at /flipflop:

  • TURNSTILE_SITE_KEY
  • TURNSTILE_SECRET_KEY

The app loads credentials through config/turnstile.yml into Rails.configuration.turnstile. The feature is toggled via the cloudflare_turnstile Flipflop flag (default: off). If disabled or credentials are absent, form pages and submissions continue with their existing behavior.

Start the Application using Docker as an alternative

We defined a Makefile with many useful commands for local development. These commands replicate the process used to deploy in the Gitlab pipeline.

  • To build an image: make build
    • BASE_IMAGE can be set to override the default base_image: make build BASE_NAME=ruby:3.1.0-alpine
    • PLATFORM can be set to override default platform used: make build PLATFORM=arm64
  • To start the dockerized app, run make run
  • To deploy prod image: make deploy VERSION=x
    • VERSION=latest by default
  • To run security check on image: make scan
    • This depends on trivy. Run brew install aquasecurity/trivy/trivy to make this available locally.
  • To run a shell with image: make shell
  • To run docker lint: make lint
    • This depends on hadolint. Run brew install hadolint to make this available locally.

Deployment

QA

Production

  • In order to deploy to production, create a release in GitLab. The release tag normally used for releases should continue to be added manually during the release process, e.g. “1.3.3”. Gitlab will then automatically tag the release image with both a “prod” tag and a release tag that references the git tag (e.g. 1.3.3). The newly tagged image will then be deployed to the production environment.

Profiling

Three helper scripts are available for local profiling runs:

  • bin/profile-stackprof
  • bin/profile-ruby-prof
  • bin/profile-flamegraph

Each script supports two modes:

  • runner evaluates a Ruby expression in the Rails app context.
  • request profiles one or more application paths with Rack::MockRequest.

StackProf

Write a stack sample dump to tmp/stackprof and print a text summary:

bin/profile-stackprof runner 'Book.displayable.limit(10).load'
STACKPROF_MODE=cpu bin/profile-stackprof runner 'Webpage.limit(10).load'
bin/profile-stackprof request /
bin/profile-stackprof request /books /subjects

ruby-prof

Write profiler reports to tmp/ruby-prof:

bin/profile-ruby-prof runner 'Book.displayable.limit(10).load'
RUBY_PROF_PRELUDE='scope = Book.displayable.limit(50)' bin/profile-ruby-prof runner 'scope.load'
RUBY_PROF_PRINTER=graph_html bin/profile-ruby-prof runner 'Webpage.limit(10).load'
bin/profile-ruby-prof request /
RUBY_PROF_PRINTER=multi bin/profile-ruby-prof request /books /subjects

flamegraph

Write an HTML flamegraph to tmp/flamegraph:

bin/profile-flamegraph runner 'Book.displayable.limit(10).load'
FLAMEGRAPH_PRELUDE='scope = Webpage.limit(25)' bin/profile-flamegraph runner 'scope.load'
bin/profile-flamegraph request /