Skip to content

Commit 3beb33a

Browse files
committed
Change device ownership inside the container
- This avoids creating a new group in a new container image - Also there is no need for the environment file to be dynamically generated Signed-off-by: Doru Blânzeanu <[email protected]>
1 parent db9a21c commit 3beb33a

File tree

7 files changed

+72
-86
lines changed

7 files changed

+72
-86
lines changed

.devcontainer/Dockerfile

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,59 @@
1-
FROM ghcr.io/hyperlight-dev/hyperlight-devcontainer:latest
1+
## Dockerfile for devcontainer
22

3-
COPY .env /tmp/.env
3+
FROM mcr.microsoft.com/devcontainers/base:debian AS base
44

5-
RUN . /tmp/.env && \
6-
sudo groupadd -r -g ${DEVICE_GID} -U ${USER} ${DEVICE_GROUP}
5+
ARG USER
6+
ARG GROUP
7+
ARG RUST_TOOLCHAIN
8+
9+
ENV HOME="/home/${USER}"
10+
ENV PATH="$HOME/.cargo/bin:$PATH"
11+
12+
# Install dependencies
13+
RUN apt-get update \
14+
&& apt-get -y install \
15+
build-essential \
16+
cmake \
17+
curl \
18+
git \
19+
gnupg \
20+
lsb-release \
21+
make \
22+
software-properties-common \
23+
sudo \
24+
wget
25+
26+
# Install llvm
27+
RUN wget https://apt.llvm.org/llvm.sh \
28+
&& chmod +x ./llvm.sh \
29+
&& sudo ./llvm.sh 17 all \
30+
&& sudo ln -s /usr/lib/llvm-17/bin/clang-cl /usr/bin/clang-cl \
31+
&& sudo ln -s /usr/lib/llvm-17/bin/llvm-lib /usr/bin/llvm-lib \
32+
&& sudo ln -s /usr/lib/llvm-17/bin/lld-link /usr/bin/lld-link \
33+
&& sudo ln -s /usr/lib/llvm-17/bin/llvm-ml /usr/bin/llvm-ml \
34+
&& sudo ln -s /usr/lib/llvm-17/bin/ld.lld /usr/bin/ld.lld \
35+
&& sudo ln -s /usr/lib/llvm-17/bin/clang /usr/bin/clang
36+
37+
FROM base AS dev
38+
39+
# Make sure the devcontainer user has sudo access
40+
RUN chown -R "${USER}:$GROUP" /home/${USER} \
41+
&& echo "${USER} ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
42+
43+
# Persist bash hystory
44+
RUN SNIPPET="export PROMPT_COMMAND='history -a' && export HISTFILE=/commandhistory/.bash_history" \
45+
&& mkdir /commandhistory \
46+
&& touch /commandhistory/.bash_history \
47+
&& chown -R $USER /commandhistory \
48+
&& echo "$SNIPPET" >> "/home/$USER/.bashrc"
49+
50+
USER $USER
51+
52+
# Install rust
53+
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y \
54+
&& rustup default $RUST_TOOLCHAIN \
55+
&& rustup target add x86_64-unknown-linux-gnu \
56+
&& rustup target add x86_64-unknown-none \
57+
&& rustup target add x86_64-pc-windows-msvc \
58+
&& cargo install just
759

.devcontainer/Dockerfile.base

Lines changed: 0 additions & 59 deletions
This file was deleted.

.devcontainer/create_env.sh

Lines changed: 0 additions & 12 deletions
This file was deleted.

.devcontainer/devcontainer.json

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,22 @@
33
{
44
"name": "Hyperlight",
55

6-
"build": {
7-
"dockerfile": "Dockerfile"
8-
},
6+
"image": "ghcr.io/dblnz/hyperlight-devcontainer:latest",
97

10-
"remoteUser": "vscode",
8+
"containerUser": "vscode",
9+
// Environment for the container also used by in the `postCreateCommand`
10+
"containerEnv": {
11+
"REMOTE_USER": "vscode",
12+
"REMOTE_GROUP": "vscode",
13+
"DEVICE": "/dev/kvm"
14+
},
1115

1216
"runArgs": [
13-
"--env-file", ".devcontainer/.env",
1417
"--device=/dev/kvm"
1518
],
1619

17-
// Use 'initializeCommand' to run commands before container image build
18-
"initializeCommand": "bash .devcontainer/create_env.sh",
20+
// Use 'postCreateCommand' to run commands after the container is created
21+
"postCreateCommand": "bash .devcontainer/setup.sh",
1922

2023
"customizations": {
2124
"vscode": {

.devcontainer/setup.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
3+
# Change device ownership
4+
sudo chown -R $REMOTE_USER:$REMOTE_GROUP ${DEVICE}
5+

.github/workflows/CreateDevcontainerImage.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Create and publish devcontainer Docker image
33
on:
44
push:
55
paths:
6-
- ".devcontainer/Dockerfile.base"
6+
- ".devcontainer/Dockerfile"
77
- ".github/workflows/CreateDevcontainerImage.yml"
88

99
# Defines two custom environment variables for the workflow. These are used for the Container registry domain, and a name for the Docker image that this workflow builds.

.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@
1616
# Mono auto generated files
1717
mono_crash.*
1818

19-
# Devcontainer generated files
20-
.devcontainer/.env
21-
2219
# Build results
2320
**/[Dd]ebug/*
2421
/[Dd]ebugPublic/

0 commit comments

Comments
 (0)