Skip to content

Commit 6a1cd6d

Browse files
committed
update readme
1 parent a76a614 commit 6a1cd6d

File tree

1 file changed

+88
-49
lines changed

1 file changed

+88
-49
lines changed

README.md

Lines changed: 88 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@ EPS DEV CONTAINERS
33

44
# Introduction
55
This repo contains code to build a vscode devcontainers that can be used as a base image for all EPS projects.
6-
Images are build for amd64 and arm64 and a manifest file created that can be pulled for both architectures.
7-
Images are based on mcr.microsoft.com/devcontainers/base:ubuntu-22.04
8-
Images contain
6+
Images are build for amd64 and arm64 and a manifest file created that can be pulled for both architectures. This is then pushed to github container registry.
7+
Images are built using using https://github.com/devcontainers/cli.
8+
9+
We build a base image based on mcr.microsoft.com/devcontainers/base:ubuntu-22.04 that other images are then based on
10+
11+
The base image contains
912
- latest os packages
1013
- asdf
1114
- aws cli
@@ -24,94 +27,130 @@ asdf install and setup for these so they are available globally as vscode user
2427
- ruby (for github pages)
2528
- trivy
2629

27-
Install asdf plugins for all tools we use
2830
Install and setup git-secrets
2931

32+
# Using the images
33+
In each eps project, you can put this in the devcontainer Dockerfile. You should not need to add any features.
34+
```
35+
FROM ghcr.io/nhsdigital/eps-devcontainers/node_24_python_3_13:<version>
36+
37+
USER root
38+
# specify DOCKER_GID to force container docker group id to match host
39+
RUN if [ -n "${DOCKER_GID}" ]; then \
40+
if ! getent group docker; then \
41+
groupadd -g ${DOCKER_GID} docker; \
42+
else \
43+
groupmod -g ${DOCKER_GID} docker; \
44+
fi && \
45+
usermod -aG docker vscode; \
46+
fi
47+
48+
USER vscode
49+
```
50+
3051
# Project structure
31-
## base container
32-
The base dev container is defined in src/base/.devcontainer folder. This folder contains a Dockerfile and a devcontainer.json file which is used to build the container.
33-
As part of the dockerfile, there are scripts in the scripts folder that run as root and vscode user that setup and install various programs.
52+
We have 3 types of dev container. These are defined under src
3453

35-
The dev container is built using https://github.com/devcontainers/cli
54+
`base` - this is the base image that all others are based on.
55+
`languages` - this installs specific versions of node and python.
56+
`projects` - this is used for projects where more customization is needed than just a base language image
3657

37-
## common files
38-
There are some common files under src/common. These include
39-
- a Dockerfile used to build specific containers that installs poetry after python has been installed
40-
- a .trivyignore file that contains trivy suppressions in the base image
58+
Each image to be built contains a .devcontainer folder that defines how the devcontainer should be built. At a minimum, this should contain a devcontainer.json file. See https://containers.dev/implementors/json_reference/ for options for this
4159

42-
## specific containers
43-
There are specific containers in src/<specific> - eg src/base/node_24_python_3_14
44-
These have a .devcontainer/devcontainer.json file used to built the image
45-
These use the base container as a base and then install specific versions of tools using devcontainer features, or a customised Dockerfile
46-
If there are specific vulnerabilities from these tools, then these should be added to the .trivyignore file in the folder
60+
Images under languages should point to a dockerfile under src/common that is based off the base image. This also runs `.devcontainer/scripts/root_install.sh` and `.devcontainer/scripts/vscode_install.sh` as vscode user as part of the build
4761

48-
# Build process
62+
We use trivy to scan for vulnerabilities in the built docker images. Known vulnerabilities in the base image are in `src/common/.trivyignore.yaml`. Vulnerabilities in specific images are in `.trivyignore.yaml` file in each images folder. These are combined before running a scan to exclude know vulnerabilities
63+
64+
# Pull requests and merge to main process
65+
For each pull request, and merge to main, images are built and scanned using trivy, but the images are not pushed to github container registry
4966
Docker images are built for each pull request, and on merges to main.
5067
Docker images are built for amd64 and arm64 architecture, and a combined manifest is created and pushed as part of the build.
5168

52-
The base image is built first, and then all other images are built
69+
The base image is built first, and then language images, and finally project images.
5370

