Skip to content

Commit 39472a3

Browse files
committed
Add devcontainer
Signed-off-by: Doru Blânzeanu <dblnz@pm.me>
1 parent 36dbf1a commit 39472a3

File tree

5 files changed

+179
-0
lines changed

5 files changed

+179
-0
lines changed

.devcontainer/Dockerfile

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
## Dockerfile for devcontainer
2+
3+
FROM mcr.microsoft.com/devcontainers/base:bookworm AS base
4+
5+
ARG USER=vscode
6+
ARG GROUP=vscode
7+
8+
ENV HOME="/home/${USER}"
9+
ENV PATH="$HOME/.cargo/bin:$PATH"
10+
11+
# Install dependencies
12+
RUN apt-get update \
13+
&& apt-get -y install \
14+
build-essential \
15+
cmake \
16+
curl \
17+
gdb \
18+
git \
19+
gnupg \
20+
lsb-release \
21+
make \
22+
pkg-config \
23+
software-properties-common \
24+
sudo \
25+
wget \
26+
musl-tools
27+
28+
ARG LLVM_VERSION=18
29+
30+
# Install llvm
31+
RUN wget https://apt.llvm.org/llvm.sh \
32+
&& chmod +x ./llvm.sh \
33+
&& sudo ./llvm.sh ${LLVM_VERSION} clang clang-tools-extra \
34+
&& sudo ln -s /usr/lib/llvm-${LLVM_VERSION}/bin/ld.lld /usr/bin/ld.lld \
35+
&& sudo ln -s /usr/lib/llvm-${LLVM_VERSION}/bin/clang /usr/bin/clang
36+
37+
# Install Node.js
38+
RUN curl -fsSL https://deb.nodesource.com/setup_22.x | bash - \
39+
&& apt-get install -y nodejs
40+
41+
FROM base AS dev
42+
43+
# Make sure the devcontainer user has sudo access
44+
RUN chown -R "${USER}:${GROUP}" /home/${USER} \
45+
&& echo "${USER} ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
46+
47+
# Persist bash history
48+
RUN SNIPPET="export PROMPT_COMMAND='history -a' && export HISTFILE=/commandhistory/.bash_history" \
49+
&& mkdir /commandhistory \
50+
&& touch /commandhistory/.bash_history \
51+
&& chown -R "${USER}" /commandhistory \
52+
&& echo "$SNIPPET" >> "/home/${USER}/.bashrc"
53+
54+
USER $USER
55+
56+
ARG RUST_TOOLCHAIN=1.89
57+
58+
# Install rust
59+
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y \
60+
&& rustup default ${RUST_TOOLCHAIN} \
61+
&& rustup target add x86_64-unknown-linux-gnu \
62+
&& rustup target add x86_64-unknown-linux-musl \
63+
&& rustup target add x86_64-unknown-none \
64+
&& rustup target add wasm32-wasip1 \
65+
&& rustup toolchain add nightly-x86_64-unknown-linux-gnu \
66+
&& cargo install just \
67+
&& cargo install cargo-component \
68+
&& cargo install cargo-hyperlight \
69+
&& cargo install hyperlight-wasm-aot --locked --version 0.12.0 \
70+
&& cargo install wasmtime-cli --locked --version 36.0.6

.devcontainer/devcontainer.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"name": "Hyperlight Wasm HTTP Example",
3+
4+
"image": "ghcr.io/hyperlight-dev/hyperlight-wasm-http-example-devcontainer:latest",
5+
6+
"containerUser": "vscode",
7+
"containerEnv": {
8+
"DEVICE": "/dev/kvm",
9+
"REMOTE_USER": "vscode",
10+
"REMOTE_GROUP": "vscode"
11+
},
12+
13+
"runArgs": [
14+
"--device=/dev/kvm"
15+
],
16+
17+
"postStartCommand": "bash .devcontainer/setup.sh",
18+
19+
"customizations": {
20+
"vscode": {
21+
"extensions": [
22+
"rust-lang.rust-analyzer",
23+
"vadimcn.vscode-lldb",
24+
"dbaeumer.vscode-eslint",
25+
"bytecodealliance.starlingmonkey-debugger"
26+
],
27+
"settings": {
28+
"rust-analyzer.rustfmt.extraArgs": [
29+
"+nightly"
30+
]
31+
}
32+
}
33+
}
34+
}

.devcontainer/setup.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
3+
# Change device ownership
4+
sudo chown -R $REMOTE_USER:$REMOTE_GROUP $DEVICE
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: Create and publish devcontainer Docker image
2+
3+
on:
4+
push:
5+
branches:
6+
- "main"
7+
paths:
8+
- ".devcontainer/Dockerfile"
9+
- ".github/workflows/CreateDevcontainerImage.yml"
10+
- "rust-toolchain.toml"
11+
12+
env:
13+
REGISTRY: ghcr.io
14+
IMAGE_NAME: ${{ github.repository }}-devcontainer
15+
USER: vscode
16+
GROUP: vscode
17+
LLVM_VERSION: 18
18+
RUST_TOOLCHAIN_DEFAULT: 1.89
19+
RUST_TOOLCHAIN_FILE: rust-toolchain.toml
20+
21+
jobs:
22+
build-and-push-image:
23+
runs-on: ubuntu-latest
24+
permissions:
25+
contents: read
26+
packages: write
27+
28+
steps:
29+
- name: Checkout repository
30+
uses: actions/checkout@v6
31+
32+
- name: Read Rust toolchain version from ${{ env.RUST_TOOLCHAIN_FILE }}
33+
id: toolchain
34+
run: |
35+
version=$(cat ${{ env.RUST_TOOLCHAIN_FILE }} | sed -n '/\[toolchain\]/,/^\[/{/^\s*channel = /s/[^"]*"\([^"]*\)".*/\1/p}')
36+
cat ${{ env.RUST_TOOLCHAIN_FILE }} | grep $version &> /dev/null \
37+
&& echo "RUST_TOOLCHAIN=${version}" >> "$GITHUB_OUTPUT" \
38+
|| echo "RUST_TOOLCHAIN=${{ env.RUST_TOOLCHAIN_DEFAULT }}" >> "$GITHUB_OUTPUT"
39+
40+
- name: Log in to the Container registry
41+
uses: docker/login-action@v4
42+
with:
43+
registry: ${{ env.REGISTRY }}
44+
username: ${{ github.actor }}
45+
password: ${{ secrets.GITHUB_TOKEN }}
46+
47+
- name: Extract metadata (tags, labels) for Docker
48+
id: meta
49+
uses: docker/metadata-action@v6
50+
with:
51+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
52+
53+
- name: Build and push Docker image
54+
id: push
55+
uses: docker/build-push-action@v7
56+
with:
57+
context: ./.devcontainer
58+
push: true
59+
tags: |
60+
${{ steps.meta.outputs.tags }}
61+
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
62+
labels: ${{ steps.meta.outputs.labels }}
63+
build-args: |
64+
USER=${{ env.USER }}
65+
GROUP=${{ env.GROUP }}
66+
LLVM_VERSION=${{ env.LLVM_VERSION }}
67+
RUST_TOOLCHAIN=${{ steps.toolchain.outputs.RUST_TOOLCHAIN }}

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,7 @@ JS:
101101
```sh
102102
cargo run -- out/sample_wasi_http_js.aot
103103
```
104+
105+
## Try it yourself!
106+
107+
[GitHub codespaces](https://codespaces.new/hyperlight-dev/hyperlight-wasm-http-example)

0 commit comments

Comments
 (0)