Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
200 changes: 200 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
name: Build / Test / Push

on:
push:
branches:
- '**'
workflow_dispatch:

env:
BUILD_SUFFIX: -build-${{ github.run_id }}_${{ github.run_attempt }}
DOCKER_METADATA_SET_OUTPUT_ENV: 'true'

jobs:
build:
runs-on: ${{ matrix.runner }}
outputs:
image-arm64: ${{ steps.gen-output.outputs.image-arm64 }}
image-x64: ${{ steps.gen-output.outputs.image-x64 }}
strategy:
fail-fast: false
matrix:
runner:
- ubuntu-24.04
- ubuntu-24.04-arm
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- id: build-meta
name: Docker meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}
tags: type=sha,suffix=${{ env.BUILD_SUFFIX }}

# Build cache is shared among all builds of the same architecture
- id: cache-meta
name: Docker meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}
tags: type=raw,value=buildcache-${{ runner.arch }}

- id: get-registry
name: Get the sanitized registry name
run: |
echo "registry=$(echo '${{ steps.build-meta.outputs.tags }}' | cut -f1 -d:)" | tee -a "$GITHUB_OUTPUT"

- id: build
name: Build/push the arch-specific image
uses: docker/build-push-action@v6
with:
cache-from: type=registry,ref=${{ steps.cache-meta.outputs.tags }}
cache-to: type=registry,ref=${{ steps.cache-meta.outputs.tags }},mode=max
labels: ${{ steps.build-meta.outputs.labels }}
provenance: mode=max
sbom: true
tags: ${{ steps.get-registry.outputs.registry }}
outputs: type=image,push-by-digest=true,push=true

- id: gen-output
name: Write arch-specific image digest to outputs
run: |
echo "image-${RUNNER_ARCH,,}=${{ steps.get-registry.outputs.registry }}@${{ steps.build.outputs.digest }}" | tee -a "$GITHUB_OUTPUT"

merge:
runs-on: ubuntu-24.04
needs: build
env:
DOCKER_APP_IMAGE_ARM64: ${{ needs.build.outputs.image-arm64 }}
DOCKER_APP_IMAGE_X64: ${{ needs.build.outputs.image-x64 }}
outputs:
image: ${{ steps.meta.outputs.tags }}
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- id: meta
name: Generate tag for the app image
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}
tags: type=sha,suffix=${{ env.BUILD_SUFFIX }}

- name: Push the multi-platform app image
run: |
docker buildx imagetools create \
--tag "$DOCKER_METADATA_OUTPUT_TAGS" \
"$DOCKER_APP_IMAGE_ARM64" "$DOCKER_APP_IMAGE_X64"

test:
runs-on: ubuntu-24.04
needs: merge
env:
COMPOSE_FILE: docker-compose.yml:docker-compose.ci.yml
DOCKER_APP_IMAGE: ${{ needs.merge.outputs.image }}
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Docker Compose
uses: docker/setup-compose-action@v1

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Setup the stack
run: |
docker compose build --quiet
docker compose pull --quiet
docker compose up --wait
docker compose exec app rails assets:precompile
docker compose exec -u root app chown -R nara:nara artifacts

- name: Run RSpec
if: ${{ always() }}
run: |
docker compose exec -e RAILS_ENV=test app rake check

- name: Run Rubocop
if: ${{ always() }}
run: |
docker compose exec -e RAILS_ENV=test app rubocop --format progress --format html --out artifacts/rubocop.html

- name: Run Brakeman
if: ${{ always() }}
run: |
docker compose exec -e RAILS_ENV=test app brakeman -o artifacts/brakeman.html

- name: Copy out artifacts
if: ${{ always() }}
run: |
docker compose cp app:/opt/app/artifacts ./
docker compose logs > artifacts/docker-compose-services.log
docker compose config > artifacts/docker-compose.merged.yml

