scientist-softserv / oral-history

UCLA LIBRARY-CENTER FOR ORAL HISTORY RESEARCH --Documenting the histories of Los Angeles-- The UCLA Library creates a vibrant nexus of ideas, collections, expertise, and spaces in which users illuminate solutions for local and global challenges. We constantly evolve to advance UCLA’s research, education, and public service mission by empowering and
https://oralhistory.library.ucla.edu/
0 stars 0 forks source link

Docker Development Setup

Special Linux instructions

If you are running Linux, some additional steps are required to set up a suitable host environment, due to the current implementation in Dockerfile and docker-compose.yml.

  1. A local user/group on your (host) machine must match the app user, with uid/gid 9999.
  2. Set the proper permissions inside the web container.

This worked, in a Debian (via WSL2) host environment:

# Become root, or run each of the following via sudo
sudo bash

# Step 1, from above
# The group and user can be called anything on the host; this uses oh_public for both
# Create a group with gid 9999, to match the web container's app user
groupadd -g 9999 oh_public

# Create a user with uid 9999, also matching web's app user
# Also create home directory, and set bash shell since we're not animals
useradd oh_public -u 9999 -g 9999 -d /home/oh_public -m -s /bin/bash -c "For testing OH public build"

# Add the user to the docker group, assuming you have one,
# since running docker as root on the host is bad
usermod -a -G docker oh_public

# Step 2, from above
# Since the web image is built as root, and some things run in it as root,
# the first run can create some directories inside /home/app/webapp as root
# instead of as the app user.  This means the app user... can't write to them.

# Start the application and monitor logs.  If you see repeated messages like this:

web_1       | /usr/local/rvm/gems/ruby-2.7.7/gems/bootsnap-1.4.9/lib/bootsnap/compile_cache.rb:29:in `permission_error': bootsnap doesn't have permission to write cache entries in '/home/app/webapp/tmp/cache/bootsnap-compile-cache' (or, less likely, doesn't have permission to read '/usr/local/rvm/gems/ruby-2.7.7/gems/railties-6.1.7.3/lib/rails/commands.rb') (Bootsnap::CompileCache::PermissionError)

# Run the following as root.  This only needs to be done once,
# after the initial startup (or if you remove the whole application and start over)
cd /home/oh_public/oral-history # or wherever on the host this application is
chown -R oh_public:oh_public .

Load database and import some sample data using the following commands

docker compose exec web bundle exec rake db:migrate
docker compose exec web bundle exec rake db:seed
docker compose exec web bundle exec rake import[100]

If you get an error on the final line, and are using the zsh shell, you will need to escape the square brackets.

docker compose exec web bundle exec rake import\[100\]

Note: The 100 in import[100] limits the number of assets initially loaded. You may adjust this as desired.

At this point you should be able to access the application at http://127.0.0.1:8000/

Sign into the Admin Dashboard

The default development username and password are:

Common Developer Recipes:

Drop into a bash console inside docker container:

Drop into a sh console inside docker container:

Drop into a rails console:

Drop into a postgresql console:

Build and Deploy Process

Optional: Contact DevSupport for Argo account for log access

Application Only Changes

On merging and pushing this change to main, the new image: tag value will trigger a new deployment. This process is automatic when updating [stage,test]-oralhistory-values.yaml.

For production, prod-oralhistory-values.yaml should be updated and DevSupport notified, and is not automatically deployed.

Chart Changes

If there are changes to files under templates/, extra steps are required to propagate the chart changes.