You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+88-49Lines changed: 88 additions & 49 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,9 +3,12 @@ EPS DEV CONTAINERS
3
3
4
4
# Introduction
5
5
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
9
12
- latest os packages
10
13
- asdf
11
14
- aws cli
@@ -24,94 +27,130 @@ asdf install and setup for these so they are available globally as vscode user
24
27
- ruby (for github pages)
25
28
- trivy
26
29
27
-
Install asdf plugins for all tools we use
28
30
Install and setup git-secrets
29
31
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
+
30
51
# 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
34
53
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
36
57
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
41
59
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
47
61
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
49
66
Docker images are built for each pull request, and on merges to main.
50
67
Docker images are built for amd64 and arm64 architecture, and a combined manifest is created and pushed as part of the build.
51
68
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.
53
70
54
71
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.
55
72
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
58
78
59
79
# 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
61
84
```
62
85
CONTAINER_NAME=base \
63
86
BASE_VERSION=latest \
64
87
BASE_FOLDER=. \
65
88
make build-image
66
89
```
67
-
or this to build a language image
90
+
Language images
68
91
```
69
92
CONTAINER_NAME=node_24_python_3_12 \
70
93
BASE_VERSION=latest \
71
94
BASE_FOLDER=languages \
72
95
make build-image
73
96
```
74
-
or this to build a project image
97
+
Project images
75
98
```
76
99
CONTAINER_NAME=fhir_facade_api \
77
100
BASE_VERSION=latest \
78
101
BASE_FOLDER=projects \
79
102
make build-image
80
103
```
81
104
82
-
to build a local image, and then
105
+
## Scanning images
106
+
You can use these commands to scan images
107
+
Base image
83
108
```
84
-
CONTAINER_NAME=base BASE_VERSION=latest make scan-image
109
+
CONTAINER_NAME=base \
110
+
BASE_FOLDER=. \
111
+
make scan-image
85
112
```
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
90
114
```
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
105
120
```
121
+
CONTAINER_NAME=fhir_facade_api \
122
+
BASE_FOLDER=projects \
123
+
make scan-image
124
+
```
106
125
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
109
134
```
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
111
139
```
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
+
112
148
If generated locally, then the output goes into .out/scan.out.json
113
149
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
115
151
```
116
-
poetry run python scripts/trivy_to_trivyignore.py --input .out/scan.out.json --output src/common/.trivyignore.yaml
0 commit comments