5471
Docker images are scanned for vulnerabilities using trivy as part of a build step, and the build fails if vulnerabilities are found not in .trivyignore file.
5572

56-
For pull requests, an image is pushed with tag `pr-<pull-request-id>-<short commit sha>`
57-
On merges to main, a new release is created, and images are tagged with `latest` and the version of the release.
73+
74+
# Release workflow
75+
There is a release workflow that runs weekly at 18:00 on Thursday and on demand.
76+
This creates a new release tag, builds all images, and pushes them to github container registry.
77+
Images are tagged with the release tag, and also with latest
5878

5979
# Local testing
60-
For local testing, you can run this to build the base image
80+
## Building images
81+
You can use these commands to build images
82+
83+
Base image
6184
```
6285
CONTAINER_NAME=base \
6386
BASE_VERSION=latest \
6487
BASE_FOLDER=. \
6588
make build-image
6689
```
67-
or this to build a language image
90+
Language images
6891
```
6992
CONTAINER_NAME=node_24_python_3_12 \
7093
BASE_VERSION=latest \
7194
BASE_FOLDER=languages \
7295
make build-image
7396
```
74-
or this to build a project image
97+
Project images
7598
```
7699
CONTAINER_NAME=fhir_facade_api \
77100
BASE_VERSION=latest \
78101
BASE_FOLDER=projects \
79102
make build-image
80103
```
81104

82-
to build a local image, and then
105+
## Scanning images
106+
You can use these commands to scan images
107+
Base image
83108
```
84-
CONTAINER_NAME=base BASE_VERSION=latest make scan-image
109+
CONTAINER_NAME=base \
110+
BASE_FOLDER=. \
111+
make scan-image
85112
```
86-
to scan for vulnerabilities
87-
88-
# Using the images
89-
In each eps project, you can put this in the devcontainer Dockerfile. You should not need to add any features.
113+
Language images
90114
```
91-
FROM ghcr.io/nhsdigital/eps-devcontainers/node_24_python_3_13:<version>
92-
93-
USER root
94-
# specify DOCKER_GID to force container docker group id to match host
95-
RUN if [ -n "${DOCKER_GID}" ]; then \
96-
if ! getent group docker; then \
97-
groupadd -g ${DOCKER_GID} docker; \
98-
else \
99-
groupmod -g ${DOCKER_GID} docker; \
100-
fi && \
101-
usermod -aG docker vscode; \
102-
fi
103-
104-
USER vscode
115+
CONTAINER_NAME=node_24_python_3_12 \
116+
BASE_FOLDER=languages \
117+
make scan-image
118+
```
119+
Project images
105120
```
121+
CONTAINER_NAME=fhir_facade_api \
122+
BASE_FOLDER=projects \
123+
make scan-image
124+
```
106125

107-
# Generating a .trivyignore file
108-
You can generate a .trivyignore file for known vulnerabilities by either downloading the json scan output generated by the build, or by generating it locally using
126+
## Interactive shell on image
127+
You can use this to start an interactive shell on built images
128+
base image
129+
```
130+
CONTAINER_NAME=base \
131+
make shell-image
132+
```
133+
Language images
109134
```
110-
CONTAINER_NAME=base BASE_VERSION=latest make scan-image-json
135+
CONTAINER_NAME=node_24_python_3_12 \
136+
make shell-image
137+
```
138+
Project images
111139
```
140+
CONTAINER_NAME=fhir_facade_api \
141+
make shell-image
142+
```
143+
144+
145+
## Generating a .trivyignore file
146+
You can generate a .trivyignore file for known vulnerabilities by either downloading the json scan output generated by the build, or by generating it locally using the scanning images commands above with a make target of scan-image-json
147+
112148
If generated locally, then the output goes into .out/scan.out.json
113149

114-
Once you have this, use the following to generate a .trivyignore
150+
Once you have the scan output, use the following to generate a .trivyignore
115151
```
116-
poetry run python scripts/trivy_to_trivyignore.py --input .out/scan.out.json --output src/common/.trivyignore.yaml
152+
poetry run python \
153+
scripts/trivy_to_trivyignore.py \
154+
--input .out/scan.out.json \
155+
--output src/common/.trivyignore.yaml
117156
```

0 commit comments

Comments
 (0)