Skip to content

Commit b49fa7e

Browse files
authored
Chore: [AEA-0000] - devcontainer fail fast, posix equality, force docker gid (#2146)
## Summary **Remove items from this list if they are not relevant. Remove this line once this has been done** - Routine Change ### Details - fail fast on RUN steps (use && instead of ;) - posix-compliant equality (single = conditions) - permit injection of docker group id if needed
1 parent 71472e1 commit b49fa7e

File tree

2 files changed

+30
-13
lines changed

2 files changed

+30
-13
lines changed

.devcontainer/Dockerfile

Lines changed: 27 additions & 12 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,15 +69,15 @@ 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 java; \
62-
asdf plugin add direnv; \
63-
asdf plugin add golang https://github.com/kennyp/asdf-golang.git; \
64-
asdf plugin add golangci-lint https://github.com/hypnoglow/asdf-golangci-lint.git; \
65-
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 java && \
77+
asdf plugin add direnv && \
78+
asdf plugin add golang https://github.com/kennyp/asdf-golang.git && \
79+
asdf plugin add golangci-lint https://github.com/hypnoglow/asdf-golangci-lint.git && \
80+
asdf plugin add actionlint && \
6681
asdf plugin add ruby https://github.com/asdf-vm/asdf-ruby.git
6782

6883

@@ -71,5 +86,5 @@ ADD .tool-versions /workspaces/prescriptionsforpatients/.tool-versions
7186
ADD .tool-versions /home/vscode/.tool-versions
7287

7388
# install python before poetry to ensure correct python version is used
74-
RUN asdf install python; \
89+
RUN asdf install python && \
7590
asdf install

.devcontainer/devcontainer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
"build": {
44
"dockerfile": "Dockerfile",
55
"context": "..",
6-
"args": {}
6+
"args": {
7+
"DOCKER_GID": "${env:DOCKER_GID:}"
8+
}
79
},
810
"mounts": [
911
"source=${env:HOME}${env:USERPROFILE}/.aws,target=/home/vscode/.aws,type=bind",

0 commit comments

Comments
 (0)