Skip to content

Commit d5f885d

Browse files
committed
ci: rework devcontainer
1 parent 5131277 commit d5f885d

File tree

7 files changed

+702
-157
lines changed

7 files changed

+702
-157
lines changed

.devcontainer/Dockerfile

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# See here for image contents: https://hub.docker.com/layers/library/rust/1.81.0-slim/images/sha256-ba4ee661bb466ab49f6ceb8c6d9e9f9784bba7c6e45225187cd3c7fb1fbc12ce
2+
3+
ARG RUST_VERSION=1.85.0
4+
FROM rust:${RUST_VERSION}-slim
5+
ARG RUST_VERSION
6+
7+
# Install additional packages
8+
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
9+
&& apt-get -y install --no-install-recommends protobuf-compiler libprotobuf-dev libclang-dev libzstd-dev make pkg-config libssl-dev
10+
11+
RUN apt-get install -y gh libgmp3-dev software-properties-common curl git unzip
12+
13+
# To allow independent workflow of the container, the rust-toolchain is explicitely given.
14+
RUN echo ${RUST_VERSION} > rust_toolchain_version
15+
# Make sure to sync the nightly version with the scripts in ./scripts
16+
RUN echo "nightly-2024-08-28" > nightly_rust_toolchain_version
17+
18+
# Install cargo-binstall
19+
RUN curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash
20+
21+
RUN rustup toolchain install $(cat rust_toolchain_version) && \
22+
rustup default $(cat rust_toolchain_version) && \
23+
rustup component add clippy && \
24+
rustup component add rustfmt
25+
26+
RUN rustup toolchain install $(cat nightly_rust_toolchain_version) && \
27+
rustup component add rustfmt clippy --toolchain $(cat nightly_rust_toolchain_version)
28+
29+
RUN rustup target add x86_64-pc-windows-msvc && \
30+
rustup target add wasm32-unknown-unknown
31+
32+
RUN cargo binstall cargo-get cargo-nextest cargo-llvm-cov cargo-release --secure -y
33+
34+
# Platform specific tooling
35+
ARG TARGETPLATFORM
36+
RUN if [ "$TARGETPLATFORM" = "linux/arm64" ] ; then \
37+
curl -L https://github.com/Orange-OpenSource/hurl/releases/download/4.1.0/hurl-4.1.0-aarch64-unknown-linux-gnu.tar.gz -o hurl.tar.gz && \
38+
tar -xzf hurl.tar.gz && \
39+
mv hurl-4.1.0-aarch64-unknown-linux-gnu/hurl /usr/local/bin/ && \
40+
rm -r hurl-4.1.0-aarch64-unknown-linux-gnu && \
41+
rm hurl.tar.gz && \
42+
rustup component add llvm-tools-preview --toolchain $(cat rust_toolchain_version)-aarch64-unknown-linux-gnu; \
43+
curl -L https://go.dev/dl/go1.24.2.linux-arm64.tar.gz -o go.tar.gz; \
44+
elif [ "$TARGETPLATFORM" = "linux/amd64" ] ; then \
45+
curl -L https://github.com/Orange-OpenSource/hurl/releases/download/4.1.0/hurl-4.1.0-x86_64-unknown-linux-gnu.tar.gz -o hurl.tar.gz && \
46+
tar -xzf hurl.tar.gz && \
47+
mv hurl-4.1.0-x86_64-unknown-linux-gnu/hurl /usr/local/bin/ && \
48+
rm -r hurl-4.1.0-x86_64-unknown-linux-gnu && \
49+
rm hurl.tar.gz && \
50+
rustup component add llvm-tools-preview --toolchain $(cat rust_toolchain_version)-x86_64-unknown-linux-gnu && \
51+
rustup target add x86_64-fortanix-unknown-sgx --toolchain $(cat nightly_rust_toolchain_version); \
52+
curl -L https://go.dev/dl/go1.24.2.linux-amd64.tar.gz -o go.tar.gz; \
53+
fi
54+
55+
RUN tar -C /usr/local -xzf go.tar.gz
56+
ENV PATH="${PATH}:/usr/local/go/bin"
57+
58+
RUN asdf install
59+
60+
RUN chown -R root:root /usr/local/cargo
61+
RUN chmod -R 700 /usr/local/cargo

