Skip to content

Commit 409a3aa

Browse files
authored
Chore: [AEA-0000] - devcontainer fail fast, posix equality, force docker gid (#2361)
## Summary - Routine Change ### Details - fail fast on RUN steps (use && instead of ;) - posix-compliant equality (single = conditions) - permit injection of docker group id if needed to resolve error on starting the dev container: ``` Digital/eps-workflow-quality-checks/refs/tags/v4.0.4/dockerfiles/nhsd-git-secrets.dockerfile -t git-secrets . && poetry run pre-commit install --install-hooks -f ERROR: permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Head "http://%2Fvar%2Frun%2Fdocker.sock/_ping": dial unix /var/run/docker.sock: connect: permission denied [9902 ms] postAttachCommand from devcontainer.json failed with exit code 1. Skipping any further user-provided commands. ```
1 parent aa56d8a commit 409a3aa

File tree

2 files changed

+39
-22
lines changed

2 files changed

+39
-22
lines changed

.devcontainer/Dockerfile

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
FROM mcr.microsoft.com/devcontainers/base:ubuntu
22

3+
# provide DOCKER_GID via build args if you need to force group id to match host
4+
ARG DOCKER_GID
35
ARG TARGETARCH
46
ENV TARGETARCH=${TARGETARCH}
57

68
ARG ASDF_VERSION
79
COPY .tool-versions.asdf /tmp/.tool-versions.asdf
810

11+
# Anticipate and resolve potential permission issues with apt
12+
RUN mkdir -p /tmp && chmod 1777 /tmp
13+
914
RUN apt-get update \
1015
&& export DEBIAN_FRONTEND=noninteractive \
1116
&& apt-get -y dist-upgrade \
@@ -18,7 +23,7 @@ RUN apt-get update \
1823
xz-utils tk-dev liblzma-dev netcat-traditional libyaml-dev
1924

2025
# Download correct AWS CLI for arch
21-
RUN if [ "$TARGETARCH" = "arm64" ] || [ "$TARGETARCH" == "aarch64" ]; then \
26+
RUN if [ "$TARGETARCH" = "arm64" ] || [ "$TARGETARCH" = "aarch64" ]; then \
2227
wget -O /tmp/awscliv2.zip "https://awscli.amazonaws.com/awscli-exe-linux-aarch64.zip"; \
2328
else \
2429
wget -O /tmp/awscliv2.zip "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip"; \
@@ -28,7 +33,7 @@ RUN if [ "$TARGETARCH" = "arm64" ] || [ "$TARGETARCH" == "aarch64" ]; then \
2833
rm /tmp/awscliv2.zip && rm -rf /tmp/aws-cli
2934

3035
# Download correct SAM CLI for arch
31-
RUN if [ "$TARGETARCH" = "arm64" ] || [ "$TARGETARCH" == "aarch64" ]; then \
36+
RUN if [ "$TARGETARCH" = "arm64" ] || [ "$TARGETARCH" = "aarch64" ]; then \
3237
wget -O /tmp/aws-sam-cli.zip "https://github.com/aws/aws-sam-cli/releases/latest/download/aws-sam-cli-linux-arm64.zip"; \
3338
else \
3439
wget -O /tmp/aws-sam-cli.zip "https://github.com/aws/aws-sam-cli/releases/latest/download/aws-sam-cli-linux-x86_64.zip"; \
@@ -43,6 +48,16 @@ RUN ASDF_VERSION=$(awk '!/^#/ && NF {print $1; exit}' /tmp/.tool-versions.asdf)
4348
tar -xvzf /tmp/asdf.tar.gz; \
4449
mv asdf /usr/bin
4550

51+
# specify DOCKER_GID to force container docker group id to match host
52+
RUN if [ -n "${DOCKER_GID}" ]; then \
53+
if ! getent group docker; then \
54+
groupadd -g ${DOCKER_GID} docker; \
55+
else \
56+
groupmod -g ${DOCKER_GID} docker; \
57+
fi && \
58+
usermod -aG docker vscode; \
59+
fi
60+
4661
USER vscode
4762

4863
ENV PATH="/home/vscode/.asdf/shims/:$PATH"
@@ -54,19 +69,18 @@ RUN \
5469
echo 'export PATH="$HOME/gems/bin:$PATH"' >> ~/.bashrc;
5570

5671
# Install ASDF plugins
57-
RUN asdf plugin add python; \
58-
asdf plugin add poetry https://github.com/asdf-community/asdf-poetry.git; \
59-
asdf plugin add shellcheck https://github.com/luizm/asdf-shellcheck.git; \
60-
asdf plugin add nodejs https://github.com/asdf-vm/asdf-nodejs.git; \
61-
asdf plugin add direnv; \
62-
asdf plugin add actionlint; \
72+
RUN asdf plugin add python && \
73+
asdf plugin add poetry https://github.com/asdf-community/asdf-poetry.git && \
74+
asdf plugin add shellcheck https://github.com/luizm/asdf-shellcheck.git && \
75+
asdf plugin add nodejs https://github.com/asdf-vm/asdf-nodejs.git && \
76+
asdf plugin add direnv && \
77+
asdf plugin add actionlint && \
6378
asdf plugin add ruby https://github.com/asdf-vm/asdf-ruby.git
6479

65-
6680
WORKDIR /workspaces/eps-prescription-status-update-api
6781
ADD .tool-versions /workspaces/eps-prescription-status-update-api/.tool-versions
6882
ADD .tool-versions /home/vscode/.tool-versions
6983

7084
# install python before poetry to ensure correct python version is used
71-
RUN asdf install python; \
85+
RUN asdf install python && \
7286
asdf install

.devcontainer/devcontainer.json

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
"build": {
77
"dockerfile": "Dockerfile",
88
"context": "..",
9-
"args": {}
9+
"args": {
10+
"DOCKER_GID": "${env:DOCKER_GID:}"
11+
}
1012
},
1113
"mounts": [
1214
"source=${env:HOME}${env:USERPROFILE}/.aws,target=/home/vscode/.aws,type=bind",
@@ -37,7 +39,7 @@
3739
"github.vscode-github-actions"
3840
],
3941
"settings": {
40-
"python.defaultInterpreterPath": "/workspaces/eps-prescription-status-update/.venv/bin/python",
42+
"python.defaultInterpreterPath": "/workspaces/eps-prescription-status-update-api/.venv/bin/python",
4143
"python.analysis.autoSearchPaths": true,
4244
"python.analysis.extraPaths": [],
4345
"python.testing.unittestEnabled": false,
@@ -55,14 +57,15 @@
5557
}
5658
}
5759
},
58-
"remoteEnv": { "LOCAL_WORKSPACE_FOLDER": "${localWorkspaceFolder}" },
59-
"postAttachCommand": "docker build -f https://raw.githubusercontent.com/NHSDigital/eps-workflow-quality-checks/refs/tags/v4.0.4/dockerfiles/nhsd-git-secrets.dockerfile -t git-secrets . && poetry run pre-commit install --install-hooks -f",
60-
"features": {
61-
"ghcr.io/devcontainers/features/docker-outside-of-docker:1": {
62-
"version": "latest",
63-
"moby": "true",
64-
"installDockerBuildx": "true"
65-
},
66-
"ghcr.io/devcontainers/features/github-cli:1": {}
67-
}
60+
"remoteEnv": { "LOCAL_WORKSPACE_FOLDER": "${localWorkspaceFolder}" },
61+
"updateRemoteUserUID": true,
62+
"postAttachCommand": "docker build -f https://raw.githubusercontent.com/NHSDigital/eps-workflow-quality-checks/refs/tags/v4.0.4/dockerfiles/nhsd-git-secrets.dockerfile -t git-secrets . && poetry run pre-commit install --install-hooks -f",
63+
"features": {
64+
"ghcr.io/devcontainers/features/docker-outside-of-docker:1": {
65+
"version": "latest",
66+
"moby": "true",
67+
"installDockerBuildx": "true"
68+
},
69+
"ghcr.io/devcontainers/features/github-cli:1": {}
70+
}
6871
}

0 commit comments

Comments
 (0)