Skip to content

Customize rails application #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 78 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
c2854fa
Run rails new with flags
rocketnova Apr 1, 2024
bc2fead
Rename app to app-rails
rocketnova Apr 11, 2024
b93085d
Setup default application
rocketnova Apr 1, 2024
5c31029
Add environment configuration
rocketnova Apr 9, 2024
398dfd9
Add USWDS config
rocketnova Apr 9, 2024
45bcab7
Add ActiveStorage callback hooks
rocketnova Apr 9, 2024
bb4faee
Start adding AWS integrations
rocketnova Apr 9, 2024
6e9214d
Add additional starting setup
rocketnova Apr 9, 2024
7abc001
Add missing pieces
rocketnova Apr 9, 2024
c3888be
Add documentation
rocketnova Apr 10, 2024
03030e7
Rename paths to use kebab case instead of snake case
rocketnova Apr 10, 2024
4c9a0f5
Document template-only- dirs
rocketnova Apr 10, 2024
4d0bfb1
Setup database
rocketnova Apr 10, 2024
aa9525c
Fix referenced name
rocketnova Apr 10, 2024
c9ad645
*Optimize docker layer caching
rocketnova Apr 10, 2024
43be85f
*Fix waiting for database
rocketnova Apr 10, 2024
6804d5a
Namespace the helper because it was moved
rocketnova Apr 11, 2024
060f393
Fix sandbox
rocketnova Apr 11, 2024
42149c5
Remove non-working sandbox notifications for now
rocketnova Apr 11, 2024
cdb7aee
Remove unused files
rocketnova Apr 11, 2024
8881fc4
Rename everything to app-rails/app_rails
rocketnova Apr 11, 2024
e2668b4
Add comment about database initialization script
rocketnova Apr 11, 2024
3e901da
Add template-only-* content from nextjs app template
rocketnova Apr 11, 2024
2c2adc3
WIP template-only-bin
rocketnova Apr 11, 2024
aef060c
Fix bad rename/rebase
rocketnova Apr 11, 2024
cfb02a0
*Update download-and-install-template.sh
rocketnova Apr 11, 2024
8458788
*Update install-template.sh
rocketnova Apr 11, 2024
57d999c
*Update update-template.sh
rocketnova Apr 11, 2024
db3b326
Copy template-application-nextjs issue templates
rocketnova Apr 11, 2024
e7b8c48
*Update README with new template-only-bin instructions
rocketnova Apr 11, 2024
258823d
*Update update-template.sh
rocketnova Apr 18, 2024
b961650
*Add rename-template-app.sh
rocketnova Apr 18, 2024
70e536a
*Update rename-template-app.sh
rocketnova Apr 18, 2024
f7fb590
*Use bin/rails over bundle exec
rocketnova May 21, 2024
a25f7e3
*Prefix AWS environment variables
rocketnova May 21, 2024
b2c8ed7
*Use ternary expression in development.rb
rocketnova May 21, 2024
7580217
Remove init-postgres for project with one database
rocketnova May 21, 2024
4f5c813
Fix docker service name and bind mount
rocketnova May 21, 2024
c00e3a0
Fix dev docker setup
rocketnova May 21, 2024
8ed9ef2
*Add Makefile support for multiple docker compose files
rocketnova May 21, 2024
a68a509
Troubleshoot release docker build
rocketnova May 21, 2024
6e03118
*Configure setup for mock-production
rocketnova May 21, 2024
ee3a6eb
Genericize i18n strings
rocketnova May 21, 2024
76e531b
Refactored claimant -> applicant
rocketnova May 21, 2024
683eed7
Genericize employer layout
rocketnova May 21, 2024
59dae1a
AWS_BUCKET_NAME is not required for local development
rocketnova May 21, 2024
2ffd925
Fix tests
rocketnova May 21, 2024
f5f34e6
Lint
rocketnova May 22, 2024
6538967
Add CI
rocketnova May 22, 2024
3503e4e
Update bin for mock prod docker compose
rocketnova May 22, 2024
6fab4bf
Clean up some @TODOs
rocketnova May 22, 2024
7053610
Remove template-only-docs for now
rocketnova May 22, 2024
f78af41
Tidy documentation
rocketnova May 22, 2024
3a173d9
Add documentation about docker image builds
rocketnova May 22, 2024
ebed061
More documentation about docker image builds
rocketnova May 22, 2024
f405e57
Refine technical writing
rocketnova May 22, 2024
b0198b3
Genericize
rocketnova May 22, 2024
171fd3f
Update CI lint
rocketnova May 22, 2024
571c5b6
Add template-only-bin scripts
rocketnova May 22, 2024
ecad5b9
Don't require an arg for update-template
rocketnova May 22, 2024
2c58f3b
Add blank docker-compose.mock-production.yml
rocketnova May 22, 2024
05487d2
Ignore .git
rocketnova May 22, 2024
7bc9bf4
Add .keep to node_modules
rocketnova May 22, 2024
e8cafa1
Add .keep to vendor/bundle
rocketnova May 22, 2024
de4e62a
Add missing clean-native files
rocketnova May 22, 2024
bfe6c7b
Refactor template-only-bin scripts
rocketnova May 23, 2024
3e7a7dd
Fix typo
rocketnova May 23, 2024
81dc10c
Fix another typo
rocketnova May 23, 2024
e190f62
Rename from within the correct dir
rocketnova May 23, 2024
e9c22c2
Still using the wrong dir
rocketnova May 23, 2024
c219b8f
Add output info
rocketnova May 23, 2024
4ae9d0a
Merge branch 'rocket/template-only-bin' into rocket/init-template-wit…
rocketnova May 23, 2024
c9abce9
Merge branch 'main' into rocket/init-template-with-name
rocketnova May 23, 2024
48c3597
Update main README
rocketnova May 23, 2024
956ee65
Add screenshot
rocketnova May 23, 2024
9d0befc
Add empty template-only-docs
rocketnova May 23, 2024
7e7228e
Add issue links
rocketnova May 23, 2024
65df560
Remove accidental re-add of deleted file
rocketnova May 23, 2024
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
37 changes: 37 additions & 0 deletions .github/ISSUE_TEMPLATE/bug.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Bug report
description: File a bug report
labels: ["bug", "triage"]
projects: ["navapbc/4"]
body:
- type: markdown
attributes:
value: |
Thanks for taking the time to fill out this bug report!
- type: textarea
attributes:
label: What happened?
description: Also tell us, what did you expect to happen?
placeholder: Tell us what you see!
validations:
required: true
- type: textarea
attributes:
label: Steps to reproduce
description: Share the steps or a link to a repository we can use to reproduce the problem.
- type: dropdown
id: browsers
attributes:
label: What browsers are you seeing the problem on?
multiple: true
options:
- Not applicable
- Firefox
- Chrome
- Safari
- Microsoft Edge
- type: textarea
id: logs
attributes:
label: Relevant log output
description: Please copy and paste any relevant log output. This will be automatically formatted into code, so no need for backticks.
render: shell
32 changes: 32 additions & 0 deletions .github/ISSUE_TEMPLATE/feature.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Feature request
description: Suggest an idea for this project
labels: ["triage", "feature"]
projects: ["navapbc/4"]
body:
- type: textarea
attributes:
label: Describe the problem and the solution you'd like
description: A clear and concise description of what the problem is and what you want to happen.
value: |
**Is your feature request related to a problem? Please describe.**
<!-- A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] -->

