Skip to content

Commit 7711504

Browse files
authored
Merge pull request #904 from rdmurphy/main
Bring Klaxon back up to speed
2 parents 81a6bc6 + e49dc89 commit 7711504

169 files changed

Lines changed: 4880 additions & 2636 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.dockerignore

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22

33
# Ignore git directory.
44
/.git/
5+
/.gitignore
56

67
# Ignore bundler config.
78
/.bundle
89

10+
# Ignore all environment files.
11+
/.env*
12+
913
# Ignore all default key files.
1014
/config/master.key
1115
/config/credentials/*.key
1216

13-
# Ignore all environment files.
14-
/.env*
15-
!/.env.example
16-
1717
# Ignore all logfiles and tempfiles.
1818
/log/*
1919
/tmp/*
@@ -22,18 +22,30 @@
2222

2323
# Ignore pidfiles, but keep the directory.
2424
/tmp/pids/*
25-
!/tmp/pids/
2625
!/tmp/pids/.keep
2726

2827
# Ignore storage (uploaded files in development and any SQLite databases).
2928
/storage/*
3029
!/storage/.keep
3130
/tmp/storage/*
32-
!/tmp/storage/
3331
!/tmp/storage/.keep
3432

3533
# Ignore assets.
3634
/node_modules/
3735
/app/assets/builds/*
3836
!/app/assets/builds/.keep
3937
/public/assets
38+
39+
# Ignore CI service files.
40+
/.github
41+
42+
# Ignore Kamal files.
43+
/config/deploy*.yml
44+
/.kamal
45+
46+
# Ignore development files
47+
/.devcontainer
48+
49+
# Ignore Docker-related files
50+
/.dockerignore
51+
/Dockerfile*

.github/workflows/ci.yml

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616

1717
services:
1818
postgres:
19-
image: postgres:9.5
19+
image: postgres:16
2020
env:
2121
POSTGRES_DB: klaxon_test
2222
POSTGRES_USER: klaxon-test-user
@@ -26,7 +26,7 @@ jobs:
2626

2727
steps:
2828
- name: Checkout the project
29-
uses: actions/checkout@v3
29+
uses: actions/checkout@v5
3030

3131
- name: Set up Ruby
3232
uses: ruby/setup-ruby@v1
@@ -41,3 +41,36 @@ jobs:
4141

4242
- name: Run the tests
4343
run: bundle exec rspec --tag ~skip --tag ~pending --format RSpec::Github::Formatter
44+
45+
push-docker:
46+
needs: test
47+
if: github.ref == 'refs/heads/main'
48+
runs-on: ubuntu-latest
49+
permissions:
50+
contents: read
51+
packages: write
52+
53+
steps:
54+
- name: Checkout the project
55+
uses: actions/checkout@v6
56+
57+
- name: Log in to GitHub Container Registry
58+
uses: docker/login-action@v3
59+
with:
60+
registry: ghcr.io
61+
username: ${{ github.actor }}
62+
password: ${{ secrets.GITHUB_TOKEN }}
63+
64+
- name: Extract Docker metadata
65+
id: meta
66+
uses: docker/metadata-action@v5
67+
with:
68+
images: ghcr.io/${{ github.repository }}
69+
70+
- name: Build and push Docker image
71+
uses: docker/build-push-action@v6
72+
with:
73+
context: .
74+
push: true
75+
tags: ${{ steps.meta.outputs.tags }}
76+
labels: ${{ steps.meta.outputs.labels }}

.gitignore

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,45 @@
1-
.env
2-
.DS_Store
1+
# See https://help.github.com/articles/ignoring-files for more about ignoring files.
2+
#
3+
# Temporary files generated by your text editor or operating system
4+
# belong in git's global ignore instead:
5+
# `$XDG_CONFIG_HOME/git/ignore` or `~/.config/git/ignore`
36

7+
# Ignore bundler config.
48
/.bundle
5-
backups/
69

10+
# Ignore all environment files.
11+
/.env*
12+
13+
# Ignore all logfiles and tempfiles.
714
/log/*
15+
/tmp/*
816
!/log/.keep
9-
/tmp
10-
pull_dev_database.sh
17+
!/tmp/.keep
18+
19+
# Ignore pidfiles, but keep the directory.
20+
/tmp/pids/*
21+
!/tmp/pids/
22+
!/tmp/pids/.keep
23+
24+
# Ignore storage (uploaded files in development and any SQLite databases).
25+
/storage/*
26+
!/storage/.keep
27+
/tmp/storage/*
28+
!/tmp/storage/
29+
!/tmp/storage/.keep
1130

12-
snapshots
31+
# Ignore public assets (compiled assets in development and production).
32+
/public/assets
1333

34+
# Ignore key files for decrypting credentials and more.
35+
/config/*.key
36+
37+
# Ignore build assets from dartsass-rails.
1438
/app/assets/builds/*
1539
!/app/assets/builds/.keep
40+
41+
# Ignore Node dependencies
42+
/node_modules
43+
44+
# Ignore build assets from esbuild.
45+
/public/bookmarklet.js

.node-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
18.17.0
1+
24.14.0

.rubocop.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Omakase Ruby styling for Rails
2+
inherit_gem:
3+
rubocop-rails-omakase: rubocop.yml
4+
5+
plugins:
6+
- rubocop-rspec
7+
- rubocop-rspec_rails
8+
9+
AllCops:
10+
NewCops: enable
11+
12+
# Cops that are too strict for this codebase's existing specs
13+
RSpec/MultipleExpectations:
14+
Enabled: false
15+
16+
RSpec/ExampleLength:
17+
Enabled: false
18+
19+
RSpec/InstanceVariable:
20+
Enabled: false
21+
22+
RSpec/DescribeClass:
23+
Exclude:
24+
- spec/integration/**/*
25+
26+
RSpec/BeforeAfterAll:
27+
Exclude:
28+
- spec/models/app_json_spec.rb
29+
- spec/models/page_spec.rb
30+
- spec/models/safe_string_spec.rb

