Skip to content

Commit 2c8c47f

Browse files
authored
Customize rails application (#2)
1 parent 0c04e00 commit 2c8c47f

File tree

143 files changed

+6459
-156
lines changed

Some content is hidden

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

143 files changed

+6459
-156
lines changed

.github/ISSUE_TEMPLATE/bug.yaml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Bug report
2+
description: File a bug report
3+
labels: ["bug", "triage"]
4+
projects: ["navapbc/4"]
5+
body:
6+
- type: markdown
7+
attributes:
8+
value: |
9+
Thanks for taking the time to fill out this bug report!
10+
- type: textarea
11+
attributes:
12+
label: What happened?
13+
description: Also tell us, what did you expect to happen?
14+
placeholder: Tell us what you see!
15+
validations:
16+
required: true
17+
- type: textarea
18+
attributes:
19+
label: Steps to reproduce
20+
description: Share the steps or a link to a repository we can use to reproduce the problem.
21+
- type: dropdown
22+
id: browsers
23+
attributes:
24+
label: What browsers are you seeing the problem on?
25+
multiple: true
26+
options:
27+
- Not applicable
28+
- Firefox
29+
- Chrome
30+
- Safari
31+
- Microsoft Edge
32+
- type: textarea
33+
id: logs
34+
attributes:
35+
label: Relevant log output
36+
description: Please copy and paste any relevant log output. This will be automatically formatted into code, so no need for backticks.
37+
render: shell
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Feature request
2+
description: Suggest an idea for this project
3+
labels: ["triage", "feature"]
4+
projects: ["navapbc/4"]
5+
body:
6+
- type: textarea
7+
attributes:
8+
label: Describe the problem and the solution you'd like
9+
description: A clear and concise description of what the problem is and what you want to happen.
10+
value: |
11+
**Is your feature request related to a problem? Please describe.**
12+
<!-- A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] -->
13+
14+
**Describe the solution you'd like**
15+
<!-- A clear and concise description of what you want to happen. -->
16+
17+
**Describe alternatives you've considered**
18+
<!-- A clear and concise description of any alternative solutions or features you've considered. -->
19+
- type: textarea
20+
attributes:
21+
label: Additional context
22+
description: Add any other context or screenshots about the feature request here.
23+
- type: dropdown
24+
attributes:
25+
label: Priority
26+
description: How impactful would this be for your project?
27+
multiple: false
28+
options:
29+
- "My project needs this now"
30+
- "I anticipate needing this soon"
31+
- "Nice to have"
32+
- "Just want to discuss"

.github/ISSUE_TEMPLATE/task.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name: Task
2+
description: Create a task for the team
3+
projects: ["navapbc/4"]
4+
body:
5+
- type: textarea
6+
attributes:
7+
label: What's the task?
8+
validations:
9+
required: true

