Skip to content

Commit a68181c

Browse files
authored
Chore: [AEA-0000] - various fixes (#20)
## Summary - Routine Change ### Details - fix cfn-guard makefile targets - fix trivy-scan-docker makefile targets - fix install of cfn-guard - remove containers from shell-image makefile target - update readme
1 parent 242823d commit a68181c

File tree

5 files changed

+41
-36
lines changed

5 files changed

+41
-36
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ scan-image-json: guard-CONTAINER_NAME guard-BASE_FOLDER guard-IMAGE_TAG
7272

7373
shell-image: guard-CONTAINER_NAME guard-IMAGE_TAG
7474
docker run -it \
75+
--rm \
7576
"${CONTAINER_PREFIX}$${CONTAINER_NAME}:$${IMAGE_TAG}" \
7677
bash
7778

README.md

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ asdf install and setup for these so they are available globally as vscode user
3131
Install and setup git-secrets
3232

3333
# Using the images
34-
In each eps project, this should be the contents of .devcontainer/Dockerfile.
35-
34+
## Project setup
35+
In each eps project, `.devcontainer/Dockerfile` should be set to
3636
```
3737
ARG IMAGE_NAME=node_24_python_3_14
3838
ARG IMAGE_VERSION=latest
@@ -49,11 +49,7 @@ RUN if [ -n "${DOCKER_GID}" ]; then \
4949
usermod -aG docker vscode; \
5050
fi
5151
```
52-
And this should be the contents of .devcontainer/devcontainer.json.
53-
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).
54-
The name should be changed to match the name of the project.
55-
IMAGE_NAME and IMAGE_VERSION should be changed as appropriate.
56-
You should not need to add any features as these are already baked into the image
52+
`.devcontainer/devcontainer.json` should be set to.
5753
```
5854
{
5955
"name": "eps-common-workflows",
@@ -86,7 +82,12 @@ You should not need to add any features as these are already baked into the imag
8682
}
8783
}
8884
```
85+
Note - 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).
86+
The name should be changed to match the name of the project.
87+
IMAGE_NAME and IMAGE_VERSION should be changed as appropriate.
88+
You should not need to add any features as these are already baked into the image
8989

90+
## Getting image name and version in github actions
9091
This job should be used in github actions wherever you need to get the dev container name or tag
9192

9293
```
@@ -106,6 +107,30 @@ This job should be used in github actions wherever you need to get the dev conta
106107
echo "DEVCONTAINER_IMAGE_NAME=$DEVCONTAINER_IMAGE_NAME" >> "$GITHUB_OUTPUT"
107108
echo "DEVCONTAINER_IMAGE_VERSION=$DEVCONTAINER_VERSION" >> "$GITHUB_OUTPUT"
108109
```
110+
## Using images in github actions
111+
To use the image in github actions, you can use code like this
112+
```
113+
jobs:
114+
my_job_name:
115+
runs-on: ubuntu-22.04
116+
container:
117+
image: ghcr.io/nhsdigital/eps-devcontainers/<container name>:githubactions-<tag>
118+
options: --user 1001:1001 --group-add 128
119+
defaults:
120+
run:
121+
shell: bash
122+
steps:
123+
- name: copy .tool-versions
124+
run: |
125+
cp /home/vscode/.tool-versions "$HOME/.tool-versions"
126+
... other steps ....
127+
```
128+
It is important that
129+
- the image specified uses the tag starting githubactions-
130+
- there is `options: --user 1001:1001 --group-add 128` below image to ensure it uses the correct user id and is added to the docker group
131+
- the default shell is set to be bash
132+
- the first step copies .tool-versions from /home/vscode to $HOME/.tool-versions
133+
109134
# Project structure
110135
We have 4 types of dev container. These are defined under src
111136

@@ -235,26 +260,6 @@ For an image built locally, you should put the IMAGE_VERSION=local-build.
235260
For an image built from a pull request, you should put the IMAGE_VERSION=<tag of image as show in pull request job>.
236261
You can only use images built from a pull request for testing changes in github actions.
237262

238-
## Using images in github actions
239-
To use the image in github actions, you can use it in github actions using code like this
240-
```
241-
jobs:
242-
my_job_name:
243-
runs-on: ubuntu-22.04
244-
container:
245-
image: ghcr.io/nhsdigital/eps-devcontainers/<container name>:githubactions-<tag>
246-
options: --user 1001:1001
247-
steps:
248-
- name: copy .tool-versions
249-
run: |
250-
cp /home/vscode/.tool-versions "$HOME/.tool-versions"
251-
... other steps ....
252-
```
253-
It is important that
254-
- the image uses the tag starting githubactions-
255-
- there is `options: --user 1001:1001` below image
256-
- the first step copies .tool-versions from /home/vscode to $HOME/.tool-versions
257-
258263
## Generating a .trivyignore file
259264
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
260265

