Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DevHub Grant: Development Environment Containerization #3

Merged
merged 3 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# [Choice] Debian OS version (use bookworm, or bullseye on local arm64/Apple Silicon): bookworm, buster, bullseye
ARG VARIANT="bookworm"
FROM rust:1-${VARIANT}

RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
# Remove imagemagick due to https://security-tracker.debian.org/tracker/CVE-2019-10131
&& apt-get purge -y imagemagick imagemagick-6-common

# Additional packages:
# - libudev-dev: required for the hidapi crate (cargo-near dependency)
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
&& apt-get -y install --no-install-recommends libudev-dev
18 changes: 18 additions & 0 deletions .devcontainer/cargo-near/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Cargo Near (cargo-near)

A feature to install cargo-near

## Example Usage

```json
"features": {
"": {} // TODO
}
```

## Options

| Options Id | Description | Type | Default Value |
| ---------- | ----------- | ---- | ------------- |

---
8 changes: 8 additions & 0 deletions .devcontainer/cargo-near/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "Cargo Near",
"id": "cargo-near",
"version": "0.1.0",
"description": "A feature to install cargo-near",
"options": {},
"installsAfter": ["ghcr.io/devcontainers/features/rust", "ghcr.io/lee-orr/rusty-dev-containers/cargo-binstall"]
}
16 changes: 16 additions & 0 deletions .devcontainer/cargo-near/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash
set -e

if ! (which rustup > /dev/null && which cargo > /dev/null); then
which curl > /dev/null || (apt update && apt install curl -y -qq)
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
source $HOME/.cargo/env
fi

dpkg -l | grep build-essential || (apt update && apt install build-essential -y -qq)

if ! cargo install --list | grep "cargo-binstall" > /dev/null; then
curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash
fi

cargo binstall cargo-near --locked -y
34 changes: 34 additions & 0 deletions .devcontainer/devcontainer-lock.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"features": {
"ghcr.io/devcontainers-community/features/llvm": {
"version": "3.1.0",
"resolved": "ghcr.io/devcontainers-community/features/llvm@sha256:0b1cb680de18860c92d70d8b921b50f166ab875936a047b4cbf2068b69ef7bdf",
"integrity": "sha256:0b1cb680de18860c92d70d8b921b50f166ab875936a047b4cbf2068b69ef7bdf"
},
"ghcr.io/devcontainers/features/common-utils:2": {
"version": "2.4.0",
"resolved": "ghcr.io/devcontainers/features/common-utils@sha256:cd9c4413255c3b71fb716e63ee2df245c81c7262b858cf77406a68c80d09f12e",
"integrity": "sha256:cd9c4413255c3b71fb716e63ee2df245c81c7262b858cf77406a68c80d09f12e"
},
"ghcr.io/devcontainers/features/docker-in-docker:2": {
"version": "2.7.1",
"resolved": "ghcr.io/devcontainers/features/docker-in-docker@sha256:f6a73ee06601d703db7d95d03e415cab229e78df92bb5002e8559bcfc047fec6",
"integrity": "sha256:f6a73ee06601d703db7d95d03e415cab229e78df92bb5002e8559bcfc047fec6"
},
"ghcr.io/devcontainers/features/git:1": {
"version": "1.1.6",
"resolved": "ghcr.io/devcontainers/features/git@sha256:f839be8a0203abe12c917b262b1a1330b8286f9576ef21ea4a26ed60c5bc9947",
"integrity": "sha256:f839be8a0203abe12c917b262b1a1330b8286f9576ef21ea4a26ed60c5bc9947"
},
"ghcr.io/devcontainers/features/rust:1": {
"version": "1.1.1",
"resolved": "ghcr.io/devcontainers/features/rust@sha256:e81d6a952842a4e10d1e4dbb9cb295a1ead44befd8212522a67b8867427b929d",
"integrity": "sha256:e81d6a952842a4e10d1e4dbb9cb295a1ead44befd8212522a67b8867427b929d"
},
"ghcr.io/lee-orr/rusty-dev-containers/cargo-binstall:0": {
"version": "0.1.0",
"resolved": "ghcr.io/lee-orr/rusty-dev-containers/cargo-binstall@sha256:08f406c6101dccc5a872cff117f8731b4f8b08a1d8e58eac0fdd0422e84417a0",
"integrity": "sha256:08f406c6101dccc5a872cff117f8731b4f8b08a1d8e58eac0fdd0422e84417a0"
}
}
}
40 changes: 40 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"name": "NEAR Devcontainer Rust",
"build": {
"dockerfile": "./Dockerfile",
"context": "."
},

"features": {
"./cargo-near": {},
"./near-cli": {},
"ghcr.io/devcontainers-community/features/llvm": {},
"ghcr.io/devcontainers/features/rust:1": "latest",
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
"ghcr.io/devcontainers/features/git:1": {
"version": "latest",
"ppa": "false"
},
"ghcr.io/lee-orr/rusty-dev-containers/cargo-binstall:0": {},
"ghcr.io/devcontainers/features/common-utils:2": {
"installZsh": "true",
"username": "vscode",
"userUid": "1000",
"userGid": "1000",
"upgradePackages": "true"
}
},

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

"postCreateCommand": "bash .devcontainer/init.sh",

"remoteUser": "vscode",

"customizations": {
"codespaces": {
"openFiles": ["README.md", "src/lib.rs", "tests/test_basics.rs"]
}
}
}
5 changes: 5 additions & 0 deletions .devcontainer/init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Get correct rust for repo (will be redundant once repo changes to stable)
cargo

# Cache images that will be used on source verification
docker image pull nearprotocol/contract-builder:latest-amd64
18 changes: 18 additions & 0 deletions .devcontainer/near-cli/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Near CLII (near-cli-rs)

A feature to install near-cli-rs

## Example Usage

```json
"features": {
"": {} // TODO
}
```

## Options

| Options Id | Description | Type | Default Value |
| ---------- | ----------- | ---- | ------------- |

---
8 changes: 8 additions & 0 deletions .devcontainer/near-cli/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "Near CLI",
"id": "near-cli",
"version": "0.1.0",
"description": "A feature to install the near-cli",
"options": {},
"installsAfter": ["ghcr.io/devcontainers/features/rust", "ghcr.io/lee-orr/rusty-dev-containers/cargo-binstall"]
}
16 changes: 16 additions & 0 deletions .devcontainer/near-cli/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash
set -e

if ! (which rustup > /dev/null && which cargo > /dev/null); then
which curl > /dev/null || (apt update && apt install curl -y -qq)
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
source $HOME/.cargo/env
fi

dpkg -l | grep build-essential || (apt update && apt install build-essential -y -qq)

if ! cargo install --list | grep "cargo-binstall" > /dev/null; then
curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash
fi

cargo binstall near-cli-rs --locked -y
Loading