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

Added dev environment for vscode/docker/gitpod #971

Merged
merged 13 commits into from
Jul 19, 2022
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
182 changes: 182 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
FROM ubuntu:focal

ENV RUSTUP_HOME=/usr/local/rustup \
CARGO_HOME=/usr/local/cargo \
PATH=/usr/local/cargo/bin:$PATH \
RUST_VERSION=1.62.0

RUN apt-get update && \
apt-get install -y --no-install-recommends \
#### Base utilities ####
wget \
ca-certificates \
&& rm -rf /var/lib/apt/lists/*

ENV dpkgArch=amd64
ENV rustArch='x86_64-unknown-linux-gnu'
ENV rustupSha256='3dc5ef50861ee18657f9db2eeb7392f9c2a6c95c90ab41e45ab4ca71476b4338'

RUN set -eux; \
url="https://static.rust-lang.org/rustup/archive/1.24.3/${rustArch}/rustup-init"; \
wget "$url" --no-check-certificate; \
echo "${rustupSha256} *rustup-init" | sha256sum -c -; \
chmod +x rustup-init; \
./rustup-init -y --no-modify-path --profile minimal --default-toolchain $RUST_VERSION --default-host ${rustArch}; \
rm rustup-init; \
chmod -R a+w $RUSTUP_HOME $CARGO_HOME; \
rustup --version; \
cargo --version; \
rustc --version;

# ENV PATH="/root/.cargo/bin:$PATH"

ENV GOROOT=/usr/local/go
ENV GOPATH=/go/
ENV PATH=$PATH:/usr/local/go/bin:$GOPATH/bin
ENV GO111MODULE=auto

# Use the [Option] comment to specify true/false arguments that should appear in VS Code UX
#
# [Option] Install zsh
ARG INSTALL_ZSH="true"
# [Option] Upgrade OS packages to their latest versions
ARG UPGRADE_PACKAGES="false"

# Install needed packages and setup non-root user. Use a separate RUN statement to add your own dependencies.
ARG USERNAME=vscode
ARG USER_UID=1000
ARG USER_GID=$USER_UID

ENV USER_HOME=/home/${USERNAME}

# ENV CARGO_HOME=${USER_HOME}/.cargo/bin
# ENV PATH="${CARGO_HOME}:$PATH"

# ENV RUSTUP_HOME=${USER_HOME}/.cargo/bin


COPY .devcontainer/library-scripts/*.sh .devcontainer/library-scripts/*.env /tmp/library-scripts/
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
&& /bin/bash /tmp/library-scripts/common-debian.sh "${INSTALL_ZSH}" "${USERNAME}" "${USER_UID}" "${USER_GID}" "${UPGRADE_PACKAGES}" "true" "true"
#
# ****************************************************************************
# * TODO: Add any additional OS packages you want included in the definition *
# * here. We want to do this before cleanup to keep the "layer" small. *
# ****************************************************************************
# && apt-get -y install --no-install-recommends <your-package-list-here> \
# USER $USERNAME

# Install rust as non-root user
# RUN curl https://sh.rustup.rs -sSf | bash -s -- -y

# USER root

RUN bash /tmp/library-scripts/rust-debian.sh "${CARGO_HOME}" "${RUSTUP_HOME}" "${USERNAME}" "true" "true"

# Install Go
#ADD https://go.dev/dl/go1.18.4.linux-amd64.tar.gz go1.18.4.linux-amd64.tar.gz
#RUN tar -C /usr/local -xzf go1.18.4.linux-amd64.tar.gz
#
#RUN mkdir -p "$GOPATH/src" "$GOPATH/bin" "$GOPATH/pkg" && chmod -R 777 "$GOPATH"
#RUN chown ${USERNAME}:${USERNAME} /go -R

RUN bash /tmp/library-scripts/go-debian.sh "1.18.4" "${GOROOT}" "${GOPATH}" "${USERNAME}" "true" "true" && \
go install github.com/jteeuwen/go-bindata/go-bindata@latest && go-bindata -version

RUN apt-get autoremove -y && apt-get clean -y && rm -rf /var/lib/apt/lists/* /tmp/library-scripts

# [Optional] Uncomment this section to install additional OS packages.
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
# && apt-get -y install --no-install-recommends <your-package-list-here>
RUN wget -q https://github.com/WebAssembly/wabt/releases/download/1.0.20/wabt-1.0.20-ubuntu.tar.gz && \
tar -xf wabt-1.0.20-ubuntu.tar.gz wabt-1.0.20/bin/wat2wasm wabt-1.0.20/bin/wasm2wat && \
mv wabt-1.0.20/bin/wat2wasm wabt-1.0.20/bin/wasm2wat /bin && \
chmod +x /bin/wat2wasm /bin/wasm2wat && \
rm -f wabt-1.0.20-ubuntu.tar.gz

USER root

# SGX version parameters
ARG SGX_VERSION=2.12.100.3
ARG OS_REVESION=focal1

# RUN echo "deb http://deb.debian.org/debian bullseye-backports main" | sudo tee /etc/apt/sources.list.d/bullseye-backports.list

RUN apt-get update && \
apt-get install -y --no-install-recommends \
#### Base utilities ####
gdebi \
libprotobuf17 \
autoconf \
libtool \
automake \
clang \
#### SGX installer dependencies ####
g++ make libcurl4 libssl1.1 && \
rm -rf /var/lib/apt/lists/*


#RUN wget -O /tmp/libprotobuf10_3.0.0-9_amd64.deb http://ftp.br.debian.org/debian/pool/main/p/protobuf/libprotobuf10_3.0.0-9_amd64.deb
#RUN yes | gdebi /tmp/libprotobuf10_3.0.0-9_amd64.deb

WORKDIR /root

# Must create /etc/init or enclave-common install will fail
RUN mkdir /etc/init && \
mkdir sgx

# SGX Binaries
ARG SGX_VERSION=2.12.100.3
ARG OS_REVESION=focal1

##### Install SGX Binaries ######
ADD https://download.01.org/intel-sgx/sgx-linux/2.12/distro/ubuntu20.04-server/debian_pkgs/libs/libsgx-enclave-common/libsgx-enclave-common_${SGX_VERSION}-${OS_REVESION}_amd64.deb ./sgx/
ADD https://download.01.org/intel-sgx/sgx-linux/2.12/distro/ubuntu20.04-server/debian_pkgs/libs/libsgx-urts/libsgx-urts_${SGX_VERSION}-${OS_REVESION}_amd64.deb ./sgx/
ADD https://download.01.org/intel-sgx/sgx-linux/2.12/distro/ubuntu20.04-server/debian_pkgs/libs/libsgx-uae-service/libsgx-uae-service_${SGX_VERSION}-${OS_REVESION}_amd64.deb ./sgx/
ADD https://download.01.org/intel-sgx/sgx-linux/2.12/distro/ubuntu20.04-server/debian_pkgs/libs/libsgx-quote-ex/libsgx-quote-ex_${SGX_VERSION}-${OS_REVESION}_amd64.deb ./sgx/
ADD https://download.01.org/intel-sgx/sgx-linux/2.12/distro/ubuntu20.04-server/debian_pkgs/libs/libsgx-epid/libsgx-epid_${SGX_VERSION}-${OS_REVESION}_amd64.deb ./sgx/
ADD https://download.01.org/intel-sgx/sgx-linux/2.12/distro/ubuntu20.04-server/debian_pkgs/libs/libsgx-launch/libsgx-launch_${SGX_VERSION}-${OS_REVESION}_amd64.deb ./sgx/


RUN dpkg -i ./sgx/libsgx-enclave-common_${SGX_VERSION}-${OS_REVESION}_amd64.deb && \
dpkg -i ./sgx/libsgx-urts_${SGX_VERSION}-${OS_REVESION}_amd64.deb && \
dpkg -i ./sgx/libsgx-launch_${SGX_VERSION}-${OS_REVESION}_amd64.deb && \
dpkg -i ./sgx/libsgx-epid_${SGX_VERSION}-${OS_REVESION}_amd64.deb && \
dpkg -i ./sgx/libsgx-quote-ex_${SGX_VERSION}-${OS_REVESION}_amd64.deb && \
dpkg -i ./sgx/libsgx-uae-service_${SGX_VERSION}-${OS_REVESION}_amd64.deb

ADD https://download.01.org/intel-sgx/sgx-linux/2.12/distro/ubuntu20.04-server/sgx_linux_x64_sdk_${SGX_VERSION}.bin ./sgx/
# ADD https://download.01.org/intel-sgx/sgx-linux/2.12/distro/ubuntu20.04-server/sgx_linux_x64_driver_2.11.0_4505f07.bin ./sgx/

RUN chmod +x ./sgx/sgx_linux_x64_sdk_${SGX_VERSION}.bin
RUN echo -e 'no\n/opt' | ./sgx/sgx_linux_x64_sdk_${SGX_VERSION}.bin && \
echo 'source /opt/sgxsdk/environment' >> /etc/bash.bashrc && \
echo 'export SGX_MODE=SW' >> /etc/bash.bashrc \
rm -rf ./sgx/*

# ENV LD_LIBRARY_PATH=/opt/sgxsdk/libsgx-enclave-common/

RUN echo 'export SCRT_ENCLAVE_DIR=/home/vscode/SecretNetwork/go-cosmwasm/' >> /etc/bash.bashrc

USER $USERNAME

WORKDIR ${USER_HOME}

RUN cargo install xargo --version 0.3.25
RUN git clone https://github.com/scrtlabs/SecretNetwork.git

WORKDIR ${USER_HOME}/SecretNetwork

# USER root
# get rust
RUN rustup target add wasm32-unknown-unknown && rustup component add rust-src rust-analysis clippy
USER root
# fuck you permissions
RUN chown $USERNAME:$USERNAME /go -R

# '-l': see https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#user
RUN useradd -l -u 33333 -G sudo -md /home/gitpod -s /bin/bash -p gitpod gitpod \
# passwordless sudo for users in the 'sudo' group
&& sed -i.bkp -e 's/%sudo\s\+ALL=(ALL\(:ALL\)\?)\s\+ALL/%sudo ALL=NOPASSWD:ALL/g' /etc/sudoers \
# To emulate the workspace-session behavior within dazzle build env
&& mkdir /workspace && chown -hR gitpod:gitpod /workspace
67 changes: 67 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
"name": "Secret Network Core Dev Environment",

// Update the 'dockerFile' property if you aren't using the standard 'Dockerfile' filename.
"build": {
"dockerfile": "Dockerfile",
// [Optional] You can use build args to set options. e.g. 'VARIANT' below affects the image in the Dockerfile
// "args": { "VARIANT": "buster" }
"args": {
"NODE_VERSION": "lts/*"
}
},

// Set *default* container specific settings.json values on container create.
"settings": {},

// Add the IDs of extensions you want installed when the container is created.
"workspaceFolder": "/home/vscode/SecretNetwork",
"extensions": [
"bungcip.better-toml",
"rust-lang.rust-analyzer",
"golang.Go"
],

"customizations": {
"vscode": {
// Set *default* container specific settings.json values on container create.
"settings": {
"go.toolsManagement.checkForUpdates": "local",
"go.useLanguageServer": true,
"go.gopath": "/go",
"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",
"rust-lang.rust-analyzer",
"tamasfe.even-better-toml",
"serayuzgur.crates",
"golang.Go"
]
}
},


// 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": "uname -a",

// Uncomment to use Docker from inside the container. See https://aka.ms/vscode-remote/samples/docker-from-docker.
// "mounts": [ "source=/var/run/docker.sock,target=/var/run/docker.sock,type=bind" ],

// Uncomment when using a ptrace-based debugger like C++, Go, and Rust
"runArgs": [ "--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined" ],

// Comment out to connect as root instead. To add a non-root user, see: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "vscode"
}
7 changes: 7 additions & 0 deletions .devcontainer/library-scripts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Warning: Folder contents may be replaced

The contents of this folder will be automatically replaced with a file of the same name in the [vscode-dev-containers](https://github.com/microsoft/vscode-dev-containers) repository's [script-library folder](https://github.com/microsoft/vscode-dev-containers/tree/main/script-library) whenever the repository is packaged. To retain your edits, move the file to a different location. You may also delete the files if they are not needed.

## Adding a new script from the script-library folder

When creating a dev container for the vscode-dev-containers repository, simply drop a copy of the script you want to use from the [script-library folder](https://github.com/microsoft/vscode-dev-containers/tree/main/script-library) into this folder and it will be automatically kept up to date as things change.
Loading