Skip to content

Commit e4e90d7

Browse files
authored
Merge pull request #3 from hackclub/backend
Backend + railsify
2 parents 8b5caca + 346c5d0 commit e4e90d7

File tree

131 files changed

+4629
-1808
lines changed

Some content is hidden

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

131 files changed

+4629
-1808
lines changed

.dockerignore

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# See https://docs.docker.com/engine/reference/builder/#dockerignore-file for more about ignoring files.
2+
3+
# Ignore git directory.
4+
/.git/
5+
/.gitignore
6+
7+
# Ignore bundler config.
8+
/.bundle
9+
10+
# Ignore all environment files.
11+
/.env*
12+
13+
# Ignore all default key files.
14+
/config/master.key
15+
/config/credentials/*.key
16+
17+
# Ignore all logfiles and tempfiles.
18+
/log/*
19+
/tmp/*
20+
!/log/.keep
21+
!/tmp/.keep
22+
23+
# Ignore pidfiles, but keep the directory.
24+
/tmp/pids/*
25+
!/tmp/pids/.keep
26+
27+
# Ignore storage (uploaded files in development and any SQLite databases).
28+
/storage/*
29+
!/storage/.keep
30+
/tmp/storage/*
31+
!/tmp/storage/.keep
32+
33+
# Ignore CI service files.
34+
/.github
35+
36+
# Ignore Kamal files.
37+
/config/deploy*.yml
38+
/.kamal
39+
40+
# Ignore development files
41+
/.devcontainer
42+
43+
# Ignore Docker-related files
44+
/.dockerignore
45+
/Dockerfile*

.gitattributes

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# See https://git-scm.com/docs/gitattributes for more about git attribute files.
2+
3+
# Mark the database schema as having been generated.
4+
db/schema.rb linguist-generated
5+
6+
# Mark any vendored files as having been vendored.
7+
vendor/* linguist-vendored
8+
config/credentials/*.yml.enc diff=rails_credentials
9+
config/credentials.yml.enc diff=rails_credentials

.github/dependabot.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: bundler
4+
directory: "/"
5+
schedule:
6+
interval: daily
7+
open-pull-requests-limit: 10
8+
- package-ecosystem: github-actions
9+
directory: "/"
10+
schedule:
11+
interval: daily
12+
open-pull-requests-limit: 10

.github/workflows/ci.yml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: CI
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches: [ main ]
7+
8+
jobs:
9+
scan_ruby:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v4
15+
16+
- name: Set up Ruby
17+
uses: ruby/setup-ruby@v1
18+
with:
19+
ruby-version: .ruby-version
20+
bundler-cache: true
21+
22+
- name: Scan for common Rails security vulnerabilities using static analysis
23+
run: bin/brakeman --no-pager
24+
25+
lint:
26+
runs-on: ubuntu-latest
27+
steps:
28+
- name: Checkout code
29+
uses: actions/checkout@v4
30+
31+
- name: Set up Ruby
32+
uses: ruby/setup-ruby@v1
33+
with:
34+
ruby-version: .ruby-version
35+
bundler-cache: true
36+
37+
- name: Lint code for consistent style
38+
run: bin/rubocop -f github
39+
40+
test:
41+
runs-on: ubuntu-latest
42+
43+
# services:
44+
# redis:
45+
# image: redis
46+
# ports:
47+
# - 6379:6379
48+
# options: --health-cmd "redis-cli ping" --health-interval 10s --health-timeout 5s --health-retries 5
49+
steps:
50+
- name: Install packages
51+
run: sudo apt-get update && sudo apt-get install --no-install-recommends -y build-essential git libyaml-dev pkg-config
52+
53+
- name: Checkout code
54+
uses: actions/checkout@v4
55+
56+
- name: Set up Ruby
57+
uses: ruby/setup-ruby@v1
58+
with:
59+
ruby-version: .ruby-version
60+
bundler-cache: true
61+
62+
- name: Run tests
63+
env:
64+
RAILS_ENV: test
65+
# REDIS_URL: redis://localhost:6379/0
66+
run: bin/rails db:test:prepare test

.gitignore

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,35 @@ dist-ssr
7676
*.njsproj
7777
*.sln
7878
*.sw?
79+
# See https://help.github.com/articles/ignoring-files for more about ignoring files.
80+
#
81+
# Temporary files generated by your text editor or operating system
82+
# belong in git's global ignore instead:
83+
# `$XDG_CONFIG_HOME/git/ignore` or `~/.config/git/ignore`
84+
85+
# Ignore bundler config.
86+
/.bundle
87+
88+
# Ignore all environment files.
89+
/.env*
90+
91+
# Ignore all logfiles and tempfiles.
92+
/log/*
93+
/tmp/*
94+
!/log/.keep
95+
!/tmp/.keep
96+
97+
# Ignore pidfiles, but keep the directory.
98+
/tmp/pids/*
99+
!/tmp/pids/
100+
!/tmp/pids/.keep
101+
102+
# Ignore storage (uploaded files in development and any SQLite databases).
103+
/storage/*
104+
!/storage/.keep
105+
/tmp/storage/*
106+
!/tmp/storage/
107+
!/tmp/storage/.keep
108+
109+
# Ignore master key for decrypting credentials and more.
110+
/config/master.key

.rubocop.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Omakase Ruby styling for Rails
2+
inherit_gem: { rubocop-rails-omakase: rubocop.yml }
3+
4+
# Overwrite or add rules to create your own house style
5+
#
6+
# # Use `[a, [b, c]]` not `[ a, [ b, c ] ]`
7+
# Layout/SpaceInsideArrayLiteralBrackets:
8+
# Enabled: false

.ruby-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ruby-3.4.3

Dockerfile

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# syntax=docker/dockerfile:1
2+
# check=error=true
3+
4+
# This Dockerfile is designed for production, not development. Use with Kamal or build'n'run by hand:
5+
# docker build -t backend .
6+
# docker run -d -p 80:80 -e RAILS_MASTER_KEY=<value from config/master.key> --name backend backend
7+
8+
# For a containerized dev environment, see Dev Containers: https://guides.rubyonrails.org/getting_started_with_devcontainer.html
9+
10+
# Make sure RUBY_VERSION matches the Ruby version in .ruby-version
11+
ARG RUBY_VERSION=3.4.3
12+
FROM docker.io/library/ruby:$RUBY_VERSION-slim AS base
13+
14+
# Rails app lives here
15+
WORKDIR /rails
16+
17+
# Install base packages
18+
RUN apt-get update -qq && \
19+
apt-get install --no-install-recommends -y curl libjemalloc2 libvips sqlite3 && \
20+
rm -rf /var/lib/apt/lists /var/cache/apt/archives
21+
22+
# Set production environment
23+
ENV RAILS_ENV="production" \
24+
BUNDLE_DEPLOYMENT="1" \
25+
BUNDLE_PATH="/usr/local/bundle" \
26+
BUNDLE_WITHOUT="development"
27+
28+
# Throw-away build stage to reduce size of final image
29+
FROM base AS build
30+
31+
# Install packages needed to build gems
32+
RUN apt-get update -qq && \
33+
apt-get install --no-install-recommends -y build-essential git libyaml-dev pkg-config && \
34+
rm -rf /var/lib/apt/lists /var/cache/apt/archives
35+
36+
# Install application gems
37+
COPY Gemfile Gemfile.lock ./
38+
RUN bundle install && \
39+
rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git && \
40+
bundle exec bootsnap precompile --gemfile
41+
42+
# Copy application code
43+
COPY . .
44+
45+
# Precompile bootsnap code for faster boot times
46+
RUN bundle exec bootsnap precompile app/ lib/
47+
48+
49+
50+
51+
# Final stage for app image
52+
FROM base
53+
54+
# Copy built artifacts: gems, application
55+
COPY --from=build "${BUNDLE_PATH}" "${BUNDLE_PATH}"
56+
COPY --from=build /rails /rails
57+
58+
# Run and own only the runtime files as a non-root user for security
59+
RUN groupadd --system --gid 1000 rails && \
60+
useradd rails --uid 1000 --gid 1000 --create-home --shell /bin/bash && \
61+
chown -R rails:rails db log storage tmp
62+
USER 1000:1000
63+
64+
# Entrypoint prepares the database.
65+
ENTRYPOINT ["/rails/bin/docker-entrypoint"]
66+
67+
# Start server via Thruster by default, this can be overwritten at runtime
68+
EXPOSE 80
69+
CMD ["./bin/thrust", "./bin/rails", "server"]

Gemfile

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
source "https://rubygems.org"
2+
3+
# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"
4+
gem "rails", "~> 8.0.4"
5+
# Use PostgreSQL as the database for Active Record
6+
gem "pg", "~> 1.5"
7+
# Use the Puma web server [https://github.com/puma/puma]
8+
gem "puma", ">= 5.0"
9+
# Build JSON APIs with ease [https://github.com/rails/jbuilder]
10+
# gem "jbuilder"
11+
12+
# Use Active Model has_secure_password [https://guides.rubyonrails.org/active_model_basics.html#securepassword]
13+
# gem "bcrypt", "~> 3.1.7"
14+
15+
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
16+
gem "tzinfo-data", platforms: %i[ windows jruby ]
17+
18+
# Use the database-backed adapters for Rails.cache, Active Job, and Action Cable
19+
gem "solid_cache"
20+
gem "solid_queue"
21+
gem "solid_cable"
22+
23+
# Reduces boot times through caching; required in config/boot.rb
24+
gem "bootsnap", require: false
25+
26+
# Deploy this application anywhere as a Docker container [https://kamal-deploy.org]
27+
gem "kamal", require: false
28+
29+
# Add HTTP asset caching/compression and X-Sendfile acceleration to Puma [https://github.com/basecamp/thruster/]
30+
gem "thruster", require: false
31+
32+
# Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images]
33+
# gem "image_processing", "~> 1.2"
34+
35+
# Use Rack CORS for handling Cross-Origin Resource Sharing (CORS), making cross-origin Ajax possible
36+
gem "rack-cors"
37+
38+
# Rate limiting
39+
gem "rack-attack"
40+
41+
group :development, :test do
42+
# Load .env files
43+
gem "dotenv-rails"
44+
45+
# See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
46+
gem "debug", platforms: %i[ mri windows ], require: "debug/prelude"
47+
48+
# Static analysis for security vulnerabilities [https://brakemanscanner.org/]
49+
gem "brakeman", require: false
50+
51+
# Omakase Ruby styling [https://github.com/rails/rubocop-rails-omakase/]
52+
gem "rubocop-rails-omakase", require: false
53+
end
54+
55+
gem "norairrecord", "~> 0.5.1"
56+
gem "faraday", "~> 1.10" # norairrecord requires Faraday 1.x API
57+
58+
# Authentication
59+
gem "jwt"
60+
61+
gem "omniauth", "~> 2.1"
62+
gem "omniauth-hack_club"

0 commit comments

Comments
 (0)