**Describe the solution you'd like**
<!-- A clear and concise description of what you want to happen. -->

**Describe alternatives you've considered**
<!-- A clear and concise description of any alternative solutions or features you've considered. -->
- type: textarea
attributes:
label: Additional context
description: Add any other context or screenshots about the feature request here.
- type: dropdown
attributes:
label: Priority
description: How impactful would this be for your project?
multiple: false
options:
- "My project needs this now"
- "I anticipate needing this soon"
- "Nice to have"
- "Just want to discuss"
9 changes: 9 additions & 0 deletions .github/ISSUE_TEMPLATE/task.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: Task
description: Create a task for the team
projects: ["navapbc/4"]
body:
- type: textarea
attributes:
label: What's the task?
validations:
required: true
46 changes: 46 additions & 0 deletions .github/workflows/ci-app-rails.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: CI app-rails

on:
push:
branches:
- main
paths:
- app-rails/**
- .github/workflows/ci-app-rails.yml
pull_request:
paths:
- app-rails/**
- .github/workflows/ci-app-rails.yml

defaults:
run:
working-directory: ./app-rails

jobs:
# As an enhancement, it is possible to share the built docker image and share
# it across jobs as described in:
# https://docs.github.com/en/actions/using-workflows/storing-workflow-data-as-artifacts#passing-data-between-jobs-in-a-workflow
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
# https://github.com/docker/compose/issues/1973
- name: Create required env files
working-directory: ./
run: |
touch ./app-rails/.env

- run: make lint

test:
name: Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- run: make init-container
- run: make precompile-assets

- name: Start tests
run: make test
74 changes: 72 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,72 @@
# template-application-rails
Ruby on Rails with USWDS template, including CI/CD, for teams building web applications
# Template Ruby on Rails application

This is a template repository for a Ruby on Rails application.

See [`navapbc/platform`](https://github.com/navapbc/platform) for other template repos.

## Features

- [U.S. Web Design System](https://designsystem.digital.gov/) for themeable styling and a set of common components
- Integration with AWS services, including:
- Database integration with AWS RDS Postgresql using UUIDs
- Active Storage configuration with AWS S3
- Action Mailer configuration with AWS SES
- Authentication with [devise](https://github.com/heartcombo/devise) and AWS Cognito
- Internationalization (i18n)
- Authorization using [pundit](https://github.com/varvet/pundit)
- Linting and code formatting using [rubocop](https://rubocop.org/)
- Testing using [rspec](https://rspec.info)

<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">

## Repo structure

```text
├── .github # GitHub workflows and repo templates
├── docs # Project docs and decision records
├── app-rails # Web application
├── template-only-bin # Scripts for managing this template; not copied into your project
├── template-only-docs # Documentation for this template; not copied into your project
```

## Installation

To get started using the template application on your project:

1. Run the [download and install script](./template-only-bin/download-and-install-template.sh) in your project's root directory.

```bash
curl https://raw.githubusercontent.com/navapbc/template-application-rails/main/template-only-bin/download-and-install-template.sh | bash -s
```

This script will:

1. Clone the template repository
2. Copy the template files into your project directory
3. Remove any files specific to the template repository, like this README.

You can optionally pass in a branch, commit hash, or release that you want to install. For example:

```bash
curl https://raw.githubusercontent.com/navapbc/template-application-rails/main/template-only-bin/download-and-install-template.sh | bash -s -- <commit_hash>
```
2. [Follow the steps in `app-rails/README.md`](./app-rails/README.md) to set up the application locally.
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.

## Updates

If you have previously installed this template and would like to update your project to use a newer version of this application:

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`).

```bash
curl https://raw.githubusercontent.com/navapbc/template-application-rails/main/template-only-bin/download-and-install-template.sh | bash -s -- <commit_hash> <app_name>
```

This script will:

1. Clone the template repository
2. Copy the template files into your project directory
3. Remove any files specific to the template repository, like this README.

⚠️ Warning! This will modify existing files. Review all changes carefully after executing the script by running `git diff`.
15 changes: 15 additions & 0 deletions app-rails/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@
# Ignore bundler config.
/.bundle

# Ignore installed gems.
/vendor/bundle/*
!/vendor/bundle/.keep

# Ignore all environment files (except templates).
/.env*
/*.env*
!/.env*.erb

# Ignore all logfiles and tempfiles.
Expand All @@ -33,6 +38,16 @@

# Ignore master key for decrypting credentials and more.
/config/master.key
/config/credentials/*

# Ignore development log.
/log/development.log

/app/assets/builds/*
!/app/assets/builds/.keep

/node_modules/*
!/node_modules/.keep

# Testing
coverage/*
1 change: 1 addition & 0 deletions app-rails/.rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--require spec_helper
8 changes: 8 additions & 0 deletions app-rails/.rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require:
- rubocop-rspec
inherit_gem:
pundit: config/rubocop-rspec.yml
rubocop-rails-omakase: rubocop.yml
AllCops:
Exclude:
- lib/templates/**/*
94 changes: 74 additions & 20 deletions app-rails/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