.devcontainer/devcontainer.json

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
2+
// https://github.com/microsoft/vscode-dev-containers/tree/v0.245.2/containers/rust
3+
{
4+
"name": "Rust",
5+
"image": "ghcr.io/dojoengine/torii-dev:v1.5.0",
6+
"runArgs": [
7+
"--cap-add=SYS_PTRACE",
8+
"--security-opt",
9+
"seccomp=unconfined"
10+
],
11+
// Configure tool-specific properties.
12+
"customizations": {
13+
// Configure properties specific to VS Code.
14+
"vscode": {
15+
// Set *default* container specific settings.json values on container create.
16+
"settings": {
17+
"lldb.executable": "/usr/bin/lldb",
18+
// VS Code don't watch files under ./target
19+
"files.watcherExclude": {
20+
"**/target/**": true
21+
},
22+
"rust-analyzer.checkOnSave.command": "clippy"
23+
},
24+
// Add the IDs of extensions you want installed when the container is created.
25+
"extensions": [
26+
"vadimcn.vscode-lldb",
27+
"mutantdino.resourcemonitor",
28+
"rust-lang.rust-analyzer",
29+
"tamasfe.even-better-toml",
30+
"serayuzgur.crates",
31+
"starkware.cairo1"
32+
]
33+
}
34+
},
35+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
36+
// "forwardPorts": [],
37+
// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
38+
// "remoteUser": "vscode",
39+
"remoteEnv": {
40+
"PATH": "${containerEnv:PATH}:/workspace/torii/target/release"
41+
}
42+
}
Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
#!/bin/bash
2+
#-------------------------------------------------------------------------------------------------------------
3+
# Copyright (c) Microsoft Corporation. All rights reserved.
4+
# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information.
5+
#-------------------------------------------------------------------------------------------------------------
6+
#
7+
# Docs: https://github.com/microsoft/vscode-dev-containers/blob/main/script-library/docs/node.md
8+
# Maintainer: The VS Code and Codespaces Teams
9+
#
10+
# Syntax: ./node-debian.sh [directory to install nvm] [node version to install (use "none" to skip)] [non-root user] [Update rc files flag] [install node-gyp deps]
11+
12+
export NVM_DIR=${1:-"/usr/local/share/nvm"}
13+
export NODE_VERSION=${2:-"lts"}
14+
USERNAME=${3:-"automatic"}
15+
UPDATE_RC=${4:-"true"}
16+
INSTALL_TOOLS_FOR_NODE_GYP="${5:-true}"
17+
export NVM_VERSION="0.38.0"
18+
19+
set -e
20+
21+
if [ "$(id -u)" -ne 0 ]; then
22+
echo -e 'Script must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.'
23+
exit 1
24+
fi
25+
26+
# Ensure that login shells get the correct path if the user updated the PATH using ENV.
27+
rm -f /etc/profile.d/00-restore-env.sh
28+
echo "export PATH=${PATH//$(sh -lc 'echo $PATH')/\$PATH}" > /etc/profile.d/00-restore-env.sh
29+
chmod +x /etc/profile.d/00-restore-env.sh
30+
31+
# Determine the appropriate non-root user
32+
if [ "${USERNAME}" = "auto" ] || [ "${USERNAME}" = "automatic" ]; then
33+
USERNAME=""
34+
POSSIBLE_USERS=("vscode" "node" "codespace" "$(awk -v val=1000 -F ":" '$3==val{print $1}' /etc/passwd)")
35+
for CURRENT_USER in ${POSSIBLE_USERS[@]}; do
36+
if id -u ${CURRENT_USER} > /dev/null 2>&1; then
37+
USERNAME=${CURRENT_USER}
38+
break
39+
fi
40+
done
41+
if [ "${USERNAME}" = "" ]; then
42+
USERNAME=root
43+
fi
44+
elif [ "${USERNAME}" = "none" ] || ! id -u ${USERNAME} > /dev/null 2>&1; then
45+
USERNAME=root
46+
fi
47+
48+
updaterc() {
49+
if [ "${UPDATE_RC}" = "true" ]; then
50+
echo "Updating /etc/bash.bashrc and /etc/zsh/zshrc..."
51+
if [[ "$(cat /etc/bash.bashrc)" != *"$1"* ]]; then
52+
echo -e "$1" >> /etc/bash.bashrc
53+
fi
54+
if [ -f "/etc/zsh/zshrc" ] && [[ "$(cat /etc/zsh/zshrc)" != *"$1"* ]]; then
55+
echo -e "$1" >> /etc/zsh/zshrc
56+
fi
57+
fi
58+
}
59+
60+
# Function to run apt-get if needed
61+
apt_get_update_if_needed()
62+
{
63+
if [ ! -d "/var/lib/apt/lists" ] || [ "$(ls /var/lib/apt/lists/ | wc -l)" = "0" ]; then
64+
echo "Running apt-get update..."
65+
apt-get update
66+
else
67+
echo "Skipping apt-get update."
68+
fi
69+
}
70+
71+
# Checks if packages are installed and installs them if not
72+
check_packages() {
73+
if ! dpkg -s "$@" > /dev/null 2>&1; then
74+
apt_get_update_if_needed
75+
apt-get -y install --no-install-recommends "$@"
76+
fi
77+
}
78+
79+
# Ensure apt is in non-interactive to avoid prompts
80+
export DEBIAN_FRONTEND=noninteractive
81+
82+
# Install dependencies
83+
check_packages apt-transport-https curl ca-certificates tar gnupg2 dirmngr
84+
85+
# Install yarn
86+
if type yarn > /dev/null 2>&1; then
87+
echo "Yarn already installed."
88+
else
89+
# Import key safely (new method rather than deprecated apt-key approach) and install
90+
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | gpg --dearmor > /usr/share/keyrings/yarn-archive-keyring.gpg
91+
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/yarn-archive-keyring.gpg] https://dl.yarnpkg.com/debian/ stable main" > /etc/apt/sources.list.d/yarn.list
92+
apt-get update
93+
apt-get -y install --no-install-recommends yarn
94+
fi
95+
96+
# Adjust node version if required
97+
if [ "${NODE_VERSION}" = "none" ]; then
98+
export NODE_VERSION=
99+
elif [ "${NODE_VERSION}" = "lts" ]; then
100+
export NODE_VERSION="lts/*"
101+
fi
102+
103+
# Create a symlink to the installed version for use in Dockerfile PATH statements
104+
export NVM_SYMLINK_CURRENT=true
105+
106+
# Install the specified node version if NVM directory already exists, then exit
107+
if [ -d "${NVM_DIR}" ]; then
108+
echo "NVM already installed."
109+
if [ "${NODE_VERSION}" != "" ]; then
110+
su ${USERNAME} -c ". $NVM_DIR/nvm.sh && nvm install ${NODE_VERSION} && nvm clear-cache"
111+
fi
112+
exit 0
113+
fi
114+
115+
# Create nvm group, nvm dir, and set sticky bit
116+
if ! cat /etc/group | grep -e "^nvm:" > /dev/null 2>&1; then
117+
groupadd -r nvm
118+
fi
119+
umask 0002
120+
usermod -a -G nvm ${USERNAME}
121+
mkdir -p ${NVM_DIR}
122+
chown :nvm ${NVM_DIR}
123+
chmod g+s ${NVM_DIR}
124+
su ${USERNAME} -c "$(cat << EOF
125+
set -e
126+
umask 0002
127+
# Do not update profile - we'll do this manually
128+
export PROFILE=/dev/null
129+
ls -lah /home/${USERNAME}/.nvs || :
130+
curl -so- https://raw.githubusercontent.com/nvm-sh/nvm/v${NVM_VERSION}/install.sh | bash
131+
source ${NVM_DIR}/nvm.sh
132+
if [ "${NODE_VERSION}" != "" ]; then
133+
nvm alias default ${NODE_VERSION}
134+
fi
135+
nvm clear-cache
136+
EOF
137+
)" 2>&1
138+
# Update rc files
139+
if [ "${UPDATE_RC}" = "true" ]; then
140+
updaterc "$(cat <<EOF
141+
export NVM_DIR="${NVM_DIR}"
142+
[ -s "\$NVM_DIR/nvm.sh" ] && . "\$NVM_DIR/nvm.sh"
143+
[ -s "\$NVM_DIR/bash_completion" ] && . "\$NVM_DIR/bash_completion"
144+
EOF
145+
)"
146+
fi
147+
148+
# If enabled, verify "python3", "make", "gcc", "g++" commands are available so node-gyp works - https://github.com/nodejs/node-gyp
149+
if [ "${INSTALL_TOOLS_FOR_NODE_GYP}" = "true" ]; then
150+
echo "Verifying node-gyp OS requirements..."
151+
to_install=""
152+
if ! type make > /dev/null 2>&1; then
153+
to_install="${to_install} make"
154+
fi
155+
if ! type gcc > /dev/null 2>&1; then
156+
to_install="${to_install} gcc"
157+
fi
158+
if ! type g++ > /dev/null 2>&1; then
159+
to_install="${to_install} g++"
160+
fi
161+
if ! type python3 > /dev/null 2>&1; then
162+
to_install="${to_install} python3-minimal"
163+
fi
164+
if [ ! -z "${to_install}" ]; then
165+
apt_get_update_if_needed
166+
apt-get -y install ${to_install}
167+
fi
168+
fi
169+
170+
echo "Done!"

0 commit comments

Comments
 (0)