Skip to content

Commit ac86813

Browse files
authored
Update Dockerfile & README (#771)
1 parent 37f493d commit ac86813

16 files changed

+98
-164
lines changed

.env.example

-2
This file was deleted.

.env.test.example

-3
This file was deleted.

.github/workflows/test.yml

+1-6
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,9 @@ jobs:
4242
with:
4343
bundler-cache: true
4444

45-
- name: Setup Node
46-
uses: actions/setup-node@v4
47-
with:
48-
node-version: 14.17.5
49-
5045
- name: Find yarn cache location
5146
id: yarn-cache
52-
run: echo "::set-output name=dir::$(yarn cache dir)"
47+
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT
5348

5449
- name: JS package cache
5550
uses: actions/cache@v4

Dockerfile

+11-28
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,25 @@ FROM ruby:3.2.3-alpine as builder
22

33
# build dependencies:
44
RUN apk add --no-cache \
5+
ruby-dev \
56
build-base \
67
postgresql-dev \
78
tzdata \
89
yarn
910

1011
WORKDIR /app
1112

12-
COPY Gemfile* .ruby-version ./
13+
COPY Gemfile* .ruby-version package.json yarn.lock ./
1314

14-
RUN gem install bundler -v 2.4.19
1515
RUN bundle config deployment true && \
1616
bundle config without development test && \
17-
bundle install --jobs 4 --retry 3
18-
19-
# Install node packages defined in package.json
20-
COPY package.json yarn.lock ./
21-
RUN yarn install --frozen-lockfile --check-files
17+
bundle install --jobs 4 --retry 3 && \
18+
yarn install --frozen-lockfile
2219

2320
# Copy all files to /app
2421
COPY . .
2522

26-
# The following are ENV variables that need to be present by the time
27-
# the assets pipeline run, but doesn't matter their value.
28-
#
29-
ENV EXTERNAL_URL replace_this_at_build_time
30-
ENV SECRET_KEY_BASE replace_this_at_build_time
31-
ENV GOVUK_NOTIFY_API_KEY replace_this_at_build_time
32-
33-
ENV RAILS_ENV production
34-
RUN bundle exec rake assets:precompile
23+
RUN RAILS_ENV=production SECRET_KEY_BASE_DUMMY=1 bundle exec rake assets:precompile
3524

3625
# Copy fonts and images (without digest) along with the digested ones,
3726
# as there are some hardcoded references in the `govuk-frontend` files
@@ -40,20 +29,19 @@ RUN cp -r node_modules/govuk-frontend/dist/govuk/assets/. public/assets/
4029

4130
# tidy up installation
4231
RUN rm -rf log/* tmp/* /tmp && \
43-
rm -rf /usr/local/bundle/cache && \
44-
find /usr/local/bundle/gems -name "*.c" -delete && \
45-
find /usr/local/bundle/gems -name "*.h" -delete && \
46-
find /usr/local/bundle/gems -name "*.o" -delete && \
47-
find /usr/local/bundle/gems -name "*.html" -delete
32+
rm -rf /usr/local/bundle/cache
4833

4934
# Build runtime image
5035
FROM ruby:3.2.3-alpine
5136

5237
# The application runs from /app
5338
WORKDIR /app
5439

55-
# libpq: required to run postgres, tzdata: required to set timezone, nodejs: JS runtime
56-
RUN apk add --no-cache libpq tzdata nodejs
40+
# postgresql-client: to run postgres, tzdata: required to set timezone, nodejs: JS runtime
41+
RUN apk add --no-cache \
42+
postgresql-client \
43+
tzdata \
44+
nodejs
5745

5846
# add non-root user and group with alpine first available uid, 1000
5947
RUN addgroup -g 1000 -S appgroup && \
@@ -78,8 +66,3 @@ ENV APP_GIT_COMMIT ${APP_GIT_COMMIT}
7866

7967
ENV APPUID 1000
8068
USER $APPUID
81-
82-
ENV PUMA_PORT 3000
83-
EXPOSE $PUMA_PORT
84-
85-
ENTRYPOINT ["./run.sh"]

Gemfile

-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
33

44
ruby File.read(".ruby-version").strip
55

6-
# Reduces boot times through caching; required in config/boot.rb
7-
gem "bootsnap", ">= 1.1.0", require: false
86
gem "govuk-components", "~> 5.4"
97
gem "govuk_design_system_formbuilder"
108
gem "jquery-rails"

Gemfile.lock

+8-4
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,6 @@ GEM
9090
bigdecimal (3.1.8)
9191
binding_of_caller (1.0.0)
9292
debug_inspector (>= 0.0.1)
93-
bootsnap (1.12.0)
94-
msgpack (~> 1.2)
9593
brakeman (6.1.2)
9694
racc
9795
builder (3.3.0)
@@ -159,6 +157,8 @@ GEM
159157
factory_bot (~> 6.4)
160158
railties (>= 5.0.0)
161159
ffi (1.17.0)
160+
ffi (1.17.0-arm64-darwin)
161+
ffi (1.17.0-x86_64-linux-gnu)
162162
globalid (1.2.1)
163163
activesupport (>= 6.1)
164164
govuk-components (5.4.0)
@@ -221,7 +221,6 @@ GEM
221221
mini_mime (1.1.5)
222222
mini_portile2 (2.8.7)
223223
minitest (5.24.1)
224-
msgpack (1.7.1)
225224
multi_test (1.1.0)
226225
mutex_m (0.2.0)
227226
net-imap (0.4.10)
@@ -237,6 +236,10 @@ GEM
237236
nokogiri (1.16.6)
238237
mini_portile2 (~> 2.8.2)
239238
racc (~> 1.4)
239+
nokogiri (1.16.6-arm64-darwin)
240+
racc (~> 1.4)
241+
nokogiri (1.16.6-x86_64-linux)
242+
racc (~> 1.4)
240243
pagy (8.4.5)
241244
parallel (1.25.1)
242245
parser (3.3.3.0)
@@ -437,12 +440,13 @@ GEM
437440
zeitwerk (2.6.16)
438441

439442
PLATFORMS
443+
arm64-darwin-23
440444
ruby
445+
x86_64-linux
441446

442447
DEPENDENCIES
443448
better_errors
444449
binding_of_caller
445-
bootsnap (>= 1.1.0)
446450
brakeman
447451
capybara
448452
cucumber (< 9.0.0)

README.md

+52-67
Original file line numberDiff line numberDiff line change
@@ -27,103 +27,88 @@ We have also added visual graphics to better aid understanding:
2727

2828
- [docs/results](docs/results)
2929

30-
We have also gather together all the documents and information we have gone through in one ticket:
31-
32-
- https://trello.com/c/kT50EDZ7
33-
34-
If for some reason the ticket is not available, please refer to the following:
30+
Please refer to the following for more information:
3531

3632
- https://www.gov.uk/guidance/rehabilitation-periods
37-
- https://hub.unlock.org.uk/knowledgebase/detailedguideroa/
33+
- https://hub.unlock.org.uk/advice/detailedguideroa/
3834
- https://docs.google.com/spreadsheets/d/1ZSCk-wgMfIc22GQahKH_ys4u-E9GWIn6dQ7mm5t1RFI/edit#gid=2019860123
3935

4036
It is important to understand how convictions work, as this is the main reason for the existence of this service.
4137

42-
## Docker
43-
44-
The application can be run inside a docker container. This will take care of the ruby environment, postgres database,
45-
and any other dependency for you, without having to configure anything in your machine.
46-
47-
* `docker-compose up`
48-
49-
The application will be run in "production" mode, so will be as accurate as possible to a real production environment.
50-
51-
Please note, in production environments this is done in a slightly different way as we don't use docker-compose in those
52-
environments (kubernetes cluster). But the general idea is the same.
53-
54-
## Getting Started
55-
56-
You will need to install [Homebrew](https://brew.sh), to enable the `brew` command.
57-
58-
* Copy `.env.example` to `.env` and replace with suitable values.
38+
## Development
5939

60-
* `bundle install`
61-
* `bundle exec rails db:setup`
62-
* `bundle exec rails db:migrate`
63-
* `bundle exec rails server`
40+
### Working on the Code
6441

65-
### GOV.UK Frontend (styles, javascript and other assets)
42+
Work should be based off of, and PRed to, the main branch. We use the GitHub
43+
PR approval process so once your PR is ready you'll need to have one person
44+
approve it, and the CI tests passing, before it can be merged.
6645

67-
* `brew install yarn` # if you don't have it already
68-
* `yarn` # this will install the dependencies
6946

70-
### For running the tests:
47+
### Basic Setup
7148

72-
* Copy `.env.test.example` to `.env.test` and replace with suitable values if you expect to run the tests
73-
* `RAILS_ENV=test bundle exec rails db:setup`
74-
* `RAILS_ENV=test bundle exec rails db:migrate`
49+
#### Cloning This Repository
7550

76-
You can then run all the code linters and tests with:
51+
Clone this repository then `cd` into the new directory
7752

78-
* `RAILS_ENV=test bundle exec rake`
79-
or
80-
* `RAILS_ENV=test bundle exec rake test:all_the_things`
53+
```
54+
$ git clone git@github.com:ministryofjustice/disclosure-checker.git
55+
$ cd disclosure-checker
56+
```
8157

82-
Or you can run specific tests as follows (refer to *lib/tasks/all_tests.rake* for the complete list):
58+
### Installing the app for development
8359

84-
* `RAILS_ENV=test bundle exec rake spec`
85-
* `RAILS_ENV=test bundle exec rake brakeman`
60+
#### Latest Version of Ruby
8661

87-
## Cucumber features
62+
If you don't have `rbenv` already installed, install it as follows:
63+
```
64+
$ brew install rbenv ruby-build
65+
$ rbenv init
66+
```
8867

89-
ChromeDriver is needed for the integration tests. It can be installed on Mac using Homebrew: `brew cask install chromedriver`
68+
Follow the instructions printed out from the `rbenv init` command and update your `~/.bash_profile` or equivalent file accordingly, then start a new terminal and navigate to the repo directory.
9069

91-
The features can be run manually (these are not part of the default rake task) in any of these forms:
70+
Use `rbenv` to install the latest version of ruby as defined in `.ruby-version` (make sure you are in the repo path):
9271

93-
* `bundle exec cucumber features`
94-
* `bundle exec cucumber features/caution.feature`
95-
* `bundle exec cucumber features/caution.feature -t @happy_path`
72+
```
73+
$ rbenv install
74+
```
9675

97-
Any of the files in the [features](features) directory can be run individually.
76+
#### Dependencies
9877

99-
By default cucumber will start a local server on a random port, run features against that server, and kill the server once the features have finished.
78+
Node.js:
10079

101-
If you want to show the browser (useful to debug issues) prefix the commands like this:
80+
```
81+
$ brew install node
82+
```
10283

103-
* `SHOW_BROWSER=1 bundle exec cucumber features/caution.feature`
84+
Yarn
10485

105-
## K8s cluster staging environment
86+
```
87+
$ brew install yarn
88+
```
10689

107-
There is a staging environment running on [this url][k8s-staging]
90+
Postgresql
10891

109-
The staging env uses http basic auth to restrict access. The username and
110-
password should be available from the MoJ Rattic server, in the Family Justice group.
92+
```
93+
$ brew install postgresql
94+
```
11195

112-
This environment should be used for any test or demo purposes, user research, etc.
113-
Do not use production for tests as this will have an impact on metrics and will trigger real emails
96+
#### Setup
11497

115-
There is a [deploy repo][deploy-repo] for this staging environment.
116-
It contains the k8s configuration files and also the required ENV variables.
98+
Use the following commands to install gems and javascript packages then create the database
11799

118-
## Continuous integration and deployment
100+
```
101+
$ bin/setup
102+
$ bin/yarn install
103+
```
119104

120-
GitHub actions are used for CI and CD and you can find the configuration in `.github/workflows/test-build-deploy.yml`
105+
#### Running locally:
121106

122-
After a successful merge to `main`, a docker image will be created and pushed to an ECR repository.
123-
It will also trigger an automatic deploy to [staging][k8s-staging].
107+
```
108+
$ bin/rails server
109+
```
124110

125-
For more details, refer to the [deploy repo][deploy-repo].
111+
The site will be accessible at http://localhost:3000.
126112

127-
[c100-application]: https://github.com/ministryofjustice/c100-application
128-
[deploy-repo]: https://github.com/ministryofjustice/disclosure-checker-deploy
129-
[k8s-staging]: https://disclosure-checker-staging.apps.live.cloud-platform.service.justice.gov.uk
113+
## Exceptions
114+
Any exceptions raised in any deployed environment will be sent to [Sentry](https://ministryofjustice.sentry.io/projects/disclosure-checker).

config/application.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class Application < Rails::Application
3333
# Don't generate system test files.
3434
config.generators.system_tests = nil
3535

36-
config.x.session.expires_in_minutes = ENV.fetch("SESSION_EXPIRES_IN_MINUTES", 60).to_i
36+
config.x.session.expires_in_minutes = 60
3737

3838
config.x.surveys.feedback = "https://www.research.net/r/QW7JCHL".freeze
3939

@@ -47,6 +47,8 @@ class Application < Rails::Application
4747
config.x.cookies_consent_name = "dc_cookies_consent".freeze
4848
config.x.cookies_consent_expiration = 1.year
4949

50+
config.add_autoload_paths_to_load_path = false
51+
5052
config.sentry_dsn = "https://d82ca719a5b246bf80342c2266fe7550@o345774.ingest.sentry.io/5373163"
5153
end
5254
end

config/boot.rb

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
22

33
require "bundler/setup" # Set up gems listed in the Gemfile.
4-
require "bootsnap/setup" # Speed up boot time by caching expensive operations.

config/database.yml

+3
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@ default: &default
77
adapter: postgresql
88

99
development:
10+
database: disclosure_checker_development
1011
<<: *default
1112
test:
13+
database: disclosure_checker_test
1214
<<: *default
1315
production:
16+
database: disclosure_checker_production
1417
<<: *default
File renamed without changes.

config/initializers/form_builder.rb

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
require "custom_form_helpers"
1+
Rails.application.config.to_prepare do
2+
ActionView::Base.default_form_builder = GOVUKDesignSystemFormBuilder::FormBuilder
23

3-
ActionView::Base.default_form_builder = GOVUKDesignSystemFormBuilder::FormBuilder
4+
GOVUKDesignSystemFormBuilder.configure do |config|
5+
config.default_error_summary_turbo_prefix = "turbolinks"
46

5-
GOVUKDesignSystemFormBuilder.configure do |config|
6-
config.default_error_summary_turbo_prefix = "turbolinks"
7+
config.default_legend_tag = "h1"
8+
config.default_legend_size = "xl"
9+
config.default_caption_size = "xl"
10+
end
711

8-
config.default_legend_tag = "h1"
9-
config.default_legend_size = "xl"
10-
config.default_caption_size = "xl"
11-
end
12-
13-
GOVUKDesignSystemFormBuilder::FormBuilder.class_eval do
14-
include CustomFormHelpers
12+
GOVUKDesignSystemFormBuilder::FormBuilder.class_eval do
13+
include CustomFormHelpers
14+
end
1515
end

config/kubernetes/production/deployment.yml

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ spec:
2626
imagePullPolicy: Always
2727
ports:
2828
- containerPort: 3000
29+
command: ["./config/docker/entrypoint-webapp.sh"]
2930
resources:
3031
requests:
3132
cpu: 125m

0 commit comments

Comments
 (0)