Skip to content

Migrate to Devcontainers POC #371

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

Merged
merged 51 commits into from
Apr 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
8d1319f
Initial Devcontainers config
anataliocs Mar 31, 2025
fb4c43f
Update config
anataliocs Apr 1, 2025
e68310c
Update startup scripts
anataliocs Apr 1, 2025
c021c4f
Update devcontainer for stellar cli
anataliocs Apr 1, 2025
f0ace8e
Add cargo watch binaryen and make all entrypoint
anataliocs Apr 1, 2025
83ddaac
Fix script perms
anataliocs Apr 1, 2025
71ce798
Fix script perms
anataliocs Apr 1, 2025
2e199ef
Use homebrew safely
anataliocs Apr 1, 2025
4f8ef2f
Fix scripts
anataliocs Apr 1, 2025
06a820b
improve caching
anataliocs Apr 1, 2025
339e6ce
improve caching
anataliocs Apr 1, 2025
f1181ca
Update docs, cleanup and caching
anataliocs Apr 2, 2025
9f037fe
code cleanup
anataliocs Apr 2, 2025
c540440
Clean up script to make sure stuff gets added to /Users/chris.anatali…
anataliocs Apr 2, 2025
6bfd9e5
Clean up script to make sure stuff gets added to /Users/chris.anatali…
anataliocs Apr 2, 2025
7445f71
Fix scripts
anataliocs Apr 2, 2025
bcd7007
Run checks and static analysis on bash scripts to fix
anataliocs Apr 2, 2025
bd50bfe
Run checks and static analysis on bash scripts to fix
anataliocs Apr 2, 2025
903da9a
Create validate-devcontainer-json
anataliocs Apr 2, 2025
b0b0e6a
Add GH action to validate devcontainer json vs schema
anataliocs Apr 2, 2025
2524666
Add GH action to validate scripts, test build and push prebuild cache
anataliocs Apr 2, 2025
6eef356
Update validate-devcontainer-json.yml
anataliocs Apr 2, 2025
42a606f
Fix GH action
anataliocs Apr 2, 2025
cb20752
Update tests.md
anataliocs Apr 2, 2025
abd0309
Update validate-devcontainer-json.yml
anataliocs Apr 2, 2025
2f49dda
JSON Schema validation on GH Action
anataliocs Apr 3, 2025
1d9cc22
JSON Schema validation on GH Action
anataliocs Apr 3, 2025
0c52028
Getting JSON Schema validation and script validation and build cache …
anataliocs Apr 4, 2025
8b1a4f0
Add devcontainer cli to GH Action
anataliocs Apr 4, 2025
1e0da9b
Add devcontainer cli to GH Action
anataliocs Apr 4, 2025
664156a
Add devcontainer cli to GH Action
anataliocs Apr 4, 2025
add9aca
Add devcontainer cli to GH Action
anataliocs Apr 4, 2025
5429261
Add devcontainer cli to GH Action
anataliocs Apr 4, 2025
1fbacb8
Add devcontainer cli to GH Action
anataliocs Apr 4, 2025
4dc1b4e
Add devcontainer cli to GH Action
anataliocs Apr 4, 2025
42ea804
Green GH Action JSON validation and build jobs
anataliocs Apr 4, 2025
a64bbca
Green GH Action JSON validation and build jobs
anataliocs Apr 7, 2025
6bb7ab4
Code cleanup
anataliocs Apr 7, 2025
51efba9
Update welcome message and VSCode extensions
anataliocs Apr 7, 2025
120b448
Update badge to use vscode web by default
anataliocs Apr 7, 2025
e56a6f3
Build stellar cli and sccache from gh release binary
anataliocs Apr 7, 2025
6f689ad
Build stellar cli and sccache from gh release binary
anataliocs Apr 7, 2025
9bd1248
Code cleanup
anataliocs Apr 8, 2025
418379b
Code cleanup
anataliocs Apr 8, 2025
1b04e0c
Tune down rust analyzer, spiking CPU to 100%
anataliocs Apr 8, 2025
be4cdc5
Update .devcontainer/Dockerfile
anataliocs Apr 15, 2025
550b12d
Update build-and-test-devcontainer.yml
anataliocs Apr 15, 2025
7dd2e34
Pin bats to commit hash
anataliocs Apr 15, 2025
244e772
Merge branch 'migrate-to-devcontainers-poc' of github.com:anataliocs/…
anataliocs Apr 15, 2025
e866798
Clean-up bash scripts
anataliocs Apr 15, 2025
7479e22
Cross-platform gh cli install
anataliocs Apr 15, 2025
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
19 changes: 19 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM mcr.microsoft.com/devcontainers/rust:1.0.9-1