.github/workflows/ci-app-rails.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: CI app-rails
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- app-rails/**
9+
- .github/workflows/ci-app-rails.yml
10+
pull_request:
11+
paths:
12+
- app-rails/**
13+
- .github/workflows/ci-app-rails.yml
14+
15+
defaults:
16+
run:
17+
working-directory: ./app-rails
18+
19+
jobs:
20+
# As an enhancement, it is possible to share the built docker image and share
21+
# it across jobs as described in:
22+
# https://docs.github.com/en/actions/using-workflows/storing-workflow-data-as-artifacts#passing-data-between-jobs-in-a-workflow
23+
lint:
24+
name: Lint
25+
runs-on: ubuntu-latest
26+
steps:
27+
- uses: actions/checkout@v3
28+
# https://github.com/docker/compose/issues/1973
29+
- name: Create required env files
30+
working-directory: ./
31+
run: |
32+
touch ./app-rails/.env
33+
34+
- run: make lint
35+
36+
test:
37+
name: Test
38+
runs-on: ubuntu-latest
39+
steps:
40+
- uses: actions/checkout@v3
41+
42+
- run: make init-container
43+
- run: make precompile-assets
44+
45+
- name: Start tests
46+
run: make test

README.md

Lines changed: 72 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,72 @@
1-
# template-application-rails
2-
Ruby on Rails with USWDS template, including CI/CD, for teams building web applications
1+
# Template Ruby on Rails application
2+
3+
This is a template repository for a Ruby on Rails application.
4+
5+
See [`navapbc/platform`](https://github.com/navapbc/platform) for other template repos.
6+
7+
## Features
8+
9+
- [U.S. Web Design System](https://designsystem.digital.gov/) for themeable styling and a set of common components
10+
- Integration with AWS services, including:
11+
- Database integration with AWS RDS Postgresql using UUIDs
12+
- Active Storage configuration with AWS S3
13+
- Action Mailer configuration with AWS SES
14+
- Authentication with [devise](https://github.com/heartcombo/devise) and AWS Cognito
15+
- Internationalization (i18n)
16+
- Authorization using [pundit](https://github.com/varvet/pundit)
17+
- Linting and code formatting using [rubocop](https://rubocop.org/)
18+
- Testing using [rspec](https://rspec.info)
19+
20+
<img width="1023" alt="CleanShot 2024-05-22 at 16 35 53@2x" src="https://github.com/navapbc/template-application-rails/assets/67701/fb291a98-7dfa-429e-91e2-30beacf58b9e">
21+
22+
## Repo structure
23+
24+
```text
25+
├── .github # GitHub workflows and repo templates
26+
├── docs # Project docs and decision records
27+
├── app-rails # Web application
28+
├── template-only-bin # Scripts for managing this template; not copied into your project
29+
├── template-only-docs # Documentation for this template; not copied into your project
30+
```
31+
32+
## Installation
33+
34+
To get started using the template application on your project:
35+
36+
1. Run the [download and install script](./template-only-bin/download-and-install-template.sh) in your project's root directory.
37+
38+
```bash
39+
curl https://raw.githubusercontent.com/navapbc/template-application-rails/main/template-only-bin/download-and-install-template.sh | bash -s
40+
```
41+
42+
This script will:
43+
44+
1. Clone the template repository
45+
2. Copy the template files into your project directory
46+
3. Remove any files specific to the template repository, like this README.
47+
48+
You can optionally pass in a branch, commit hash, or release that you want to install. For example:
49+
50+
```bash
51+
curl https://raw.githubusercontent.com/navapbc/template-application-rails/main/template-only-bin/download-and-install-template.sh | bash -s -- <commit_hash>
52+
```
53+
2. [Follow the steps in `app-rails/README.md`](./app-rails/README.md) to set up the application locally.
54+
3. Optional, if using the Platform infrastructure template: [Follow the steps in the `template-infra` README](https://github.com/navapbc/template-infra#installation) to set up the various pieces of your infrastructure.
55+
56+
## Updates
57+
58+
If you have previously installed this template and would like to update your project to use a newer version of this application:
59+
60+
1. Run the [download and install script](./template-only-bin/download-and-install-template.sh) in your project's root directory and pass in the branch, commit hash, or release that you want to update to, followed by the name of your application directory (e.g. `app-rails`).
61+
62+
```bash
63+
curl https://raw.githubusercontent.com/navapbc/template-application-rails/main/template-only-bin/download-and-install-template.sh | bash -s -- <commit_hash> <app_name>
64+
```
65+
66+
This script will:
67+
68+
1. Clone the template repository
69+
2. Copy the template files into your project directory
70+
3. Remove any files specific to the template repository, like this README.
71+
72+
⚠️ Warning! This will modify existing files. Review all changes carefully after executing the script by running `git diff`.

app-rails/.gitignore

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,13 @@
77
# Ignore bundler config.
88
/.bundle
99

10+
# Ignore installed gems.
11+
/vendor/bundle/*
12+
!/vendor/bundle/.keep
13+
1014
# Ignore all environment files (except templates).
1115
/.env*
16+
/*.env*
1217
!/.env*.erb
1318

1419
# Ignore all logfiles and tempfiles.
@@ -33,6 +38,16 @@
3338

3439
# Ignore master key for decrypting credentials and more.
3540
/config/master.key
41+
/config/credentials/*
42+
43+
# Ignore development log.
44+
/log/development.log
3645

3746
/app/assets/builds/*
3847
!/app/assets/builds/.keep
48+
49+
/node_modules/*
50+
!/node_modules/.keep
51+
52+
# Testing
53+
coverage/*

app-rails/.rspec

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

app-rails/.rubocop.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
require:
2+
- rubocop-rspec
3+
inherit_gem:
4+
pundit: config/rubocop-rspec.yml
5+
rubocop-rails-omakase: rubocop.yml
6+
AllCops:
7+
Exclude:
8+
- lib/templates/**/*

app-rails/Dockerfile

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

33
# Make sure RUBY_VERSION matches the Ruby version in .ruby-version and Gemfile
44
ARG RUBY_VERSION=3.3.0
5+
6+
7+
##########################################################################################
8+
# BASE: Shared base docker image
9+
##########################################################################################
510
FROM registry.docker.com/library/ruby:$RUBY_VERSION-slim as base
611