.ruby-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.1.4
1+
3.4.8

Dockerfile

Lines changed: 41 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,82 @@
1-
# syntax = docker/dockerfile:1
1+
# syntax=docker/dockerfile:1
2+
# check=error=true
23

3-
# Make sure RUBY_VERSION matches the Ruby version in .ruby-version and Gemfile
4-
ARG RUBY_VERSION=3.1.4
5-
FROM ruby:$RUBY_VERSION-slim as base
4+
# Make sure RUBY_VERSION matches the Ruby version in .ruby-version
5+
ARG RUBY_VERSION=3.4.8
6+
FROM ruby:$RUBY_VERSION-slim AS base
67

78
# Rails app lives here
89
WORKDIR /rails
910

10-
# Set production environment
11-
ENV RAILS_ENV="production" \
12-
BUNDLE_WITHOUT="development:test" \
13-
BUNDLE_DEPLOYMENT="1"
14-
1511
# Update gems and bundler
1612
RUN gem update --system --no-document && \
1713
gem install -N bundler
1814

19-
# Install packages needed to install nodejs
15+
# Install base packages
2016
RUN apt-get update -qq && \
21-
apt-get install --no-install-recommends -y curl && \
17+
apt-get install --no-install-recommends -y curl libjemalloc2 postgresql-client && \
2218
rm -rf /var/lib/apt/lists /var/cache/apt/archives
2319

24-
# Install Node.js
25-
ARG NODE_VERSION=18.17.0
26-
ENV PATH=/usr/local/node/bin:$PATH
27-
RUN curl -sL https://github.com/nodenv/node-build/archive/master.tar.gz | tar xz -C /tmp/ && \
28-
/tmp/node-build-master/bin/node-build "${NODE_VERSION}" /usr/local/node && \
29-
rm -rf /tmp/node-build-master
20+
# Set production environment
21+
ENV BUNDLE_DEPLOYMENT="1" \
22+
BUNDLE_PATH="/usr/local/bundle" \
23+
BUNDLE_WITHOUT="development:test" \
24+
RAILS_ENV="production"
3025

