Closed4

c2a-coreにdevcontainerで動かす

ピン留めされたアイテム
keizo042keizo042

完全版

  • rootユーザで動いてるのだけが難点
  • Dockerfileビルド時にc2aユーザを作ってrye,nvmをいい感じのディレクトリにインストールし、vscodeのremoteユーザをc2aとかにすればnon rootになるがローカル開発環境だしいらないかな
├── Dockerfile
├── devcontainer.json
├── install.sh
└── postCreateCommand.sh

devcontainer.json

{
  "build": {
    "dockerfile": "Dockerfile"
  },
  "remoteUser": "root",
  "postCreateCommand": "bash .devcontainer/postCreateCommand.sh "
}

Dockerfile

FROM mcr.microsoft.com/devcontainers/rust:1-1-bullseye

COPY ./install.sh install.sh
RUN  bash  install.sh

install.sh

sudo apt update -y
sudo apt install -y  ninja-build gcc-multilib clang protobuf-compiler libclang-dev cmake g++ g++-multilib
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
source "$HOME/.nvm/nvm.sh"  # This loads nvm
nvm install node
npm install -g yarn
curl -sSf https://rye-up.com/get | RYE_INSTALL_OPTION="--yes" bash
echo "export NVM_DIR=\"/root/.nvm\"" >> /etc/profile.d/docker
echo "source \"/root/.rye/env\"" >> /etc/profile.d/docker
echo "source \"/root/.nvm/nvm.sh\"" >> /etc/profile.d/docker

postCreateCommand.sh

[ ! -d ./python-wings-interface ] && git clone  https://github.com/ut-issl/python-wings-interface.git || true
[ ! -d ./c2a-pytest-gaia ] && git clone https://github.com/arkedge/c2a-pytest-gaia.git || true

``
keizo042keizo042

PRにして出すほどでもないが、自分がちょこっと動かして遊ぶために公開メモとして残しておく。

  • "c2a-core"とは https://github.com/arkedge/c2a-core のこと。

  • 公開した方の記事 https://meltingrabbit.com/blog/article/2021113001/

  • 記事はut-issl orgだがビルドしたのはarkedgeのorg

  • arkdedgeが先行版でut-isslがstableみたい

  • cargo build, cargo testをできるようにした。ほとんどやることがなかった。

  • version

    • c2-acore v4.3.0
    • vscode 1.87.1
  • やること

    • c2a-core/.devcontainer/devcontainer.json に配置する
    • reopen in dev containerをvscodeから実行する
  • next action

    • 接続したボードにdevcontainerからビルドバイナリを書き込むことができれば嬉しい
    • dockerはdebianだけどrustのクロスコンパイルを信じる

// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/rust
{
	"name": "Rust",
	// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
	"image": "mcr.microsoft.com/devcontainers/rust:1-1-bullseye"

	// Use 'mounts' to make the cargo cache persistent in a Docker Volume.
	// "mounts": [
	// 	{
	// 		"source": "devcontainer-cargo-cache-${devcontainerId}",
	// 		"target": "/usr/local/cargo",
	// 		"type": "volume"
	// 	}
	// ]

	// Features to add to the dev container. More info: https://containers.dev/features.
	// "features": {},

	// Use 'forwardPorts' to make a list of ports inside the container available locally.
	// "forwardPorts": [],

	// Use 'postCreateCommand' to run commands after the container is created.
	"postCreateCommand": "sudo apt update -y && sudo apt install -y  gcc-multilib clang",

	// Configure tool-specific properties.
	// "customizations": {},

	// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
	// "remoteUser": "root"
}

keizo042keizo042

development_environment.mdに必要なツールが書いてあった。

git diff でpatchを出した。patch -N とかで、一枚目の設定にmergeできる

diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json
index f21bb6bb..2a0868dc 100644
--- a/.devcontainer/devcontainer.json
+++ b/.devcontainer/devcontainer.json
@@ -3,7 +3,7 @@
 {
 	"name": "Rust",
 	// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
-	"image": "mcr.microsoft.com/devcontainers/rust:1-1-bullseye"
+	"image": "mcr.microsoft.com/devcontainers/rust:1-1-bullseye",
 
 	// Use 'mounts' to make the cargo cache persistent in a Docker Volume.
 	// "mounts": [
@@ -21,7 +21,7 @@
 	// "forwardPorts": [],
 
 	// Use 'postCreateCommand' to run commands after the container is created.
-	"postCreateCommand": "sudo apt update -y && sudo apt install -y  gcc-multilib clang",
+	"postCreateCommand": "bash .devcontainer/install.sh"
 
 	// Configure tool-specific properties.
 	// "customizations": {},
diff --git a/.devcontainer/install.sh b/.devcontainer/install.sh
new file mode 100644
index 00000000..53710b29
--- /dev/null
+++ b/.devcontainer/install.sh
@@ -0,0 +1,9 @@
+sudo apt update -y
+sudo apt install -y  gcc-multilib clang
+curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
+export NVM_DIR="$HOME/.nvm"
+[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
+nvm install node
+npm install -g yarn
+curl -sSf https://rye-up.com/get | RYE_INSTALL_OPTION="--yes" bash
+

keizo042keizo042
  • vscodeで立ち上げた時にnvmやryeへパスが通っていなかったためDockerfileにした改善版
  • rootユーザで動いてるのがちょっと気に食わないが目をつぶる
diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile
new file mode 100644
index 00000000..293973ec
--- /dev/null
+++ b/.devcontainer/Dockerfile
@@ -0,0 +1,4 @@
+FROM mcr.microsoft.com/devcontainers/rust:1-1-bullseye
+
+COPY ./install.sh install.sh
+RUN  bash  install.sh
diff --git a/.devcontainer/Dockerfile.tmp b/.devcontainer/Dockerfile.tmp
new file mode 100644
index 00000000..ddf51049
--- /dev/null
+++ b/.devcontainer/Dockerfile.tmp
@@ -0,0 +1,4 @@
+FROM mcr.microsoft.com/devcontainers/rust:1-1-bullseye
+
+COPY ./install.sh install.sh
+
diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json
new file mode 100644
index 00000000..3763959e
--- /dev/null
+++ b/.devcontainer/devcontainer.json
@@ -0,0 +1,6 @@
+{
+  "build": {
+    "dockerfile": "Dockerfile"
+  },
+  "remoteUser": "root"
+}
\ No newline at end of file
diff --git a/.devcontainer/install.sh b/.devcontainer/install.sh
new file mode 100644
index 00000000..e0dfbd5e
--- /dev/null
+++ b/.devcontainer/install.sh
@@ -0,0 +1,10 @@
+sudo apt update -y
+sudo apt install -y  gcc-multilib clang
+curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
+source "$HOME/.nvm/nvm.sh"  # This loads nvm
+nvm install node
+npm install -g yarn
+curl -sSf https://rye-up.com/get | RYE_INSTALL_OPTION="--yes" bash
+echo "export NVM_DIR=\"/root/.nvm\"" >> /etc/profile.d/docker
+echo "source \"/root/.rye/env\"" >> /etc/profile.d/docker
+echo "source \"/root/.nvm/nvm.sh\"" >> /etc/profile.d/docker
diff --git a/.github/dependabot.yml b/.github/dependabot.yml
new file mode 100644
index 00000000..f33a02cd
--- /dev/null
+++ b/.github/dependabot.yml
@@ -0,0 +1,12 @@
+# To get started with Dependabot version updates, you'll need to specify which
+# package ecosystems to update and where the package manifests are located.
+# Please see the documentation for more information:
+# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
+# https://containers.dev/guide/dependabot
+
+version: 2
+updates:
+ - package-ecosystem: "devcontainers"
+   directory: "/"
+   schedule:
+     interval: weekly

このスクラップは2024/04/06にクローズされました