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

Feature/adds development container #32

Merged
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
27 changes: 27 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

ARG VARIANT="bullseye"

FROM mcr.microsoft.com/devcontainers/base:$VARIANT

ARG VARIANT

ARG WASI_VERSION="16"

ENV WASI_VERSION_FULL=${WASI_VERSION}.0

# [Optional] Uncomment this section to install additional packages.
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
# && apt-get -y install --no-install-recommends <your-package-list-here>

# Install WASI-SDK
RUN cd /tmp \
&& wget https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-${WASI_VERSION}/wasi-sdk-${WASI_VERSION_FULL}-linux.tar.gz \
&& tar xvf wasi-sdk-${WASI_VERSION_FULL}-linux.tar.gz \
&& sudo cp -r wasi-sdk-${WASI_VERSION_FULL} /opt/wasi-sdk \
&& cd -

# Install Spin
RUN cd /tmp \
mikkelhegn marked this conversation as resolved.
Show resolved Hide resolved
&& curl -fsSL https://developer.fermyon.com/downloads/install.sh | bash \
&& sudo mv ./spin /usr/local/bin/spin \
&& cd -
55 changes: 55 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/ubuntu
{
"name": "Ubuntu",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"build": {
"context": "../",
"dockerfile": "Dockerfile",
"args": {
"VARIANT": "jammy",
"WASI_VERSION": "16",
}
},
"features": {
"ghcr.io/devcontainers/features/python:1": {
"installTools": true,
"version": "3.11"
},
"ghcr.io/devcontainers/features/rust:1": {
"version": "latest",
"profile": "minimal"
}
},
"customizations": {
"vscode": {
"settings": {
"lldb.executable": "/usr/bin/lldb",
// VS Code don't watch files under ./target
"files.watcherExclude": {
"**/target/**": true
},
"rust-analyzer.checkOnSave.command": "clippy"
},
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"vadimcn.vscode-lldb",
"mutantdino.resourcemonitor",
"matklad.rust-analyzer",
"tamasfe.even-better-toml",
"serayuzgur.crates"
]
}
},
// 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": [],
"onCreateCommand": ".devcontainer/onCreateCommands.sh",
// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "uname -a",
// Configure tool-specific properties.
// "customizations": {},
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
}
28 changes: 28 additions & 0 deletions .devcontainer/onCreateCommands.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash

set -ex
ARTIFACT_PY_VERSION="3.11.4"
ARTIFACT_SDK_VERSION="16"


# Install rust components
rustup update stable
rustup default stable
rustup component add clippy rustfmt
rustup target add wasm32-wasi wasm32-unknown-unknown

# Fetch WASI compiled cPython artifact
mkdir -p cpython/builddir/wasi/install

cd cpython/builddir/wasi/install
wget https://github.com/brettcannon/cpython-wasi-build/releases/download/v${ARTIFACT_PY_VERSION}/python-${ARTIFACT_PY_VERSION}-wasi_sdk-${ARTIFACT_SDK_VERSION}.zip
unzip python-${ARTIFACT_PY_VERSION}-wasi_sdk-${ARTIFACT_SDK_VERSION}.zip

cd -
cd cpython/builddir/wasi
wget https://github.com/brettcannon/cpython-wasi-build/releases/download/v${ARTIFACT_PY_VERSION}/_build-python-${ARTIFACT_PY_VERSION}-wasi_sdk-${ARTIFACT_SDK_VERSION}.zip
unzip _build-python-${ARTIFACT_PY_VERSION}-wasi_sdk-${ARTIFACT_SDK_VERSION}.zip
cd -

# Make Spin Python SDK
make
mikkelhegn marked this conversation as resolved.
Show resolved Hide resolved
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,29 @@ spin up
## Building and Running

### Prerequisites
__Note__: When using the devcontainer for development, the following dependencies are already installed for you. To prevent speed up build times and prevent compatibility issues, a pre-compiled artifact of cpython for wasi is used rather than compiling from source. (https://github.com/brettcannon/cpython-wasi-build/releases/tag/v3.11.4)

- [WASI SDK](https://github.com/WebAssembly/wasi-sdk) v16 or later, installed in /opt/wasi-sdk
- [CPython](https://github.com/python/cpython) build prereqs (e.g. Make, Clang, etc.)
- [Rust](https://rustup.rs/) (including `wasm32-wasi` target)
- [Spin](https://github.com/fermyon/spin)
- [pipenv](https://pypi.org/project/pipenv/) for installing Python project dependencies


### Instructions

First, build CPython for wasm32-wasi.
First, perform a git submodule update to update the cpython submodule. **(Unnecessary if using devcontainer)**
```bash
git submodule update --init --recursive
```

Then, build CPython for wasm32-wasi. **(Unnecessary if using devcontainer)**

```bash
./build-python.sh
```

Then, build the `spin-python-cli`:
Then, build the `spin-python-cli`: **(Unnecessary if using devcontainer)**

```bash
make
Expand Down