3126

3227
# Throw-away build stage to reduce size of final image
33-
FROM base as build
28+
FROM base AS build
3429

35-
# Install packages needed to build gems
30+
# Install packages needed to build gems and node modules
3631
RUN apt-get update -qq && \
37-
apt-get install --no-install-recommends -y build-essential libpq-dev
32+
apt-get install --no-install-recommends -y build-essential libpq-dev libyaml-dev node-gyp pkg-config python-is-python3 && \
33+
rm -rf /var/lib/apt/lists /var/cache/apt/archives
3834

39-
# Build options
40-
ENV PATH="/usr/local/node/bin:$PATH"
35+
# Install Node.js
36+
ARG NODE_VERSION=24.14.0
37+
ENV PATH=/usr/local/node/bin:$PATH
38+
RUN curl -sL https://github.com/nodenv/node-build/archive/master.tar.gz | tar xz -C /tmp/ && \
39+
/tmp/node-build-master/bin/node-build "${NODE_VERSION}" /usr/local/node && \
40+
rm -rf /tmp/node-build-master
4141

4242
# Install application gems
43-
COPY --link Gemfile Gemfile.lock ./
43+
COPY Gemfile Gemfile.lock ./
4444
RUN bundle install && \
45-
bundle exec bootsnap precompile --gemfile && \
46-
rm -rf ~/.bundle/ $BUNDLE_PATH/ruby/*/cache $BUNDLE_PATH/ruby/*/bundler/gems/*/.git
45+
rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git && \
46+
bundle exec bootsnap precompile --gemfile
47+
48+
# Install node modules
49+
COPY package.json package-lock.json ./
50+
RUN npm install
51+
52+
# Build the bookmarklet
53+
COPY config/esbuild.js config/
54+
COPY app/javascript/bookmarklet/ app/javascript/bookmarklet/
55+
RUN npm run build:bookmarklet
4756

4857
# Copy application code
49-
COPY --link . .
58+
COPY . .
5059

5160
# Precompile bootsnap code for faster boot times
5261
RUN bundle exec bootsnap precompile app/ lib/
5362

5463
# Precompiling assets for production without requiring secret RAILS_MASTER_KEY
55-
RUN SECRET_KEY_BASE=DUMMY ./bin/rails assets:precompile
64+
RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile
5665

5766

5867
# Final stage for app image
5968
FROM base
6069

61-
# Install packages needed for deployment
62-
RUN apt-get update -qq && \
63-
apt-get install --no-install-recommends -y curl postgresql-client && \
64-
rm -rf /var/lib/apt/lists /var/cache/apt/archives
6570

6671
# Copy built artifacts: gems, application
67-
COPY --from=build /usr/local/bundle /usr/local/bundle
72+
COPY --from=build "${BUNDLE_PATH}" "${BUNDLE_PATH}"
6873
COPY --from=build /rails /rails
6974

7075
# Run and own only the runtime files as a non-root user for security
71-
RUN useradd rails --create-home --shell /bin/bash && \
72-
chown -R rails:rails db log tmp
73-
USER rails:rails
74-
75-
# Deployment options
76-
ENV RAILS_LOG_TO_STDOUT="1" \
77-
RAILS_SERVE_STATIC_FILES="true"
76+
RUN groupadd --system --gid 1000 rails && \
77+
useradd rails --uid 1000 --gid 1000 --create-home --shell /bin/bash && \
78+
chown -R 1000:1000 db log tmp
79+
USER 1000:1000
7880

7981
# Entrypoint prepares the database.
8082
ENTRYPOINT ["/rails/bin/docker-entrypoint"]

0 commit comments

Comments
 (0)