Skip to content

Commit

Permalink
I have decided to convert all the JavaScript in the application to Ty…
Browse files Browse the repository at this point in the history
…peScript.

We have quite a lot of JavaScript in this application and I do find it quite difficult to maintain. I am hopeful TypeScript will make all the maintenance easier and help future proof our code. It also gave me an opportunity to review our code and remove anything that was no longer needed.

(I also had nothing else to do at this moment in time and wanted to give myself a challenge)
  • Loading branch information
tim-s-ccs committed Sep 27, 2022
1 parent 3bd0536 commit 35826bd
Show file tree
Hide file tree
Showing 93 changed files with 3,879 additions and 3,523 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,6 @@ launch.json

# We are using yarn not npm, but this file sometimes gets added by snyk which brakes the pipeline
package-lock.json

# We will compile the typescript as part of the assets pipeline
app/assets/javascripts/dist/*
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ RUN bundle install

# Install Node.js dependencies
COPY package.json yarn.lock ./
RUN yarn install --frozen-lockfile --production --no-cache
RUN yarn install --frozen-lockfile --production --no-cache --ignore-scripts

COPY . .

Expand Down
105 changes: 14 additions & 91 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ make
### MacOS

#### Check the Ruby version
##### N.B. The project currently runs on 2.7.4. (August 2021)
##### N.B. The project currently runs on 2.7.6 (April 2022)

Ensure that a ruby version manager (e.g. rvm or rbenv) is installed and set up properly, using 2.7.4 as the Ruby version before trying anything else.
Ensure that a ruby version manager (e.g. rvm or rbenv) is installed and set up properly, using 2.7.6 as the Ruby version before trying anything else.

#### Install Postgres and PostGIS
`brew install postgres` (this will install the latest (HEAD) version, currently 12. The server runs 11!)
Expand Down Expand Up @@ -118,43 +118,11 @@ obtained from the [AWS Systems Manager Parameter Store][aws-parameter-store].
* If present, enable the Cognito sign-in link on the Supply Teachers gateway
page

#### DfE Sign-in

* `DFE_SIGNIN_URL`
* Obtained from DfE Sign-in. Should have just `/` as a path component, e.g.
`https://signin.example.com/`.
* `DFE_SIGNIN_CLIENT_ID`
* Obtained from DfE Sign-in.
* `DFE_SIGNIN_CLIENT_SECRET`
* Obtained from DfE Sign-in.
* `DFE_SIGNIN_REDIRECT_URI`
* A link to the authentication callback in this application, i.e.
`https://marketplace.service.crowncommercial.gov.uk/auth/dfe/callback` for
the live service
* `DFE_SIGNIN_WHITELISTED_EMAIL_ADDRESSES`
* Comma-separated list of email addresses allowed access via DfE Sign-in
* If this variable is not present, DfE Sign-in is not protected by
whitelisting

#### Google Analytics

* `GA_TRACKING_ID`
* Google Analytics is disabled if this is not set

#### Upload URL protection

HTTP Basic Authentication credentials. Only needed in production environments.
See the [Uploading data section](#uploading-data) below.

* `HTTP_BASIC_AUTH_NAME`
* `HTTP_BASIC_AUTH_PASSWORD`

If the following environment variable is set then the app exposes routes for
uploading supplier data JSON. Otherwise those routes do not exist and users
receive a 404.

* `APP_HAS_UPLOAD_PRIVILEGES`

#### Database

The following are used to configure the database, but only in production
Expand All @@ -181,47 +149,6 @@ rails s
```

Visit [localhost:3000](http://localhost:3000).

## Uploading data

You can upload data for a given framework using the following command where
`FRAMEWORK_NAME` is one of `supply-teachers`, `facilities-management` or
`management-consultancy`; `SCHEME` is one of `http` (local development) or
`https` (other environments); `HTTP_BASIC_AUTH_NAME` &
`HTTP_BASIC_AUTH_PASSWORD` credentials (only needed for production
environments):

```
git clone [email protected]:Crown-Commercial-Service/crown-marketplace-data.git
cd crown-marketplace-data/$FRAMEWORK_NAME
curl --user $HTTP_BASIC_AUTH_NAME:$HTTP_BASIC_AUTH_PASSWORD --request POST \
--header "Content-Type: application/json" --data @output/data.json \
$SCHEME://$HOST/$FRAMEWORK_NAME/uploads
```

### Audit trail

The application keeps a record of each *successful* upload in the database. So,
for example, the time of the most recent upload for a framework can be obtained
using the Rails console with one of the following commands:

* `FacilitiesManagement::Upload.order(:created_at).last.created_at`
* `ManagementConsultancy::Upload.order(:created_at).last.created_at`
* `SupplyTeachers::Upload.order(:created_at).last.created_at`

## Regenerating error pages

We use the [juice][] npm package to generate HTML error pages from the live
service, inlining all CSS, images, web fonts, etc. A Rake task makes this
easier:

```
rake 'error_pages[http://localhost:3000]'
```

This will pull down `/errors/404.html`, for example, and save an inlined copy in
`public/404.html`.

## Development

### Design & frontend
Expand All @@ -233,6 +160,7 @@ This will pull down `/errors/404.html`, for example, and save an inlined copy in
[yarn][], and the exact versions of all dependencies direct/indirect are
locked in `yarn.lock`.
* The CSS follows [Block Element Modifier][] conventions.
* We use `TypeScript` to write our frontend code (in `app/typescript`)

### Code

Expand All @@ -246,9 +174,6 @@ which are somewhat non-standard:
framework into a separate Rails app if that was deemed appropriate down the
line.

* The supplier-related data for each framework is bulk uploaded over HTTPS to be
stored in the database; the data is then effectively regarded as read-only.

* A bunch of other less-variable data is stored in CSV files in the code
repository and made available to the application via classes including the
`StaticRecord` concern, e.g. `Nuts3Region` which loads its data from
Expand Down Expand Up @@ -308,9 +233,8 @@ classes.
various types.
* I18n translations are used in specs to reduce their sensitivity to copy
changes.
* [RSpec feature specs][feature-specs] are used for acceptance testing.
* RSpec matchers from the [capybara][] gem are used throughout the specs to
make assertions about rendered HTML.
* We use the [Cucumber][] testing framework to test the frontend functionality with a subset of the test run as part of the CI.
* We use [Axe Cucumber][] to run accessibility tests but these are not run as part of the CI.
* All the specs are run as part of the default Rake task, but the standard
RSpec-provided Rake tasks also exist for running sub-groups of the specs.

Expand All @@ -324,16 +248,13 @@ Note that some lines are excluded from simplecov with the `# :nocov:` instructio

### Continuous integration & deployment

* Continuous integration and deployment is implemented on the new AWS-based CCS
infrastructure.
* The tests are run automatically when a new commit is pushed to a triggering
branch of this repository on GitHub. This is achieved using
[AWS CodePipeline][] and [AWS CodeBuild][].
* The `pipeline_pre_build_tests.sh` script is run to install everything that's
needed to run the tests on the fairly vanilla CodeBuild container.
* The `pipeline_run_build_tests.sh` script is what actually runs the tests.
* If all the tests pass, then a container is built using the `Dockerfile` in
this repo, uploaded to the [AWS Elastic Container Registry][], and deployed
* When a branch is pushed or pull request is raised GitHub actions will run
the rspec and cucumber test suites.
* When the PR is merged to a main branch GitHub actions will run the test suites
again before triggering the AWS pipeline.
* We use [AWS CodePipeline][] and [AWS CodeBuild][] to build and deploy the application.
* A container is built using the `Dockerfile` in this repo,
uploaded to the [AWS Elastic Container Registry][], and deployed
using [AWS Elastic Container Service][].
* Environment variables for the various containers running on the AWS
infrastructure are obtained from the
Expand Down Expand Up @@ -365,3 +286,5 @@ Note that some lines are excluded from simplecov with the `# :nocov:` instructio
[CMpDevEnvironment]: https:/Crown-Commercial-Service/CMpDevEnvironment
[CMp Developer Guide]: https:/Crown-Commercial-Service/CMpDevEnvironment/blob/develop/docs/ccs_aws_v1-developer_guide.md
[faker]: https:/stympy/faker
[Cucumber]: https://cucumber.io/
[Axe Cucumber]: https://www.deque.com/axe/
7 changes: 1 addition & 6 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,4 @@
//= require jquery3
//= require rails-ujs
//= require govuk-frontend/govuk/all
//= require google-analytics
//= require cookie-banner
//= require_tree ./common
//= require_tree ./facilities-management
//= require cp/cp-sign-in.js
//= require global/global.js
//= require_tree ./dist
31 changes: 0 additions & 31 deletions app/assets/javascripts/common/common.js

This file was deleted.

Loading

0 comments on commit 35826bd

Please sign in to comment.