# Make sure RUBY_VERSION matches the Ruby version in .ruby-version and Gemfile
ARG RUBY_VERSION=3.3.0


##########################################################################################
# BASE: Shared base docker image
##########################################################################################
FROM registry.docker.com/library/ruby:$RUBY_VERSION-slim as base

# Rails app lives here
Expand All @@ -10,53 +15,102 @@ WORKDIR /rails
# Set production environment
ENV RAILS_ENV="production" \
BUNDLE_DEPLOYMENT="1" \
BUNDLE_PATH="/usr/local/bundle" \
BUNDLE_WITHOUT="development"
BUNDLE_PATH="/usr/local/bundle"

# Start the server by default, this can be overwritten at runtime
EXPOSE 3000


# Throw-away build stage to reduce size of final image
##########################################################################################
# BUILD: Throw-away build stage
##########################################################################################
FROM base as build

# Install packages needed to build gems
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y build-essential git libpq-dev libvips pkg-config
apt-get install --no-install-recommends -y build-essential git libpq-dev libvips pkg-config npm

# Install npm packages
COPY package.json package-lock.json ./

# Install npm packages
RUN npm install


##########################################################################################
# DEV: Used for development and test
##########################################################################################
FROM build as dev

ENV RAILS_ENV="development"

# Install packages needed for development
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y postgresql-client graphviz && \
rm -rf /var/lib/apt/lists /var/cache/apt/archives

