Skip to content

Commit 92d42df

Browse files
committed
update readme
1 parent 423fa2f commit 92d42df

2 files changed

Lines changed: 83 additions & 15 deletions

File tree

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ scan-image: guard-CONTAINER_NAME guard-BASE_FOLDER
4242
--exit-code 1 \
4343
--format table "${CONTAINER_PREFIX}$${CONTAINER_NAME}:$${IMAGE_TAG}"
4444

45-
scan-image-json: guard-CONTAINER_NAME guard-BASE_FOLDER
45+
scan-image-json: guard-CONTAINER_NAME guard-BASE_FOLDER guard-IMAGE_TAG
4646
@combined="src/$${BASE_FOLDER}/$${CONTAINER_NAME}/.trivyignore_combined.yaml"; \
4747
common="src/common/.trivyignore.yaml"; \
4848
specific="src/$${BASE_FOLDER}/$${CONTAINER_NAME}/.trivyignore.yaml"; \
@@ -58,7 +58,7 @@ scan-image-json: guard-CONTAINER_NAME guard-BASE_FOLDER
5858
--format json \
5959
--output .out/scan_results_docker.json "${CONTAINER_PREFIX}$${CONTAINER_NAME}:$${IMAGE_TAG}"
6060

61-
shell-image: guard-CONTAINER_NAME
61+
shell-image: guard-CONTAINER_NAME guard-IMAGE_TAG
6262
docker run -it \
6363
"${CONTAINER_PREFIX}$${CONTAINER_NAME}:$${IMAGE_TAG}" \
6464
bash

README.md

Lines changed: 81 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ Images are built using using https://github.com/devcontainers/cli.
88

99
We build a base image based on mcr.microsoft.com/devcontainers/base:ubuntu-22.04 that other images are then based on
1010

11+
The images have vsocde user setup as user 1001 so that they can be used in github actions
12+
1113
The base image contains
1214
- latest os packages
1315
- asdf
@@ -31,24 +33,80 @@ asdf install and setup for these so they are available globally as vscode user
3133
Install and setup git-secrets
3234

3335
# Using the images
34-
In each eps project, you can put this in the devcontainer Dockerfile. You should not need to add any features.
36+
In each eps project, this should be the contents of .devcontainer/Dockerfile.
37+
3538
```
36-
FROM ghcr.io/nhsdigital/eps-devcontainers/node_24_python_3_13:<version>
39+
ARG IMAGE_NAME=node_24_python_3_14
40+
ARG IMAGE_VERSION=latest
41+
FROM ghcr.io/nhsdigital/eps-devcontainers/${IMAGE_NAME}:${IMAGE_VERSION}
3742
3843
USER root
3944
# specify DOCKER_GID to force container docker group id to match host
4045
RUN if [ -n "${DOCKER_GID}" ]; then \
41-
if ! getent group docker; then \
42-
groupadd -g ${DOCKER_GID} docker; \
43-
else \
44-
groupmod -g ${DOCKER_GID} docker; \
45-
fi && \
46-
usermod -aG docker vscode; \
46+
if ! getent group docker; then \
47+
groupadd -g ${DOCKER_GID} docker; \
48+
else \
49+
groupmod -g ${DOCKER_GID} docker; \
50+
fi && \
51+
usermod -aG docker vscode; \
4752
fi
48-
49-
USER vscode
5053
```
54+
And this should be the contents of .devcontainer/devcontainer.json.
55+
This file will be used in github workflows to calculate the version of container to use in builds, so it must be valid JSON (no comments).
56+
The name should be changed to match the name of the project.
57+
IMAGE_NAME and IMAGE_VERSION should be changed as appropriate.
58+
You should not need to add any features as these are already baked into the image
59+
```
60+
{
61+
"name": "eps-common-workflows",
62+
"build": {
63+
"dockerfile": "Dockerfile",
64+
"args": {
65+
"DOCKER_GID": "${env:DOCKER_GID:}",
66+
"IMAGE_NAME": "node_24_python_3_14",
67+
"IMAGE_VERSION": "v1.0.1",
68+
"USER_UID": "${localEnv:USER_ID:}",
69+
"USER_GID": "${localEnv:GROUP_ID:}"
70+
},
71+
"updateRemoteUserUID": false,
72+
"postAttachCommand": "git-secrets --register-aws; git-secrets --add-provider -- cat /usr/share/secrets-scanner/nhsd-rules-deny.txt",
73+
"mounts": [
74+
"source=${env:HOME}${env:USERPROFILE}/.aws,target=/home/vscode/.aws,type=bind",
75+
"source=${env:HOME}${env:USERPROFILE}/.ssh,target=/home/vscode/.ssh,type=bind",
76+
"source=${env:HOME}${env:USERPROFILE}/.gnupg,target=/home/vscode/.gnupg,type=bind",
77+
"source=${env:HOME}${env:USERPROFILE}/.npmrc,target=/home/vscode/.npmrc,type=bind"
78+
],
79+
"containerUser": "vscode",
80+
"remoteEnv": {
81+
"LOCAL_WORKSPACE_FOLDER": "${localWorkspaceFolder}"
82+
},
83+
"features": {},
84+
"customizations": {
85+
... add any customisations you want here
86+
}
87+
}
88+
}
89+
```
90+
91+
This job should be used in github actions wherever you need to get the dev container name or tag
5192