- name: Upload the test report
if: ${{ always() }}
uses: actions/upload-artifact@v4
with:
name: ruby-nara Build Report (${{ github.run_id }}_${{ github.run_attempt }})
path: artifacts/*
if-no-files-found: error

push:
runs-on: ubuntu-24.04
needs:
- merge
- test
env:
DOCKER_APP_IMAGE: ${{ needs.merge.outputs.image }}
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Produce permanent image tags
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=sha
type=ref,event=branch
type=raw,value=latest,enable={{is_default_branch}}

- name: Retag and push the image
run: |
docker pull "$DOCKER_APP_IMAGE"
echo "$DOCKER_METADATA_OUTPUT_TAGS" | tr ' ' '\n' | xargs -n1 docker tag "$DOCKER_APP_IMAGE"
docker push --all-tags "$(echo "$DOCKER_APP_IMAGE" | cut -f1 -d:)"
59 changes: 59 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Push Release Tags

on:
push:
tags:
- '**'
workflow_dispatch:

env:
DOCKER_METADATA_SET_OUTPUT_ENV: 'true'

jobs:
retag:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Determine the sha-based image tag to retag
id: get-base-image
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}
tags: type=sha

- name: Verify that the image was previously built
env:
BASE_IMAGE: ${{ steps.get-base-image.outputs.tags }}
run: |
docker pull "$BASE_IMAGE"

- name: Produce release tags
id: tag-meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}
flavor: latest=false
tags: |
type=ref,event=tag
type=semver,pattern={{major}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{version}}

- name: Retag the pulled image
env:
BASE_IMAGE: ${{ steps.get-base-image.outputs.tags }}
run: |
echo "$DOCKER_METADATA_OUTPUT_TAGS" | tr ' ' '\n' | xargs -n1 docker tag "$BASE_IMAGE"
docker push --all-tags "$(echo "$BASE_IMAGE" | cut -f1 -d:)"
4 changes: 2 additions & 2 deletions .rspec
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
--require spec_helper
--format progress
--format RspecJunitFormatter
--out artifacts/rspec/specs.xml
--format html
--out artifacts/rspec.html
20 changes: 0 additions & 20 deletions Jenkinsfile

This file was deleted.

12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
# NARA casefiles web database

Rails web app for viewing the NARA case files database. This application runs on VM154 using port 3001. The database itself runs on mysql.lib.berkeley.edu.
Rails web app for viewing the NARA case files database. This application runs on Docker Swarm.

The Nara database app can be found under the existing Chinese immigration website at https://bancroft.berkeley.edu/collections/chinese-immigration-to-the-united-states-1884-1944/ alternatively, you can visit the website at https://nara.lib.berkeley.edu/
The Nara database app can be found under the archived Chinese immigration website at <https://web.archive.org/web/20220124061848/https://bancroft.berkeley.edu/collections/chinese-immigration-to-the-united-states-1884-1944/index.html>. Alternatively, you can visit the website at https://nara.lib.berkeley.edu/

## Local development and CI

Local development and CI is handled by Docker Compose. The app requires a custom MariaDB configuration variable (see [`docker-compose.yml`](docker-compose.yml)). This should get automatically loaded as you bring the container up locally, but this setting needs to be deployed to the Swarm configuration.

By default, Docker Compose will load sample data given a file in `db/dumps`. In CI, no sample data is loaded.

## Testing

Nara uses a combination of Rspec and Capybara, for it's test suites. To run a suite from the command line, run 'rspec' from the projects root directory.
Nara uses a combination of Rspec and Capybara for its test suites. To run a suite from the command line, run 'rspec' from the projects root directory.

## SimpleCov

Expand Down
14 changes: 14 additions & 0 deletions docker-compose.ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---

services:
app:
build: !reset
image: ${DOCKER_APP_IMAGE}
volumes: !override
- artifacts:/opt/app/artifacts

db:
volumes: !reset

volumes:
artifacts:
34 changes: 9 additions & 25 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,44 +1,28 @@
# ######################################################################
# NOTE
# ######################################################################
#
# This docker-compose file uses a custom database image from lap/nara-db,
# published in the GitLab container registry (containers.lib.berkeley.edu).
#
# Before running `docker-compose`, use `docker login containers.lib.berkeley.edu`
# to authenticate.
#
# (See https://git.lib.berkeley.edu/help/user/packages/container_registry/index.md#authenticate-with-the-container-registry)

services:
# adminer:
# image: adminer
# restart: always
# ports:
# - 8080:8080

db:
# For local development, set DATABASE_URL=mysql2://root:root@0.0.0.0:33306/NARA
# or use `mysql -u root -proot -h 0.0.0.0 -P 33306 -D NARA`
image: containers.lib.berkeley.edu/lap/nara-db/master:latest
image: mariadb:10
environment:
# Default password for the image is empty, but adminer doesn't support
# that (https://www.adminer.org/en/password/), so we use 'root'
# Default password for the image is empty
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: NARA
restart: always
ports:
- 3306:3306
command: --ft-min-word-len=3
volumes:
- ./db/dumps:/docker-entrypoint-initdb.d

rails:
app:
build:
context: .
target: development
depends_on:
- db
environment:
DATABASE_URL: 'mysql2://root:root@db:3306/NARA'
ports:
- 3000:3000
restart: always
volumes:
- ./:/opt/app:delegated

version: "3.7"