src/base/.devcontainer/Mk/check.mk

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ cfn-guard-sam-templates:
3232
SAM_OUTPUT=$$(sam validate -t "$$file" --region eu-west-2 --debug 2>&1 | grep -Pazo "(?s)AWSTemplateFormatVersion.*\\n/" | tr -d "\\0"); \
3333
output_file=".cfn_guard_out/$${file}_$${ruleset}.txt"; \
3434
mkdir -p "$$(dirname "$$output_file")"; \
35-
echo "$${SAM_OUTPUT::-1}" | ~/.guard/bin/cfn-guard validate --rules "/usr/local/share/eps/cfnguard_rulesets/output/$$ruleset.guard" --show-summary fail > "$$output_file"; \
35+
echo "$${SAM_OUTPUT::-1}" | /home/vscode/.guard/bin/cfn-guard validate --rules "/usr/local/share/eps/cfnguard_rulesets/output/$$ruleset.guard" --show-summary fail > "$$output_file"; \
3636
done < <(find ./SAMtemplates -type f \( -name "*.yaml" -o -name "*.yml" \) -print0); \
3737
done\
3838
'
@@ -42,9 +42,9 @@ cfn-guard-cloudformation:
4242
rulesets=("ncsc" "ncsc-cafv3" "wa-Reliability-Pillar" "wa-Security-Pillar"); \
4343
mkdir -p .cfn_guard_out; \
4444
for ruleset in "$${rulesets[@]}"; do \
45-
~/.guard/bin/cfn-guard validate \
45+
/home/vscode/.guard/bin/cfn-guard validate \
4646
--data cloudformation \
47-
--rules "/tmp/ruleset/output/$$ruleset.guard" \
47+
--rules "/usr/local/share/eps/cfnguard_rulesets/output/$$ruleset.guard" \
4848
--show-summary fail \
4949
> ".cfn_guard_out/cloudformation_$$ruleset.txt"; \
5050
done\
@@ -55,9 +55,9 @@ cfn-guard-cdk:
5555
rulesets=("ncsc" "ncsc-cafv3" "wa-Reliability-Pillar" "wa-Security-Pillar"); \
5656
mkdir -p .cfn_guard_out; \
5757
for ruleset in "$${rulesets[@]}"; do \
58-
~/.guard/bin/cfn-guard validate \
58+
/home/vscode/.guard/bin/cfn-guard validate \
5959
--data cdk.out \
60-
--rules "/tmp/ruleset/output/$$ruleset.guard" \
60+
--rules "/usr/local/share/eps/cfnguard_rulesets/output/$$ruleset.guard" \
6161
--show-summary fail \
6262
> ".cfn_guard_out/cdk_$$ruleset.txt"; \
6363
done\
@@ -68,9 +68,9 @@ cfn-guard-terraform:
6868
rulesets=("ncsc" "ncsc-cafv3" "wa-Reliability-Pillar" "wa-Security-Pillar"); \
6969
mkdir -p .cfn_guard_out; \
7070
for ruleset in "$${rulesets[@]}"; do \
71-
~/.guard/bin/cfn-guard validate \
71+
/home/vscode/.guard/bin/cfn-guard validate \
7272
--data terraform_plans \
73-
--rules "/tmp/ruleset/output/$$ruleset.guard" \
73+
--rules "/usr/local/share/eps/cfnguard_rulesets/output/$$ruleset.guard" \
7474
--show-summary fail \
7575
> ".cfn_guard_out/terraform_$$ruleset.txt"; \
7676
done\

src/base/.devcontainer/Mk/trivy.mk

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ trivy-scan-docker: guard-DOCKER_IMAGE
8585
--scanners vuln \
8686
--severity HIGH,CRITICAL \
8787
--config trivy.yaml \
88-
--include-dev-deps \
8988
--exit-code 1 \
9089
--pkg-types os,library \
9190
--output .trivy_out/dependency_results_docker.txt \

src/base/.devcontainer/scripts/vscode_install.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ asdf plugin add trivy https://github.com/zufardhiyaulhaq/asdf-trivy.git
2222
asdf plugin add yq https://github.com/sudermanjr/asdf-yq.git
2323

2424
# install cfn-guard
25-
$ curl --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/aws-cloudformation/cloudformation-guard/main/install-guard.sh | sh
25+
curl --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/aws-cloudformation/cloudformation-guard/main/install-guard.sh | sh
2626

2727
# install base asdf versions of common tools
2828
cd /home/vscode

0 commit comments

Comments
 (0)