Skip to content

Commit cd50f5f

Browse files
authored
Chore: [AEA-0000] - move to devcontainer (#415)
## Summary - Routine Change ### Details - move to common devcontainer
1 parent 762e070 commit cd50f5f

14 files changed

Lines changed: 137 additions & 380 deletions

.devcontainer/Dockerfile

Lines changed: 11 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -1,95 +1,15 @@
1-
FROM mcr.microsoft.com/devcontainers/base:ubuntu
2-
3-
# provide DOCKER_GID via build args if you need to force group id to match host
4-
ARG DOCKER_GID
5-
ARG TARGETARCH
6-
ENV TARGETARCH=${TARGETARCH}
7-
8-
ARG ASDF_VERSION
9-
COPY .tool-versions.asdf /tmp/.tool-versions.asdf
10-
11-
RUN if [ "$TARGETARCH" = "arm64" ] || [ "$TARGETARCH" = "aarch64" ]; then dpkg --add-architecture arm64; fi
12-
13-
# Anticipate and resolve potential permission issues with apt
14-
RUN mkdir -p /tmp && chmod 1777 /tmp
15-
# Install system dependencies
16-
RUN apt-get update \
17-
&& export DEBIAN_FRONTEND=noninteractive \
18-
&& apt-get -y dist-upgrade \
19-
&& apt-get -y install --no-install-recommends htop vim curl git build-essential \
20-
libffi-dev libssl-dev libxml2-dev libxslt1-dev libjpeg8-dev libbz2-dev \
21-
zlib1g-dev unixodbc unixodbc-dev libsecret-1-0 libsecret-1-dev libsqlite3-dev \
22-
jq apt-transport-https ca-certificates gnupg-agent \
23-
software-properties-common bash-completion python3-pip make \
24-
libreadline-dev libsqlite3-dev wget llvm libncurses5-dev libncursesw5-dev \
25-
xz-utils tk-dev liblzma-dev netcat-traditional libyaml-dev
26-
27-
# Install aws stuff
28-
RUN if [ "$TARGETARCH" = "arm64" ] || [ "$TARGETARCH" = "aarch64" ]; then \
29-
wget -O /tmp/awscliv2.zip "https://awscli.amazonaws.com/awscli-exe-linux-aarch64.zip"; \
30-
else \
31-
wget -O /tmp/awscliv2.zip "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip"; \
32-
fi && \
33-
unzip /tmp/awscliv2.zip -d /tmp/aws-cli && \
34-
/tmp/aws-cli/aws/install && \
35-
rm /tmp/awscliv2.zip && rm -rf /tmp/aws-cli
36-
37-
RUN if [ "$TARGETARCH" = "arm64" ] || [ "$TARGETARCH" = "aarch64" ]; then \
38-
wget -O /tmp/aws-sam-cli.zip "https://github.com/aws/aws-sam-cli/releases/latest/download/aws-sam-cli-linux-arm64.zip"; \
39-
else \
40-
wget -O /tmp/aws-sam-cli.zip "https://github.com/aws/aws-sam-cli/releases/latest/download/aws-sam-cli-linux-x86_64.zip"; \
41-
fi && \
42-
unzip /tmp/aws-sam-cli.zip -d /tmp/aws-sam-cli && \
43-
/tmp/aws-sam-cli/install && \
44-
rm /tmp/aws-sam-cli.zip && rm -rf /tmp/aws-sam-cli
45-
46-
# Install ASDF
47-
RUN ASDF_VERSION=$(awk '!/^#/ && NF {print $1; exit}' /tmp/.tool-versions.asdf) && \
48-
if [ "$TARGETARCH" = "arm64" ] || [ "$TARGETARCH" == "aarch64" ]; then \
49-
wget -O /tmp/asdf.tar.gz "https://github.com/asdf-vm/asdf/releases/download/v${ASDF_VERSION}/asdf-v${ASDF_VERSION}-linux-arm64.tar.gz"; \
50-
else \
51-
wget -O /tmp/asdf.tar.gz "https://github.com/asdf-vm/asdf/releases/download/v${ASDF_VERSION}/asdf-v${ASDF_VERSION}-linux-amd64.tar.gz"; \
52-
fi && \
53-
tar -xzf /tmp/asdf.tar.gz -C /tmp && \
54-
mkdir -p /usr/bin && \
55-
mv /tmp/asdf /usr/bin/asdf && \
56-
chmod +x /usr/bin/asdf && \
57-
rm -rf /tmp/asdf.tar.gz
1+
ARG IMAGE_NAME=node_24_python_3_14
2+
ARG IMAGE_VERSION=latest
3+
FROM ghcr.io/nhsdigital/eps-devcontainers/${IMAGE_NAME}:${IMAGE_VERSION}
584

5+
USER root
596
# specify DOCKER_GID to force container docker group id to match host
607
RUN if [ -n "${DOCKER_GID}" ]; then \
61-
if ! getent group docker; then \
62-
groupadd -g ${DOCKER_GID} docker; \
63-
else \
64-
groupmod -g ${DOCKER_GID} docker; \
65-
fi && \
66-
usermod -aG docker vscode; \
8+
if ! getent group docker; then \
9+
groupadd -g ${DOCKER_GID} docker; \
10+
else \
11+
groupmod -g ${DOCKER_GID} docker; \
12+
fi && \
13+
usermod -aG docker vscode; \
6714
fi
68-
69-
USER vscode
70-
71-
ENV PATH="/home/vscode/.asdf/shims/:$PATH"
72-
RUN \
73-
echo 'PATH="/home/vscode/.asdf/shims/:$PATH"' >> ~/.bashrc; \
74-
echo '# Install Ruby Gems to ~/gems' >> ~/.bashrc; \
75-
echo 'export GEM_HOME="$HOME/gems"' >> ~/.bashrc; \
76-
echo 'export PATH="$HOME/gems/bin:$PATH"' >> ~/.bashrc;
77-
78-
ENV PATH="$PATH:/workspaces/eps-assist-me/node_modules/.bin"
79-
80-
# Install ASDF plugins
81-
RUN asdf plugin add python && \
82-
asdf plugin add poetry https://github.com/asdf-community/asdf-poetry.git && \
83-
asdf plugin add nodejs https://github.com/asdf-vm/asdf-nodejs.git && \
84-
asdf plugin add shellcheck https://github.com/luizm/asdf-shellcheck.git && \
85-
asdf plugin add direnv && \
86-
asdf plugin add actionlint && \
87-
asdf plugin add ruby https://github.com/asdf-vm/asdf-ruby.git
88-
89-
WORKDIR /workspaces/eps-assist-me
90-
ADD .tool-versions /workspaces/eps-assist-me/.tool-versions
91-
ADD .tool-versions /home/vscode/.tool-versions
92-
93-
# install python before poetry to ensure correct python version is used
94-
RUN asdf install python && \
95-
asdf install
15+

.devcontainer/devcontainer.json

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
2-
// README at: https://github.com/devcontainers/templates/tree/main/src/ubuntu
31
{
42
"name": "Ubuntu",
53
"build": {
64
"dockerfile": "Dockerfile",
75
"context": "..",
86
"args": {
9-
"DOCKER_GID": "${env:DOCKER_GID:}"
7+
"DOCKER_GID": "${env:DOCKER_GID:}",
8+
"IMAGE_NAME": "node_24_python_3_14",
9+
"IMAGE_VERSION": "v1.0.7",
10+
"USER_UID": "${localEnv:USER_ID:}",
11+
"USER_GID": "${localEnv:GROUP_ID:}"
1012
}
1113
},
1214
"mounts": [
@@ -16,14 +18,11 @@
1618
"source=${env:HOME}${env:USERPROFILE}/.npmrc,target=/home/vscode/.npmrc,type=bind",
1719
"source=${env:HOME}${env:USERPROFILE}/.gitconfig,target=/home/vscode/.gitconfig,type=bind"
1820
],
19-
"features": {
20-
"ghcr.io/devcontainers/features/docker-outside-of-docker:1": {
21-
"version": "latest",
22-
"moby": "true",
23-
"installDockerBuildx": "true"
24-
}
21+
"postAttachCommand": "git-secrets --register-aws; git-secrets --add-provider -- cat /usr/share/secrets-scanner/nhsd-rules-deny.txt",
22+
"features": {},
23+
"remoteEnv": {
24+
"LOCAL_WORKSPACE_FOLDER": "${localWorkspaceFolder}/"
2525
},
26-
"remoteEnv": { "LOCAL_WORKSPACE_FOLDER": "${localWorkspaceFolder}/" },
2726
"customizations": {
2827
"vscode": {
2928
"extensions": [
@@ -55,31 +54,28 @@
5554
"python.testing.pytestEnabled": false,
5655
"python.linting.pylintEnabled": false,
5756
"python.linting.flake8Enabled": true,
58-
"python.linting.enabled": true, // required to format on save
57+
"python.linting.enabled": true,
5958
"python.formatting.provider": "black",
60-
"black-formatter.args": ["--line-length=120"],
59+
"black-formatter.args": [
60+
"--line-length=120"
61+
],
6162
"[python]": {
6263
"editor.defaultFormatter": "ms-python.black-formatter"
6364
},
6465
"editor.defaultFormatter": "dbaeumer.vscode-eslint",
65-
"editor.formatOnPaste": false, // required
66-
"editor.formatOnType": false, // required
67-
"editor.formatOnSave": true, // optional
66+
"editor.formatOnPaste": false,
67+
"editor.formatOnType": false,
68+
"editor.formatOnSave": true,
6869
"editor.formatOnSaveMode": "file",
69-
"cSpell.words": ["fhir", "Formik", "pino", "serialisation"],
70+
"cSpell.words": [
71+
"fhir",
72+
"Formik",
73+
"pino",
74+
"serialisation"
75+
],
7076
"eslint.useFlatConfig": true,
7177
"eslint.format.enable": true
7278
}
7379
}
74-
},
75-
"postCreateCommand": "rm -f ~/.docker/config.json; git config --global --add safe.directory /workspaces/eps-assist-me; make install; direnv allow ."
76-
// "features": {},
77-
// Use 'forwardPorts' to make a list of ports inside the container available locally.
78-
// "forwardPorts": [],
79-
// Use 'postCreateCommand' to run commands after the container is created.
80-
// "postCreateCommand": ""
81-
// Configure tool-specific properties.
82-
// "customizations": {},
83-
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
84-
// "remoteUser": "root"
80+
}
8581
}

.github/workflows/cdk_package_code.yml

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,46 +12,32 @@ on:
1212
COMMIT_ID:
1313
required: true
1414
type: string
15+
pinned_image:
16+
type: string
17+
required: true
1518

1619
jobs:
1720
package_code:
1821
runs-on: ubuntu-22.04
22+
container:
23+
image: ${{ inputs.pinned_image }}
24+
options: --user 1001:1001 --group-add 128
25+
defaults:
26+
run:
27+
shell: bash
1928
permissions:
2029
id-token: write
2130
contents: read
2231
packages: read
2332
steps:
33+
- name: copy .tool-versions
34+
run: |
35+
cp /home/vscode/.tool-versions "$HOME/.tool-versions"
2436
- name: Checkout code
2537
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
2638
with:
2739
ref: ${{ env.BRANCH_NAME }}
2840

29-
- name: Get asdf version
30-
id: asdf-version
31-
run: echo "version=$(awk '!/^#/ && NF {print $1; exit}' .tool-versions.asdf)" >> "$GITHUB_OUTPUT"
32-
33-
# using git commit sha for version of action to ensure we have stable version
34-
- name: Install asdf
35-
uses: asdf-vm/actions/setup@b7bcd026f18772e44fe1026d729e1611cc435d47
36-
with:
37-
asdf_version: ${{ steps.asdf-version.outputs.version }}
38-
39-
- name: Cache asdf
40-
uses: actions/cache@cdf6c1fa76f9f475f3d7449005a359c84ca0f306
41-
with:
42-
path: |
43-
~/.asdf
44-
key: ${{ runner.os }}-asdf-${{ hashFiles('**/.tool-versions') }}-${{ steps.asdf-version.outputs.version }}
45-
restore-keys: |
46-
${{ runner.os }}-asdf-${{ hashFiles('**/.tool-versions') }}-${{ steps.asdf-version.outputs.version }}
47-
48-
- name: Install asdf dependencies in .tool-versions
49-
uses: asdf-vm/actions/install@b7bcd026f18772e44fe1026d729e1611cc435d47
50-
with:
51-
asdf_version: ${{ steps.asdf-version.outputs.version }}
52-
env:
53-
PYTHON_CONFIGURE_OPTS: --enable-shared
54-
5541
- name: Setting up .npmrc
5642
env:
5743
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@@ -114,7 +100,6 @@ jobs:
114100
- name: "Tar files"
115101
run: |
116102
tar -rf artifact.tar \
117-
.tool-versions \
118103
packages \
119104
node_modules \
120105
package.json \

.github/workflows/ci.yml

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,55 +8,43 @@ env:
88
BRANCH_NAME: ${{ github.event.ref.BRANCH_NAME }}
99

1010
jobs:
11-
get_asdf_version:
12-
runs-on: ubuntu-22.04
13-
outputs:
14-
asdf_version: ${{ steps.asdf-version.outputs.version }}
15-
tag_format: ${{ steps.load-config.outputs.TAG_FORMAT }}
16-
steps:
17-
- name: Checkout code
18-
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
19-
20-
- name: Get asdf version
21-
id: asdf-version
22-
run: echo "version=$(awk '!/^#/ && NF {print $1; exit}' .tool-versions.asdf)" >> "$GITHUB_OUTPUT"
23-
24-
- name: Load config value
25-
id: load-config
26-
run: |
27-
TAG_FORMAT=$(yq '.TAG_FORMAT' .github/config/settings.yml)
28-
echo "TAG_FORMAT=$TAG_FORMAT" >> "$GITHUB_OUTPUT"
11+
get_config_values:
12+
uses: NHSDigital/eps-common-workflows/.github/workflows/get-repo-config.yml@8404cf6e3a61ac8de4d1644e175e288aa4965815
13+
with:
14+
verify_published_from_main_image: true
2915

3016
quality_checks:
31-
uses: NHSDigital/eps-common-workflows/.github/workflows/quality-checks.yml@d215f841eb18b803e339e4ed597ed1f30e086e17
32-
needs: [get_asdf_version]
17+
uses: NHSDigital/eps-common-workflows/.github/workflows/quality-checks-devcontainer.yml@8404cf6e3a61ac8de4d1644e175e288aa4965815
18+
needs: [get_config_values]
3319
with:
34-
asdfVersion: ${{ needs.get_asdf_version.outputs.asdf_version }}
20+
pinned_image: ${{ needs.get_config_values.outputs.pinned_image }}
3521
secrets:
3622
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
3723

3824
tag_release:
39-
needs: [quality_checks, get_asdf_version]
40-
uses: NHSDigital/eps-common-workflows/.github/workflows/tag-release.yml@997a1946c83bb2a9eda418847ed640738af949ff
25+
needs: [quality_checks, get_config_values]
26+
uses: NHSDigital/eps-common-workflows/.github/workflows/tag-release-devcontainer.yml@8404cf6e3a61ac8de4d1644e175e288aa4965815
4127
with:
4228
dry_run: true
43-
asdfVersion: ${{ needs.get_asdf_version.outputs.asdf_version }}
29+
pinned_image: ${{ needs.get_config_values.outputs.pinned_image }}
4430
branch_name: main
45-
tag_format: ${{ needs.get_asdf_version.outputs.tag_format }}
31+
tag_format: ${{ needs.get_config_values.outputs.tag_format }}
4632
secrets: inherit
4733

4834
package_code:
49-
needs: [tag_release]
35+
needs: [tag_release, get_config_values]
5036
uses: ./.github/workflows/cdk_package_code.yml
5137
with:
5238
STACK_NAME: epsam
5339
VERSION_NUMBER: ${{ needs.tag_release.outputs.version_tag }}
5440
COMMIT_ID: ${{ github.sha }}
41+
pinned_image: ${{ needs.get_config_values.outputs.pinned_image }}
5542

5643
release_dev:
57-
needs: [tag_release, package_code]
44+
needs: [tag_release, package_code, get_config_values]
5845
uses: ./.github/workflows/release_all_stacks.yml
5946
with:
47+
pinned_image: ${{ needs.get_config_values.outputs.pinned_image }}
6048
STACK_NAME: epsam
6149
TARGET_ENVIRONMENT: dev
6250
VERSION_NUMBER: ${{ needs.tag_release.outputs.version_tag }}
@@ -85,9 +73,10 @@ jobs:
8573
SLACK_SIGNING_SECRET: ${{ secrets.DEV_SLACK_SIGNING_SECRET }}
8674

8775
release_qa:
88-
needs: [tag_release, package_code, release_dev]
76+
needs: [tag_release, package_code, release_dev, get_config_values]
8977
uses: ./.github/workflows/release_all_stacks.yml
9078
with:
79+
pinned_image: ${{ needs.get_config_values.outputs.pinned_image }}
9180
STACK_NAME: epsam
9281
TARGET_ENVIRONMENT: qa
9382
VERSION_NUMBER: ${{ needs.tag_release.outputs.version_tag }}

0 commit comments

Comments
 (0)