diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 4797bc4..b86a35e 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -48,3 +48,8 @@ updates: timezone: "UTC" cooldown: default-days: 7 + ignore: + # Dependabot only changes the Dockerfile, but CI tests on .ruby-version, so a + # Ruby bump from here ships a Ruby that CI never ran. The Ruby version bump + # workflow updates both; a new Ruby series is a deliberate upgrade. + - dependency-name: "ruby" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6acad39..12946db 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,6 +6,11 @@ on: - master pull_request: workflow_dispatch: + # Weekly rebuild of the published image, before WhyJustRun's Tuesday 10:30 UTC + # redeploy. It picks up base-image fixes, and the Dependabot updates merged that + # week: merges made with GITHUB_TOKEN don't trigger the push event. + schedule: + - cron: "0 9 * * 2" permissions: contents: read @@ -155,10 +160,28 @@ jobs: - name: Audit gems for known vulnerabilities run: gem install bundler-audit --no-document && bundle-audit check --update - push: + image: runs-on: ubuntu-24.04 - needs: [test, system-test, brakeman, audit] - if: github.event_name == 'push' + env: + RAILS_ENV: production + SECRET_KEY_BASE: placeholder + WJR_DATABASE_NAME: placeholder + WJR_DATABASE_TEST_NAME: placeholder + WJR_DATABASE_HOST: placeholder + WJR_DATABASE_USERNAME: placeholder + WJR_DATABASE_PASSWORD: placeholder + WJR_PASSWORD_SALT: placeholder + WJR_SECRET_BASE: placeholder + WJR_SECRET_TOKEN: placeholder + WJR_DEVISE_SECRET_KEY: placeholder + WJR_RECAPTCHA_SITE_KEY: placeholder + WJR_RECAPTCHA_SECRET_KEY: placeholder + WJR_SMTP_ADDRESS: placeholder + WJR_SMTP_DOMAIN: placeholder + WJR_SMTP_USER_NAME: placeholder + WJR_SMTP_PASSWORD: placeholder + WJR_DATA_FOLDER: /tmp/whyjustrun-data/ + WJR_DATA_URL: placeholder steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 @@ -166,6 +189,56 @@ jobs: - name: Build image run: docker build . --file Dockerfile --tag $IMAGE_NAME + - name: Check that the app boots in production + # The test jobs run on the runner's Ruby without precompiled assets; this runs + # the image that gets deployed (its Ruby, its gems, its asset manifest). + run: | + env_args=() + for name in RAILS_ENV SECRET_KEY_BASE ${!WJR_*}; do env_args+=(-e "$name"); done + docker run --rm --entrypoint "" "${env_args[@]}" $IMAGE_NAME \ + bundle exec rails runner 'puts "Booted Rails #{Rails.version} on Ruby #{RUBY_VERSION}"' + + push: + runs-on: ubuntu-24.04 + needs: [test, system-test, brakeman, audit, image] + # Only master is published (as `latest`), never a branch the CI was dispatched on. + if: github.ref == 'refs/heads/master' && github.event_name != 'pull_request' + env: + RAILS_ENV: production + SECRET_KEY_BASE: placeholder + WJR_DATABASE_NAME: placeholder + WJR_DATABASE_TEST_NAME: placeholder + WJR_DATABASE_HOST: placeholder + WJR_DATABASE_USERNAME: placeholder + WJR_DATABASE_PASSWORD: placeholder + WJR_PASSWORD_SALT: placeholder + WJR_SECRET_BASE: placeholder + WJR_SECRET_TOKEN: placeholder + WJR_DEVISE_SECRET_KEY: placeholder + WJR_RECAPTCHA_SITE_KEY: placeholder + WJR_RECAPTCHA_SECRET_KEY: placeholder + WJR_SMTP_ADDRESS: placeholder + WJR_SMTP_DOMAIN: placeholder + WJR_SMTP_USER_NAME: placeholder + WJR_SMTP_PASSWORD: placeholder + WJR_DATA_FOLDER: /tmp/whyjustrun-data/ + WJR_DATA_URL: placeholder + + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7 + + - name: Build image + run: docker build . --pull --file Dockerfile --tag $IMAGE_NAME + + - name: Check that the app boots in production + # The test jobs run on the runner's Ruby without precompiled assets; this runs + # the image that gets deployed (its Ruby, its gems, its asset manifest). + run: | + env_args=() + for name in RAILS_ENV SECRET_KEY_BASE ${!WJR_*}; do env_args+=(-e "$name"); done + docker run --rm --entrypoint "" "${env_args[@]}" $IMAGE_NAME \ + bundle exec rails runner 'puts "Booted Rails #{Rails.version} on Ruby #{RUBY_VERSION}"' + - name: Log into GitHub Container Registry run: echo "${{ secrets.CR_PAT }}" | docker login https://ghcr.io -u ${{ secrets.CR_USER }} --password-stdin diff --git a/.github/workflows/dependabot-auto-merge.yml b/.github/workflows/dependabot-auto-merge.yml index 7a88b53..0f67de7 100644 --- a/.github/workflows/dependabot-auto-merge.yml +++ b/.github/workflows/dependabot-auto-merge.yml @@ -18,7 +18,14 @@ jobs: github.event.pull_request.user.login == 'dependabot[bot]' runs-on: ubuntu-latest steps: + - name: Fetch update metadata + id: metadata + uses: dependabot/fetch-metadata@25dd0e34f4fe68f24cc83900b1fe3fe149efef98 # v3.1.0 + + # Major updates can break the app in ways the tests miss (json 3 did), so they + # wait for a human review. - name: Enable auto-merge + if: steps.metadata.outputs.update-type != 'version-update:semver-major' run: gh pr merge --auto --squash "$PR_URL" env: PR_URL: ${{ github.event.pull_request.html_url }} @@ -50,6 +57,12 @@ jobs: exit 0 fi + # Major updates wait for a human review (see enable-auto-merge). + if gh api "repos/$REPO/commits/$HEAD_SHA" --jq '.commit.message' | grep -q 'update-type: version-update:semver-major'; then + echo "PR #$pr is a major update; leaving it for review" + exit 0 + fi + state=$(gh pr view "$pr" --repo "$REPO" --json state --jq '.state') if [ "$state" != "OPEN" ]; then echo "PR #$pr is $state; skipping" diff --git a/.ruby-version b/.ruby-version index a0891f5..6c165c2 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -3.3.4 +3.3.13 diff --git a/Dockerfile b/Dockerfile index 8d0687b..cb85317 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,13 @@ -FROM ruby:4.0.0-alpine AS dev +FROM ruby:3.3.13-alpine AS dev +# linux-headers and libffi-dev are for compiling the ffi gem; older Alpine releases +# pulled them in as dependencies of the other packages. RUN apk add --no-cache \ make \ pkgconfig \ build-base \ autoconf \ + linux-headers \ + libffi-dev \ libstdc++ \ mariadb-dev \ imagemagick \ diff --git a/Gemfile b/Gemfile index 31cdb11..cdd1864 100644 --- a/Gemfile +++ b/Gemfile @@ -46,7 +46,8 @@ gem "geocoder", "~> 1.8.6" # JSON Builder gem 'jbuilder', '~> 2.15.1' -# json 3 removed keywords still used by Rails 7.x and ExecJS 2.9. +# json 3 removed the create_additions keyword, which sprockets 4.2 still passed (4.4 doesn't). +# Before taking json 4, check that the production image boots (CI's image job). gem 'json', '< 4' # Logging (email) diff --git a/Gemfile.lock b/Gemfile.lock index c04927c..50d7b4e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -210,7 +210,7 @@ GEM prism (2.1.0) prism (2.1.0-x86_64-linux-gnu) public_suffix (7.0.5) - puma (8.1.1) + puma (8.1.2) nio4r (~> 2.0) pundit (2.5.2) activesupport (>= 3.0.0) @@ -287,8 +287,9 @@ GEM logger (~> 1.4) rubyzip (>= 1.2.2, < 4.0) websocket (~> 1.0) - sprockets (4.2.1) - concurrent-ruby (~> 1.0) + sprockets (4.4.1) + concurrent-ruby (~> 1.1) + logger rack (>= 2.2.4, < 4) sprockets-rails (3.5.2) actionpack (>= 6.1)