ENV DEBIAN_FRONTEND=noninteractive \
PKG_CONFIG_PATH='/usr/lib/pkgconfig:/usr/local/lib/pkgconfig:/usr/share/pkgconfig' \
CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse \
CARGO_INCREMENTAL=0 \
SCCACHE_DIR=/home/vscode/.cache/sccache \
SCCACHE_CONF=/home/vscode/.config/sccache/config \
SCCACHE_DIRECT=true \
RUSTC_WRAPPER=sccache \
SCCACHE_CACHE_SIZE=5G \
RUST_VERSION=1.81

RUN apt-get update && apt-get install -y \
libdbus-1-dev \
libudev-dev \
pkg-config \
openssl && apt-get clean && \
rm -rf /var/lib/apt/lists/*
86 changes: 86 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
{
"name": "Soroban Examples Devcontainer",
"dockerFile": "Dockerfile",
"context": "..",
"build": {
"args": {
"BUILDKIT_INLINE_CACHE": "1"
}
},
"hostRequirements": {
"cpus": 4,
"memory": "16",
"storage": "32"
},
"forwardPorts": [
4226
],
"portsAttributes": {
"4226": {
"label": "sccache"
}
},
"features": {
"ghcr.io/devcontainers/features/common-utils:2.5.3": {
"configureZshAsDefaultShell": true
},
"ghcr.io/devcontainers/features/rust:1.3.1": {
"targets": "wasm32-unknown-unknown",
"profile": "default",
"version": "1.81"
},
"ghcr.io/devcontainers-extra/features/gh-release:1.0.25": {
"repo": "stellar/stellar-cli",
"binaryNames": "stellar",
"version": "22.6.0"
},
"ghcr.io/rapidsai/devcontainers/features/sccache:25.6.1": {
"repository": "mozilla/sccache",
"version": "0.10.0"
}
},
"customizations": {
"codespaces": {
"openFiles": [
"README.md",
"FULL_HELP_DOCS.md",
"increment/src/lib.rs",
"increment/src/test.rs"
]
},
"vscode": {
"extensions": [
"rust-lang.rust-analyzer",
"vadimcn.vscode-lldb",
"tamasfe.even-better-toml"
],
"settings": {
"workbench.settings.editor": "json",
"workbench.settings.useSplitJSON": true,
"npm.autoDetect": "off",
"telemetry.feedback.enabled": false,
"workbench.tips.enabled": false,
"editor.codeLens": false,
"editor.minimap.enabled": false,
"terminal.integrated.useWslProfiles": false,
"terminal.integrated.sendKeybindingsToShell": true,
"terminal.integrated.allowChords": true,
"rust-analyzer.check.allTargets": false,
"rust-analyzer.cargo.allTargets": false,
"rust-analyzer.procMacro.attributes.enable": false,
"rust-analyzer.lens.enable": false,
"files.readonlyInclude": {
"**/.cargo/registry/src/**/*.rs": true,
"**/.cargo/git/checkouts/**/*.rs": true,
"**/lib/rustlib/src/rust/library/**/*.rs": true
}
}
}
},
"initializeCommand": "",
"onCreateCommand": "chmod +x .devcontainer/post_start_cli_autocomplete.sh && chmod +x .devcontainer/post_attach_welcome_text.sh",
"updateContentCommand": "",
"postCreateCommand": "",
"postStartCommand": ".devcontainer/post_start_cli_autocomplete.sh",
"postAttachCommand": ".devcontainer/post_attach_welcome_text.sh"
}
25 changes: 25 additions & 0 deletions .devcontainer/post_attach_welcome_text.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash
set -e

clear

