Skip to content

Commit 1b7173c

Browse files
committed
Initial commit
0 parents  commit 1b7173c

37 files changed

+14499
-0
lines changed

.dockerignore

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
node_modules
2+
npm-debug.log
3+
Dockerfile
4+
.dockerignore
5+
docs
6+
helm
7+
docker-compose*
8+
.secrets.baseline
9+
.snyk
10+
.pre-commit-config.yaml
11+
LICENCE
12+
README.md
13+
jsconfig.json
14+
.vscode
15+
.gitignore

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
test-output
2+
node_modules
3+
helm/**/*.lock
4+
*.tgz
5+
.vscode

.pre-commit-config.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
repos:
2+
- repo: https://github.com/Yelp/detect-secrets
3+
rev: v1.2.0
4+
hooks:
5+
- id: detect-secrets
6+
args: ['--baseline', '.secrets.baseline']

.secrets.baseline

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
{
2+
"version": "1.2.0",
3+
"plugins_used": [
4+
{
5+
"name": "ArtifactoryDetector"
6+
},
7+
{
8+
"name": "AWSKeyDetector"
9+
},
10+
{
11+
"name": "AzureStorageKeyDetector"
12+
},
13+
{
14+
"name": "Base64HighEntropyString",
15+
"limit": 4.5
16+
},
17+
{
18+
"name": "BasicAuthDetector"
19+
},
20+
{
21+
"name": "CloudantDetector"
22+
},
23+
{
24+
"name": "GitHubTokenDetector"
25+
},
26+
{
27+
"name": "HexHighEntropyString",
28+
"limit": 3.0
29+
},
30+
{
31+
"name": "IbmCloudIamDetector"
32+
},
33+
{
34+
"name": "IbmCosHmacDetector"
35+
},
36+
{
37+
"name": "JwtTokenDetector"
38+
},
39+
{
40+
"name": "KeywordDetector",
41+
"keyword_exclude": ""
42+
},
43+
{
44+
"name": "MailchimpDetector"
45+
},
46+
{
47+
"name": "NpmDetector"
48+
},
49+
{
50+
"name": "PrivateKeyDetector"
51+
},
52+
{
53+
"name": "SendGridDetector"
54+
},
55+
{
56+
"name": "SlackDetector"
57+
},
58+
{
59+
"name": "SoftlayerDetector"
60+
},
61+
{
62+
"name": "SquareOAuthDetector"
63+
},
64+
{
65+
"name": "StripeDetector"
66+
},
67+
{
68+
"name": "TwilioKeyDetector"
69+
}
70+
],
71+
"filters_used": [
72+
{
73+
"path": "detect_secrets.filters.allowlist.is_line_allowlisted"
74+
},
75+
{
76+
"path": "detect_secrets.filters.common.is_ignored_due_to_verification_policies",
77+
"min_level": 2
78+
},
79+
{
80+
"path": "detect_secrets.filters.heuristic.is_indirect_reference"
81+
},
82+
{
83+
"path": "detect_secrets.filters.heuristic.is_likely_id_string"
84+
},
85+
{
86+
"path": "detect_secrets.filters.heuristic.is_lock_file"
87+
},
88+
{
89+
"path": "detect_secrets.filters.heuristic.is_not_alphanumeric_string"
90+
},
91+
{
92+
"path": "detect_secrets.filters.heuristic.is_potential_uuid"
93+
},
94+
{
95+
"path": "detect_secrets.filters.heuristic.is_prefixed_with_dollar_sign"
96+
},
97+
{
98+
"path": "detect_secrets.filters.heuristic.is_sequential_string"
99+
},
100+
{
101+
"path": "detect_secrets.filters.heuristic.is_swagger_file"
102+
},
103+
{
104+
"path": "detect_secrets.filters.heuristic.is_templated_secret"
105+
}
106+
],
107+
"results": {},
108+
"generated_at": "2022-02-22T08:52:45Z"
109+
}