93+
```
94+
get_config_values:
95+
runs-on: ubuntu-22.04
96+
outputs:
97+
devcontainer_image_name: ${{ steps.load-config.outputs.DEVCONTAINER_IMAGE_NAME }}
98+
devcontainer_image_version: ${{ steps.load-config.outputs.DEVCONTAINER_VERSION }}
99+
steps:
100+
- name: Checkout code
101+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
102+
- name: Load config value
103+
id: load-config
104+
run: |
105+
DEVCONTAINER_IMAGE_NAME=$(jq -r '.build.args.IMAGE_NAME' .devcontainer/devcontainer.json)
106+
DEVCONTAINER_IMAGE_VERSION=$(jq -r '.build.args.IMAGE_VERSION' .devcontainer/devcontainer.json)
107+
echo "DEVCONTAINER_IMAGE_NAME=$DEVCONTAINER_IMAGE_NAME" >> "$GITHUB_OUTPUT"
108+
echo "DEVCONTAINER_IMAGE_VERSION=$DEVCONTAINER_VERSION" >> "$GITHUB_OUTPUT"
109+
```
52110
# Project structure
53111
We have 3 types of dev container. These are defined under src
54112

@@ -58,9 +116,9 @@ We have 3 types of dev container. These are defined under src
58116

59117
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
60118

61-
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
119+
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. These files should be in the language specific folder.
62120

63-
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
121+
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 all known vulnerabilities
64122

65123
# Pull requests and merge to main process
66124
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
@@ -72,7 +130,9 @@ The base image is built first, and then language images, and finally project ima
72130
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.
73131

74132
For pull requests, images are tagged with the pr-<pull request id>-<short commit sha>.
75-
For merges to main, images are tagged with the <short commit sha>
133+
For merges to main, images are tagged with the <short commit sha>.
134+
135+
When a pull request is merged to main or closed, all associated images are deleted from the registry using the github workflow delete_old_images
76136

77137
# Release workflow
78138
There is a release workflow that runs weekly at 18:00 on Thursday and on demand.
@@ -114,18 +174,21 @@ Base image
114174
```
115175
CONTAINER_NAME=base \
116176
BASE_FOLDER=. \
177+
IMAGE_TAG=local-build \
117178
make scan-image
118179
```
119180
Language images
120181
```
121182
CONTAINER_NAME=node_24_python_3_12 \
122183
BASE_FOLDER=languages \
184+
IMAGE_TAG=local-build \
123185
make scan-image
124186
```
125187
Project images
126188
```
127189
CONTAINER_NAME=fhir_facade_api \
128190
BASE_FOLDER=projects \
191+
IMAGE_TAG=local-build \
129192
make scan-image
130193
```
131194

@@ -134,19 +197,24 @@ You can use this to start an interactive shell on built images
134197
base image
135198
```
136199
CONTAINER_NAME=base \
200+
IMAGE_TAG=local-build \
137201
make shell-image
138202
```
139203
Language images
140204
```
141205
CONTAINER_NAME=node_24_python_3_12 \
206+
IMAGE_TAG=local-build \
142207
make shell-image
143208
```
144209
Project images
145210
```
146211
CONTAINER_NAME=fhir_facade_api \
212+
IMAGE_TAG=local-build \
147213
make shell-image
148214
```
149215

216+
## Using local or pull request images
217+
You can use local or pull request images by changing IMAGE_VERSION in devcontainer.json
150218

151219
## Generating a .trivyignore file
152220
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

0 commit comments

Comments
 (0)