echo " ⚙️ Setup testnet:"
echo " stellar network use testnet"
echo ""
echo " 🆔 Configure an Identity:"
echo " stellar keys generate --global alice --network testnet --fund"
echo " stellar keys address alice"
echo " stellar keys use alice"
echo ""
echo " 🛠️ Build a contract(Replace 'alloc' with desired project):"
echo " stellar contract build --manifest-path $CODESPACE_VSCODE_FOLDER/alloc/Cargo.toml"
echo ""
echo " 🧪 Run tests | 🔨Build Projects"
echo " ⚠️ make all in the root directory will fill up a 32GB storage instance"
echo " cd [Project] e.g. cd account"
echo " cargo test ⭐️ make all"
echo ""
echo " 📖 Stellar CLI Manual(cmd+click) 🔗 https://developers.stellar.org/docs/tools/cli/stellar-cli"
echo " 👩‍🔬 Stellar Lab(cmd+click) 🔗 https://lab.stellar.org/"


22 changes: 22 additions & 0 deletions .devcontainer/post_start_cli_autocomplete.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash
set -euxo pipefail

# Add Stellar CLI to $PATH
chmod 644 ~/.bashrc && chmod 644 ~/.zshrc

test -d /usr/local/bin/ && echo "/usr/local/bin/" >> ~/.zshrc
test -d /usr/local/bin/ && echo "/usr/local/bin/" >> ~/.bashrc

export PATH="/usr/local/bin/":$PATH
echo "export PATH='/usr/local/bin/:$PATH'" >> ~/.zshrc
echo "export PATH='/usr/local/bin/:$PATH'" >> ~/.bashrc

# Stellar CLI Auto-Complete
chmod 644 ~/.bashrc
echo "source <(stellar completion --shell bash)" >>~/.bashrc
chmod 644 ~/.zshrc
echo "source <(stellar completion --shell zsh)" >>~/.zshrc
echo "Enabled Stellar CLI auto-completion"

echo " ✅ postStartCliAutocomplete.sh executed successfully"

42 changes: 42 additions & 0 deletions .devcontainer/post_start_cli_autocomplete_test.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env bats

setup() {
load 'test_helper.bats'
_tests_helper
_create_dir_file
}

# executed after each test
teardown() {
_delete_dir_file
}

@test "script executes successfully and configures PATH and autocompletion" {
# Copy the script to the temporary directory
cp "$(dirname "$BATS_TEST_FILENAME")/post_start_cli_autocomplete.sh" "${BATS_TMPDIR}/"
chmod +x "${BATS_TMPDIR}/post_start_cli_autocomplete.sh"

# Set HOME to BATS_TMPDIR for the test
export HOME="${BATS_TMPDIR}"

# Run the script and capture its output
run "${BATS_TMPDIR}/post_start_cli_autocomplete.sh"

# Verify /usr/local/bin/ is appended to .bashrc and .zshrc files
assert_file_contains "${BATS_TMPDIR}/.bashrc" "/usr/local/bin/"
assert_file_contains "${BATS_TMPDIR}/.zshrc" "/usr/local/bin/"

# Verify env PATH export in .bashrc and .zshrc
assert_file_contains "${BATS_TMPDIR}/.bashrc" $'export PATH=\'/usr/local/bin/'
assert_file_contains "${BATS_TMPDIR}/.zshrc" $'export PATH=\'/usr/local/bin/'

# Verify stellar CLI completion is included in .bashrc and .zshrc
assert_file_contains "${BATS_TMPDIR}/.bashrc" "source <(stellar completion --shell bash)"
assert_file_contains "${BATS_TMPDIR}/.zshrc" "source <(stellar completion --shell zsh)"

# Check script execution status is successful
assert_success

# Check for success message on script execution
assert_output --partial "✅ postStartCliAutocomplete.sh executed successfully"
}
24 changes: 24 additions & 0 deletions .devcontainer/test_helper.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
_tests_helper() {
echo "BATS LIB PATH: ${BATS_LIB_PATH}"
bats_load_library bats-support
bats_load_library bats-assert
bats_load_library bats-file
}