# Install application gems for development
COPY Gemfile Gemfile.lock ./
RUN bundle config set --local without production && \
bundle install && \
rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git

# Install application gems
# Copy application code
COPY . .

CMD ["./bin/dev"]


##########################################################################################
# RELEASE-BUILD: Throw-away build stage for RELEASE
##########################################################################################
FROM build as release-build

# Install application gems for production
COPY Gemfile Gemfile.lock ./
RUN bundle install && \
rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git && \
bundle exec bootsnap precompile --gemfile
RUN bundle config set --local without development test && \
bundle install && \
rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git

# Copy application code
COPY . .

# Precompile bootsnap code for faster boot times
RUN bundle exec bootsnap precompile app/ lib/
RUN bundle exec bootsnap precompile --gemfile app/ lib/

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


# Final stage for app image
FROM base
##########################################################################################
# RELEASE: Used for production
##########################################################################################
FROM base as release

# Set production environment
ENV RAILS_ENV="production" \
BUNDLE_DEPLOYMENT="1" \
BUNDLE_PATH="/usr/local/bundle"

# Install packages needed for deployment
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y curl libvips postgresql-client && \
rm -rf /var/lib/apt/lists /var/cache/apt/archives
apt-get install -y --no-install-recommends unzip python3-venv python-is-python3 curl libvips postgresql-client && \
rm -rf /var/lib/apt/lists /var/cache/apt/archives && \
curl "https://s3.amazonaws.com/aws-cli/awscli-bundle.zip" -o "awscli-bundle.zip" && \
unzip awscli-bundle.zip && \
./awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws && \
rm -rf ./awscli-bundle awscli-bundle.zip

# Install custom db migrate script
COPY bin/db-migrate /usr/bin/

# Copy built artifacts: gems, application
COPY --from=build /usr/local/bundle /usr/local/bundle
COPY --from=build /rails /rails
COPY --from=release-build /usr/local/bundle /usr/local/bundle
COPY --from=release-build /rails /rails

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

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

# Start the server by default, this can be overwritten at runtime
EXPOSE 3000
CMD ["./bin/rails", "server"]
Loading
Loading