.snyk

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Snyk (https://snyk.io) policy file, patches or ignores known vulnerabilities.
2+
version: v1.19.0
3+
ignore: {}
4+
patch: {}

Dockerfile

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
ARG PARENT_VERSION=1.2.15-node16.14.0
2+
ARG PORT=3000
3+
ARG PORT_DEBUG=9229
4+
5+
# Development
6+
FROM defradigital/node-development:${PARENT_VERSION} AS development
7+
ARG PARENT_VERSION
8+
LABEL uk.gov.defra.ffc.parent-image=defradigital/node-development:${PARENT_VERSION}
9+
10+
ARG PORT
11+
ARG PORT_DEBUG
12+
ENV PORT ${PORT}
13+
EXPOSE ${PORT} ${PORT_DEBUG}
14+
15+
COPY --chown=node:node package*.json ./
16+
RUN npm install
17+
COPY --chown=node:node . .
18+
CMD [ "npm", "run", "start:watch" ]
19+
20+
# Production
21+
FROM defradigital/node:${PARENT_VERSION} AS production
22+
ARG PARENT_VERSION
23+
LABEL uk.gov.defra.ffc.parent-image=defradigital/node:${PARENT_VERSION}
24+
25+
ARG PORT
26+
ENV PORT ${PORT}
27+
EXPOSE ${PORT}
28+
29+
COPY --from=development /home/node/app/ ./app/
30+
COPY --from=development /home/node/package*.json ./
31+
RUN npm ci
32+
CMD [ "node", "app" ]

Jenkinsfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@Library('defra-library@v-9') _
2+
3+
buildNodeJs()

LICENCE

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
The Open Government Licence (OGL) Version 3
2+
3+
Copyright (c) 2020 Defra
4+
5+
This source code is licensed under the Open Government Licence v3.0. To view this
6+
licence, visit www.nationalarchives.gov.uk/doc/open-government-licence/version/3
7+
or write to the Information Policy Team, The National Archives, Kew, Richmond,
8+
Surrey, TW9 4DU.

README.md

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
# FFC Template Node
2+
3+
Template to support rapid delivery of microservices for FFC Platform. It contains the configuration needed to deploy a simple Hapi Node server to the Azure Kubernetes Platform.
4+
5+
## Usage
6+
7+
Create a new repository from this template and run `./rename.js` specifying the new name of the project and the description to use e.g.
8+
```
9+
./rename.js ffc-demo-web "Web frontend for demo workstream"
10+
```
11+
12+
The script will update the following:
13+
14+
* `package.json`: update `name`, `description`, `homepage`
15+
* `docker-compose.yaml`: update the service name, `image` and `container_name`
16+
* `docker-compose.test.yaml`: update the service name, `image` and `container_name`
17+
* `docker-compose.override.yaml`: update the service name, `image` and `container_name`
18+
* Rename `helm/ffc-template-node`
19+
* `helm/ffc-template-node/Chart.yaml`: update `description` and `name`
20+
* `helm/ffc-template-node/values.yaml`: update `name`, `namespace`, `workstream`, `image`, `containerConfigMap.name`
21+
* `helm/ffc-template-node/templates/_container.yaml`: update the template name
22+
* `helm/ffc-template-node/templates/cluster-ip-service.yaml`: update the template name and list parameter of include
23+
* `helm/ffc-template-node/templates/config-map.yaml`: update the template name and list parameter of include
24+
* `helm/ffc-template-node/templates/deployment.yaml`: update the template name, list parameter of deployment and container includes
25+
26+
### Notes on automated rename
27+
28+
* The Helm chart deployment values in `helm/ffc-template-node/values.yaml` may need updating depending on the resource needs of your microservice
29+
* The rename is a one-way operation i.e. currently it doesn't allow the name being changed from to be specified
30+
* There is some validation on the input to try and ensure the rename is successful, however, it is unlikely to stand up to malicious entry
31+
* Once the rename has been performed the script can be removed from the repo
32+
* Should the rename go awry the changes can be reverted via `git clean -df && git checkout -- .`
33+
34+
## Prerequisites
35+
36+
- Docker
37+
- Docker Compose
38+
39+
Optional:
40+
- Kubernetes
41+
- Helm
42+
43+
## Running the application
44+
45+
The application is designed to run in containerised environments, using Docker Compose in development and Kubernetes in production.
46+
47+
- A Helm chart is provided for production deployments to Kubernetes.
48+
49+
### Build container image
50+
51+
Container images are built using Docker Compose, with the same images used to run the service with either Docker Compose or Kubernetes.
52+
53+
When using the Docker Compose files in development the local `app` folder will
54+
be mounted on top of the `app` folder within the Docker container, hiding the CSS files that were generated during the Docker build. For the site to render correctly locally `npm run build` must be run on the host system.
55+
56+
57+
By default, the start script will build (or rebuild) images so there will
58+
rarely be a need to build images manually. However, this can be achieved
59+
through the Docker Compose
60+
[build](https://docs.docker.com/compose/reference/build/) command:
61+
62+
```
63+
# Build container images
64+
docker-compose build
65+
```
66+
67+
### Start
68+
69+
Use Docker Compose to run service locally.
70+
71+
```
72+
docker-compose up
73+
```
74+
75+
## Test structure
76+
77+
The tests have been structured into subfolders of `./test` as per the
78+
[Microservice test approach and repository structure](https://eaflood.atlassian.net/wiki/spaces/FPS/pages/1845396477/Microservice+test+approach+and+repository+structure)
79+
80+
### Running tests
81+
82+
A convenience script is provided to run automated tests in a containerised
83+
environment. This will rebuild images before running tests via docker-compose,
84+
using a combination of `docker-compose.yaml` and `docker-compose.test.yaml`.
85+
The command given to `docker-compose run` may be customised by passing
86+
arguments to the test script.
87+
88+
Examples:
89+
90+
```
91+
# Run all tests
92+
scripts/test
93+
94+
# Run tests with file watch
95+
scripts/test -w
96+
```
97+
98+
## CI pipeline
99+
100+
This service uses the [FFC CI pipeline](https://github.com/DEFRA/ffc-jenkins-pipeline-library)
101+
102+
## Licence
103+
104+
THIS INFORMATION IS LICENSED UNDER THE CONDITIONS OF THE OPEN GOVERNMENT LICENCE found at:
105+
106+
<http://www.nationalarchives.gov.uk/doc/open-government-licence/version/3>
107+
108+
The following attribution statement MUST be cited in your products and applications when using this information.
109+
110+
> Contains public sector information licensed under the Open Government license v3
111+
112+
### About the licence
113+
114+
The Open Government Licence (OGL) was developed by the Controller of Her Majesty's Stationery Office (HMSO) to enable information providers in the public sector to license the use and re-use of their information under a common open licence.
115+
116+
It is designed to encourage use and re-use of information freely and flexibly, with only a few conditions.

app/index.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const server = require('./server')
2+
3+
const init = async () => {
4+
await server.start()
5+
console.log('Server running on %s', server.info.uri)
6+
}
7+
8+
process.on('unhandledRejection', (err) => {
9+
console.log(err)
10+
process.exit(1)
11+
})
12+
13+
init()

0 commit comments

Comments
 (0)