_create_dir_file() {
temp_make
assert_dir_exist "${BATS_TMPDIR}"
echo "Temp: ${BATS_TMPDIR}"

# Create empty bash and zsh config files in the temporary directory
touch "${BATS_TMPDIR}/.bashrc"
touch "${BATS_TMPDIR}/.zshrc"

assert_file_exists "${BATS_TMPDIR}/.bashrc"
assert_file_exists "${BATS_TMPDIR}/.zshrc"
}

_delete_dir_file() {
# Remove the files created during the test
rm -f "${BATS_TMPDIR}/.bashrc" "${BATS_TMPDIR}/.zshrc"
}
15 changes: 15 additions & 0 deletions .devcontainer/tests/build_devcontainer_ci.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash
set -e
# Define devcontainer configuration directory
devcontainer_dir=".devcontainer"

# Define configuration file path
config_file="devcontainer.json"

# Build the devcontainer
devcontainer build \
--workspace-folder . \
--config $devcontainer_dir/$config_file



50 changes: 50 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Basic ignores
**/target/*
**/build/*
**/.git
**/.github
**/.vscode
**/.DS_Store
**/node_modules
**/dist
**/pnpm-lock.yaml

# Editor specific
.idea/

Dockerfile
.dockerignore
node_modules
npm-debug.log
dist
.git
.gitignore
.github

# Logs
*.log

# Temporary files
*.tmp
*.temp
*.swp
*.swo
*.bak
*.old

# Editor directories and files
.vscode/
*.code-workspace

# OS-specific files
.DS_Store
Thumbs.db

.env
.devpod-internal
build-devcontainer.sh
z-dc-build-info/*
devcontainer.md
assets/
.run/
.zshrc
88 changes: 88 additions & 0 deletions .github/workflows/build-and-test-devcontainer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
name: Build and Test DevContainer

on:
push:
paths:
- '.devcontainer/'
pull_request:
paths:
- '.devcontainer/'
workflow_dispatch:

jobs:
shellcheck-and-test:

name: Shellcheck linting
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup PATH
run: |
echo ::notice title={Setup Permissions}::{Add permissions to .devcontainers/}
chmod -R +rwx .devcontainer

echo ::notice title={Setup Workspace}::{Add .devcontainers/ to PATH}
echo "${{github.workspace}}/.devcontainer" >> "$GITHUB_PATH"
echo "${{github.workspace}}/.devcontainer/tests" >> "$GITHUB_PATH"

- name: Run ShellCheck
uses: ludeeus/action-shellcheck@00cae500b08a931fb5698e11e79bfbd38e612a38
env:
SHELLCHECK_OPTS: -s bash
with:
format: tty
severity: error
additional_files: post_start_cli_autocomplete.sh
scandir: "${{github.workspace}}/.devcontainer"
continue-on-error: true

- name: Setup Bats and bats libs
id: setup-bats
uses: bats-core/bats-action@42fcc8700f773c075a16a90eb11674c0318ad507

- name: Test Devcontainer scripts
shell: bash
env:
BATS_LIB_PATH: ${{ steps.setup-bats.outputs.lib-path }}
run: bats .devcontainer/post_start_cli_autocomplete_test.bats

build-with-devcontainer-cli:
name: Devcontainer CLI Build and Push Cache
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup PATH
run: |
echo ::notice title={Setup Permissions}::{Add permissions to .devcontainers/}
chmod -R +rwx .devcontainer

echo ::notice title={Setup Workspace}::{Add .devcontainers/ to PATH}
echo "${{github.workspace}}/.devcontainer" >> "$GITHUB_PATH"
echo "${{github.workspace}}/.devcontainer/tests" >> "$GITHUB_PATH"

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20.x'
- run: npm install -g @devcontainers/cli
working-directory: ${{ github.workspace }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
buildkitd-flags: true
cache-binary: 'true'

- name: Test Devcontainer CLI Build
run: |
echo ::notice title={Building with Devcontainer CLI}::{Building Devcontainer}

chmod +x ${{github.workspace}}/.devcontainer/tests/build_devcontainer_ci.sh
${{github.workspace}}/.devcontainer/tests/build_devcontainer_ci.sh

echo "### Devcontainer CLI Build Successful!!! :rocket:" >> $GITHUB_STEP_SUMMARY
env:
BUILDKIT_INLINE_CACHE: 1
working-directory: ${{github.workspace}}
Loading