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
## Summary
- Routine Change
### Details
- setup common Makefile targets
- create seperate image for github actions with user vscode mapped to
user id 1001
- add cfn-guard and cfn-lint to image
- reduce size of docker images by using zstd compression
docker tag "ghcr.io/nhsdigital/eps-devcontainers/${CONTAINER_NAME}:${DOCKER_TAG}-${ARCHITECTURE}" "ghcr.io/nhsdigital/eps-devcontainers/${CONTAINER_NAME}:latest-${ARCHITECTURE}"
docker tag "ghcr.io/nhsdigital/eps-devcontainers/${CONTAINER_NAME}:githubactions-${DOCKER_TAG}-${ARCHITECTURE}" "ghcr.io/nhsdigital/eps-devcontainers/${CONTAINER_NAME}:githubactions-latest-${ARCHITECTURE}"
We have 3 types of dev container. These are defined under src
110
+
We have 4 types of dev container. These are defined under src
113
111
114
112
`base` - this is the base image that all others are based on.
115
113
`languages` - this installs specific versions of node and python.
116
-
`projects` - this is used for projects where more customization is needed than just a base language image
114
+
`projects` - this is used for projects where more customization is needed than just a base language image.
115
+
`githubactions` - this just takes an existing image and remaps vscode user to be 1001 so it can be used by github actions.
117
116
118
117
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
119
118
@@ -122,16 +121,20 @@ Images under languages should point to a dockerfile under src/common that is bas
122
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
123
122
124
123
# Pull requests and merge to main process
125
-
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
126
-
Docker images are built for each pull request, and on merges to main.
127
-
Docker images are built for amd64 and arm64 architecture, and a combined manifest is created and pushed as part of the build.
124
+
For each pull request, and merge to main, images are built and scanned using trivy, and pushed to github docker registry.
125
+
Docker images are built for amd64 and arm64 architecture, and a combined manifest is created and pushed as part of the build.
126
+
The main images have a vscode user with id 1000. A separately tagged image is also created with user vscode mapped to user id 1001 so they can be used by github actions.
128
127
129
128
The base image is built first, and then language images, and finally project images.
130
129
131
130
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.
132
131
133
-
For pull requests, images are tagged with the pr-<pullrequestid>-<shortcommitsha>.
134
-
For merges to main, images are tagged with the <shortcommitsha>.
132
+
For pull requests, images are tagged with the pr-{pull request id}-{short commit sha}.
133
+
For merges to main, images are tagged with the {short commit sha}.
134
+
Github actions images are tagged with githubactions-{tag}
135
+
Amd64 images are tagged with {tag}-amd64
136
+
Arm64 images are tagged with {tag}-arm64
137
+
Combined image manifest image is just tagged with {tag} so can be included in devcontainer.json and the correct image is pulled based on the host architecture.
135
138
136
139
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
- there is `options: --user 1001:1001` below image
256
+
- the first step copies .tool-versions from /home/vscode to $HOME/.tool-versions
257
+
223
258
## Generating a .trivyignore file
224
259
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
There are a set of common Makefiles that are defined in `src/base/.devcontainer/Mk` and are included from `common.mk`. These are installed to /usr/local/share/eps/Mk on the base image so are available for all containers.
279
+
280
+
This should be added to the end of each projects Makefile to include them
281
+
```
282
+
%:
283
+
@$(MAKE) -f /usr/local/share/eps/Mk/common.mk $@
284
+
```
285
+
### Targets
286
+
The following targets are defined. These are needed for quality checks to run. Some targets are project specific and so should be overridden in the projects Makefile.
287
+
288
+
Build targets (`build.mk`)
289
+
-`install` - placeholder target - should be overridden locally
290
+
-`install-node` - placeholder target - should be overridden locally
291
+
-`docker-build` - placeholder target - should be overridden locally
292
+
-`compile` - placeholder target - should be overridden locally
293
+
294
+
Check targets (`check.mk`)
295
+
-`lint` - placeholder target - should be overridden locally
296
+
-`test` - placeholder target - should be overridden locally
297
+
-`shellcheck` - runs shellcheck on `scripts/*.sh` and `.github/scripts/*.sh` when files exist
298
+
-`cfn-lint` - runs `cfn-lint` against `cloudformation/**/*.yml|yaml` and `SAMtemplates/**/*.yml|yaml`
299
+
-`cdk-synth` - placeholder target - should be overridden locally
300
+
-`cfn-guard-sam-templates` - validates SAM templates against cfn-guard rulesets and writes outputs to `.cfn_guard_out/`
301
+
-`cfn-guard-cloudformation` - validates `cloudformation` templates against cfn-guard rulesets and writes outputs to `.cfn_guard_out/`
302
+
-`cfn-guard-cdk` - validates `cdk.out` against cfn-guard rulesets and writes outputs to `.cfn_guard_out/`
303
+
-`cfn-guard-terraform` - validates `terraform_plans` against cfn-guard rulesets and writes outputs to `.cfn_guard_out/`
304
+
-`actionlint` - runs actionlint against github actions
305
+
-`secret-scan` - runs git-secrets (including scanning history) against the repo
306
+
-`guard-<ENVIRONMENT_VARIABLE>` - checks if an environment variable is set and errors if it is not
307
+
308
+
Credentials targets (`credentials.mk`)
309
+
-`aws-configure` - configures an AWS sso session
310
+
-`aws-login` - Authorizes an sso session with AWS so aws cli tools can be used. You may still need to set AWS_PROFILE before running commands
311
+
-`github-login` - Authorizes github cli to github with scope to read packages
312
+
-`create-npmrc` - depends on `github-login`, then writes `.npmrc` with a GitHub Packages auth token and `@nhsdigital` registry
313
+
314
+
Trivy targets (`trivy.mk`)
315
+
-`trivy-license-check` - runs Trivy license scan (HIGH/CRITICAL) and writes `.trivy_out/license_scan.txt`
316
+
-`trivy-generate-sbom` - generates CycloneDX SBOM at `.trivy_out/sbom.cdx.json`
317
+
-`trivy-scan-python` - scans Python dependencies (HIGH/CRITICAL) and writes `.trivy_out/dependency_results_python.txt`
318
+
-`trivy-scan-node` - scans Node dependencies (HIGH/CRITICAL) and writes `.trivy_out/dependency_results_node.txt`
319
+
-`trivy-scan-go` - scans Go dependencies (HIGH/CRITICAL) and writes `.trivy_out/dependency_results_go.txt`
320
+
-`trivy-scan-java` - scans Java dependencies (HIGH/CRITICAL) and writes `.trivy_out/dependency_results_java.txt`
321
+
-`trivy-scan-docker` - scans a built image (HIGH/CRITICAL) and writes `.trivy_out/dependency_results_docker.txt` (requires `DOCKER_IMAGE`), for example:
0 commit comments