Skip to content

Commit 42e97af

Browse files
committed
added devcontainer
1 parent 0bceeb2 commit 42e97af

7 files changed

Lines changed: 267 additions & 0 deletions

File tree

.devcontainer/Dockerfile

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
################################################################################
2+
# Copyright (c) 2023 Contributors to the Eclipse Foundation
3+
#
4+
# See the NOTICE file(s) distributed with this work for additional
5+
# information regarding copyright ownership.
6+
#
7+
# This program and the accompanying materials are made available under the
8+
# terms of the Apache License Version 2.0 which is available at
9+
# https://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# SPDX-License-Identifier: Apache-2.0
12+
################################################################################
13+
14+
FROM mcr.microsoft.com/devcontainers/rust:latest
15+
ARG USERNAME=vscode
16+
ARG TARGETARCH
17+
18+
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
19+
&& apt-get -y install \
20+
curl \
21+
gcc \
22+
git \
23+
openjdk-17-jre \
24+
zip \
25+
&& \
26+
rm -rf /var/lib/apt/lists/*
27+
28+
# Download openfasttrace JARs and create shortcut oft executable
29+
ARG OFT_CORE_VERSION=4.1.0
30+
ARG OFT_ASCIIDOC_PLUGIN_VERSION=0.3.0
31+
ENV LIB_DIR=/opt/oft/lib
32+
RUN mkdir -p $LIB_DIR \
33+
&& base_url=https://github.com/itsallcode \
34+
&& wget -P $LIB_DIR ${base_url}/openfasttrace/releases/download/$OFT_CORE_VERSION/openfasttrace-$OFT_CORE_VERSION.jar \
35+
&& wget -P $LIB_DIR ${base_url}/openfasttrace-asciidoc-plugin/releases/download/$OFT_ASCIIDOC_PLUGIN_VERSION/openfasttrace-asciidoc-plugin-$OFT_ASCIIDOC_PLUGIN_VERSION-with-dependencies.jar \
36+
&& echo '#!/bin/bash\n\njava -cp "${LIB_DIR}/*" org.itsallcode.openfasttrace.core.cli.CliStarter "$@"' > /usr/local/bin/oft \
37+
&& chmod +x /usr/local/bin/oft
38+
39+
# Before installing cargo tools, change to the user that will be used in the container later.
40+
# The reason is that cargo creates some cache, etc. folders with the correct group rustlang, but
41+
# without making them group writable. Easiest fix is to change to the correct user before the install,
42+
# so that the owner is correct from the start.
43+
USER ${USERNAME}
44+
45+
# Install cargo cli tools
46+
RUN cargo install cargo-nextest cargo-deny cargo-tarpaulin --locked

.devcontainer/devcontainer.json

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
2+
// README at: https://github.com/devcontainers/templates/tree/main/src/rust
3+
{
4+
"name": "up-transport-iceoryx2-rust",
5+
"build": {
6+
"dockerfile": "Dockerfile"
7+
},
8+
"runArgs": [
9+
"--privileged"
10+
],
11+
"containerEnv": {
12+
"WORKSPACE_FOLDER": "${containerWorkspaceFolder}"
13+
},
14+
"mounts": [
15+
{
16+
// This is a workaround which is again necessary on MacOS 14.0, it looks like this bug is back:
17+
// https://github.com/microsoft/vscode-dev-containers/issues/1487#issuecomment-1143907307
18+
"type": "volume",
19+
"source": "rust-volume",
20+
"target": "/rust-volume"
21+
},
22+
{
23+
"type": "bind",
24+
"source": "${localWorkspaceFolder}/.devcontainer/scripts",
25+
"target": "/home/vscode/scripts"
26+
},
27+
{
28+
"type": "bind",
29+
"source": "${localEnv:HOME}${localEnv:USERPROFILE}/.ssh",
30+
"target": "/home/vscode/.ssh"
31+
}
32+
],
33+
"postCreateCommand": ".devcontainer/scripts/post-create.sh --workspace-folder='${containerWorkspaceFolder}'",
34+
"workspaceMount": "source=${localWorkspaceFolder},target=/workspace/${localWorkspaceFolderBasename}/,type=bind",
35+
"workspaceFolder": "/workspace/${localWorkspaceFolderBasename}/",
36+
"remoteUser": "vscode",
37+
"customizations": {
38+
"vscode": {
39+
// Set *default* container specific settings.json values on container create.
40+
"settings": {
41+
"lldb.executable": "/usr/bin/lldb",
42+
// VS Code don't watch files under ./target
43+
"files.watcherExclude": {
44+
"**/target/**": true
45+
},
46+
"rust-analyzer.check.command": "clippy",
47+
"rust-analyzer.checkOnSave": true,
48+
"coverage-gutters.coverageBaseDir": "**",
49+
"coverage-gutters.coverageFileNames": [
50+
"target/tarpaulin/lcov.info"
51+
]
52+
},
53+
// Add the IDs of extensions you want installed when the container is created.
54+
"extensions": [
55+
"asciidoctor.asciidoctor-vscode",
56+
"bianxianyang.htmlplay",
57+
"bierner.markdown-mermaid",
58+
"bierner.markdown-preview-github-styles",
59+
"davidanson.vscode-markdownlint",
60+
"gxl.git-graph-3",
61+
"hediet.vscode-drawio",
62+
"linusu.auto-dark-mode",
63+
"ms-azuretools.vscode-containers",
64+
"rust-lang.rust-analyzer",
65+
"streetsidesoftware.code-spell-checker",
66+
"tamasfe.even-better-toml",
67+
"timonwong.shellcheck",
68+
"vadimcn.vscode-lldb",
69+
"yzhang.markdown-all-in-one"
70+
]
71+
}
72+
}
73+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/bin/bash
2+
3+
source ${WORKSPACE_FOLDER}/.devcontainer/scripts/colors.sh
4+
5+
PRIMARY_COLOR=$COLOR_GRAY
6+
SECONDARY_COLOR=$COLOR_NC
7+
INFO_COLOR=$COLOR_CYAN
8+
9+
if [ -d "$HOME/.ssh" ]; then
10+
# Sometimes when mounting volumes, the files unexpectedly change their read-write-execute status.
11+
# This is dependent on the OS the Docker container is mounting from, and how it exposes its
12+
# files permissions, ownership, and "executability" to the container and the containers user.
13+
#
14+
# More about specific permissions inside the .ssh folder
15+
# https://serverfault.com/a/253314
16+
find ~/.ssh -maxdepth 1 -type f -exec chmod 600 {} \;
17+
fi
18+
19+
WELCOME_INFO="${SECONDARY_COLOR}
20+
██ ██ ███████ ██ ██████ ██████ ███ ███ ███████
21+
██ ██ ██ ██ ██ ██ ██ ████ ████ ██
22+
██ █ ██ █████ ██ ██ ██ ██ ██ ████ ██ █████
23+
██ ███ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
24+
███ ███ ███████ ███████ ██████ ██████ ██ ██ ███████
25+
${PRIMARY_COLOR}
26+
to the Eclipse Foundation ${INFO_COLOR}up-transport-iceoryx2-rust${PRIMARY_COLOR} code repository
27+
28+
Workspace Folder ${SECONDARY_COLOR}$WORKSPACE_FOLDER
29+
30+
${INFO_COLOR}Library Version(s)${PRIMARY_COLOR}
31+
Rust Version ${SECONDARY_COLOR}$(rustc --version)${PRIMARY_COLOR}
32+
Cargo Version ${SECONDARY_COLOR}$(cargo --version)${PRIMARY_COLOR}
33+
34+
${INFO_COLOR}Git${PRIMARY_COLOR}
35+
Username ${SECONDARY_COLOR}$(git config user.name)${PRIMARY_COLOR}
36+
Email ${SECONDARY_COLOR}$(git config user.email)${PRIMARY_COLOR}
37+
38+
to see this info again, use the ${INFO_COLOR}welcome${PRIMARY_COLOR} command${COLOR_NC}
39+
"
40+
41+
alias welcome='printf "$WELCOME_INFO"'
42+
welcome

.devcontainer/scripts/colors.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
3+
export COLOR_NC='\e[0m' # No Color
4+
export COLOR_BLACK='\e[0;30m'
5+
export COLOR_GRAY='\e[1;30m'
6+
export COLOR_RED='\e[0;31m'
7+
export COLOR_LIGHT_RED='\e[1;31m'
8+
export COLOR_GREEN='\e[0;32m'
9+
export COLOR_LIGHT_GREEN='\e[1;32m'
10+
export COLOR_BROWN='\e[0;33m'
11+
export COLOR_YELLOW='\e[1;33m'
12+
export COLOR_BLUE='\e[0;34m'
13+
export COLOR_LIGHT_BLUE='\e[1;34m'
14+
export COLOR_PURPLE='\e[0;35m'
15+
export COLOR_LIGHT_PURPLE='\e[1;35m'
16+
export COLOR_CYAN='\e[0;36m'
17+
export COLOR_LIGHT_CYAN='\e[1;36m'
18+
export COLOR_LIGHT_GRAY='\e[0;37m'
19+
export COLOR_WHITE='\e[1;37m'
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash
2+
3+
get_arch_and_os() {
4+
ARCH=$(uname -m)
5+
OS=$(uname -s | tr "[:upper:]" "[:lower:]")
6+
7+
case "$ARCH" in
8+
x86_64)
9+
TARGET_ARCH="x86_64"
10+
;;
11+
aarch64 | arm64)
12+
TARGET_ARCH="aarch64"
13+
;;
14+
*)
15+
echo "Unsupported architecture: $ARCH"
16+
exit 1
17+
;;
18+
esac
19+
20+
case "$OS" in
21+
linux)
22+
TARGET_OS="unknown-linux-gnu"
23+
;;
24+
*)
25+
echo "OS is unsupported or not implemented in this script: $OS"
26+
exit 1
27+
;;
28+
esac
29+
echo "$TARGET_ARCH $TARGET_OS"
30+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
3+
install_rust_toolchain() {
4+
source ${WORKSPACE_FOLDER}/.devcontainer/scripts/functions/get-arch-and-os.sh
5+
read -r TARGET_ARCH TARGET_OS <<< "$(get_arch_and_os)"
6+
ARCH_AND_OS="${TARGET_ARCH}-${TARGET_OS}"
7+
echo "Detected architecture and OS: $ARCH_AND_OS"
8+
RUST_TOOLCHAIN="stable-$ARCH_AND_OS"
9+
echo "Adding rustup target '$ARCH_AND_OS'"
10+
rustup target add "$ARCH_AND_OS"
11+
echo "Installing Rust toolchain for '$ARCH_AND_OS'"
12+
rustup toolchain install "$RUST_TOOLCHAIN"
13+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/bin/bash
2+
3+
#region sudo stuff
4+
5+
HOST_OS=""
6+
ARCH_AND_OS_FUNC="${WORKSPACE_FOLDER}/.devcontainer/scripts/functions/get-arch-and-os.sh"
7+
if [[ -f "$ARCH_AND_OS_FUNC" ]]; then
8+
source $ARCH_AND_OS_FUNC
9+
read -r _ HOST_OS <<< "$(get_arch_and_os)"
10+
fi
11+
if [[ "$HOST_OS" == "darwin" ]]; then # darwin == Mac OS
12+
# This is a workaround which is againt necessary on MacOS 14.0, it looks like this bug is back:
13+
# https://github.com/microsoft/vscode-dev-containers/issues/1487#issuecomment-1143907307
14+
# grant permissions to mounted rust volume
15+
echo "(Mac OS only) Granting permissions to mounted rust volume"
16+
sudo chown vscode:vscode /rust-volume
17+
18+
# create /.cargo/config.toml in root folder
19+
sudo mkdir /.cargo/
20+
sudo touch /.cargo/config.toml
21+
sudo bash -c "cat << EOF > /.cargo/config.toml
22+
[build]
23+
target-dir = \"/rust-volume/target\"
24+
EOF"
25+
fi
26+
27+
#endregion
28+
29+
if ! grep -q "WELCOME_INFO" ~/.bashrc; then
30+
if [[ -f "${WORKSPACE_FOLDER}/.devcontainer/scripts/bashrc_addition.sh" ]]; then
31+
cat "${WORKSPACE_FOLDER}/.devcontainer/scripts/bashrc_addition.sh" >> ~/.bashrc
32+
fi
33+
fi
34+
35+
for arg in "$@"; do
36+
if [[ "$arg" == --workspace-folder=* ]]; then
37+
WORKSPACE_FOLDER="${arg#--workspace-folder=}"
38+
fi
39+
done
40+
INSTALL_RUST_TOOLCHAIN_FUNC="${WORKSPACE_FOLDER}/.devcontainer/scripts/functions/install-rust-toolchain.sh"
41+
if [[ -f "$INSTALL_RUST_TOOLCHAIN_FUNC" ]]; then
42+
source $INSTALL_RUST_TOOLCHAIN_FUNC
43+
install_rust_toolchain "$@"
44+
fi

0 commit comments

Comments
 (0)