712
# Rails app lives here
@@ -10,53 +15,102 @@ WORKDIR /rails
1015
# Set production environment
1116
ENV RAILS_ENV="production" \
1217
BUNDLE_DEPLOYMENT="1" \
13-
BUNDLE_PATH="/usr/local/bundle" \
14-
BUNDLE_WITHOUT="development"
18+
BUNDLE_PATH="/usr/local/bundle"
19+
20+
# Start the server by default, this can be overwritten at runtime
21+
EXPOSE 3000
1522

1623

17-
# Throw-away build stage to reduce size of final image
24+
##########################################################################################
25+
# BUILD: Throw-away build stage
26+
##########################################################################################
1827
FROM base as build
1928

2029
# Install packages needed to build gems
2130
RUN apt-get update -qq && \
22-
apt-get install --no-install-recommends -y build-essential git libpq-dev libvips pkg-config
31+
apt-get install --no-install-recommends -y build-essential git libpq-dev libvips pkg-config npm
32+
33+
# Install npm packages
34+
COPY package.json package-lock.json ./
35+
36+
# Install npm packages
37+
RUN npm install
38+
39+
40+
##########################################################################################
41+
# DEV: Used for development and test
42+
##########################################################################################
43+
FROM build as dev
44+
45+
ENV RAILS_ENV="development"
46+
47+
# Install packages needed for development
48+
RUN apt-get update -qq && \
49+
apt-get install --no-install-recommends -y postgresql-client graphviz && \
50+
rm -rf /var/lib/apt/lists /var/cache/apt/archives
51+
52+
# Install application gems for development
53+
COPY Gemfile Gemfile.lock ./
54+
RUN bundle config set --local without production && \
55+
bundle install && \
56+
rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git
2357

24-
# Install application gems
58+
# Copy application code
59+
COPY . .
60+
61+
CMD ["./bin/dev"]
62+
63+
64+
##########################################################################################
65+
# RELEASE-BUILD: Throw-away build stage for RELEASE
66+
##########################################################################################
67+
FROM build as release-build
68+
69+
# Install application gems for production
2570
COPY Gemfile Gemfile.lock ./
26-
RUN bundle install && \
27-
rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git && \
28-
bundle exec bootsnap precompile --gemfile
71+
RUN bundle config set --local without development test && \
72+
bundle install && \
73+
rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git
2974

3075
# Copy application code
3176
COPY . .
3277

3378
# Precompile bootsnap code for faster boot times
34-
RUN bundle exec bootsnap precompile app/ lib/
79+
RUN bundle exec bootsnap precompile --gemfile app/ lib/
3580

3681
# Precompiling assets for production without requiring secret RAILS_MASTER_KEY
3782
RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile
3883

3984

40-
# Final stage for app image
41-
FROM base
85+
##########################################################################################
86+
# RELEASE: Used for production
87+
##########################################################################################
88+
FROM base as release
89+
90+
# Set production environment
91+
ENV RAILS_ENV="production" \
92+
BUNDLE_DEPLOYMENT="1" \
93+
BUNDLE_PATH="/usr/local/bundle"
4294

4395
# Install packages needed for deployment
4496
RUN apt-get update -qq && \
45-
apt-get install --no-install-recommends -y curl libvips postgresql-client && \
46-
rm -rf /var/lib/apt/lists /var/cache/apt/archives
97+
apt-get install -y --no-install-recommends unzip python3-venv python-is-python3 curl libvips postgresql-client && \
98+
rm -rf /var/lib/apt/lists /var/cache/apt/archives && \
99+
curl "https://s3.amazonaws.com/aws-cli/awscli-bundle.zip" -o "awscli-bundle.zip" && \
100+
unzip awscli-bundle.zip && \
101+
./awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws && \
102+
rm -rf ./awscli-bundle awscli-bundle.zip
103+
104+
# Install custom db migrate script
105+
COPY bin/db-migrate /usr/bin/
47106

48107
# Copy built artifacts: gems, application
49-
COPY --from=build /usr/local/bundle /usr/local/bundle
50-
COPY --from=build /rails /rails
108+
COPY --from=release-build /usr/local/bundle /usr/local/bundle
109+
COPY --from=release-build /rails /rails
51110

52111
# Run and own only the runtime files as a non-root user for security
53112
RUN useradd rails --create-home --shell /bin/bash && \
54113
chown -R rails:rails db log storage tmp
55114
USER rails:rails
56115

57-
# Entrypoint prepares the database.
58-
ENTRYPOINT ["/rails/bin/docker-entrypoint"]
59-
60-
# Start the server by default, this can be overwritten at runtime
61-
EXPOSE 3000
62116
CMD ["./bin/rails", "server"]

0 commit comments

Comments
 (0)