Skip to content
This repository has been archived by the owner on Feb 1, 2024. It is now read-only.

Commit

Permalink
Add version support (#817)
Browse files Browse the repository at this point in the history
* add version support

Signed-off-by: Jasti Sri Radhe Shyam <radheshyam.jasti@zeeve.io>

* add support for versions and code search params in palyground URL

Signed-off-by: Jasti Sri Radhe Shyam <radheshyam.jasti@zeeve.io>

* state management fix for versiom and backend test

Signed-off-by: Jasti Sri Radhe Shyam <radheshyam.jasti@zeeve.io>

* - change version on click
- add routing with version number in backend

Signed-off-by: Jasti Sri Radhe Shyam <radheshyam.jasti@zeeve.io>

* add docker compiler file

Signed-off-by: Jasti Sri Radhe Shyam <radheshyam.jasti@zeeve.io>

* more precise ink version locking

Signed-off-by: Jasti Sri Radhe Shyam <radheshyam.jasti@zeeve.io>

* fix fmt and add multi-version docker calls support in backend

Signed-off-by: Jasti Sri Radhe Shyam <radheshyam.jasti@zeeve.io>

* update cspell version

Signed-off-by: Jasti Sri Radhe Shyam <radheshyam.jasti@zeeve.io>

* modify frontend version route to access frontend dir from args

Signed-off-by: Jasti Sri Radhe Shyam <radheshyam.jasti@zeeve.io>

* - fix inconsistent version update on UI
- add ink compiler scripts

Signed-off-by: Jasti Sri Radhe Shyam <radheshyam.jasti@zeeve.io>

* fix rust and js formating issues

Signed-off-by: Jasti Sri Radhe Shyam <radheshyam.jasti@zeeve.io>

* fix rust github workflow and playground test

Signed-off-by: Jasti Sri Radhe Shyam <radheshyam.jasti@zeeve.io>

* modify to build lastest complier using versions list and it's corresponding dockerfile

Signed-off-by: Jasti Sri Radhe Shyam <radheshyam.jasti@zeeve.io>

---------

Signed-off-by: Jasti Sri Radhe Shyam <radheshyam.jasti@zeeve.io>
  • Loading branch information
radhe-zeeve committed Feb 1, 2024
1 parent beaace9 commit c9c7c14
Show file tree
Hide file tree
Showing 42 changed files with 858 additions and 69 deletions.
6 changes: 4 additions & 2 deletions .cspell.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.1",
"version": "0.2",
"language": "en",
"ignorePaths": [
"**/contract/target/**",
Expand All @@ -19,7 +19,8 @@
"crates/rust_analyzer_wasm/webdriver.json",
"sysbox/*",
"config/data/*",
"*.svg"
"*.svg",
"docker/*"
],
"words": [
"dcdd",
Expand Down Expand Up @@ -74,6 +75,7 @@
"rlib",
"cdylib",
"achimcc",
"radhezeeve",
"prefill",
"deserialization",
"filesets",
Expand Down
13 changes: 10 additions & 3 deletions .github/workflows/compiler_docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,15 @@ jobs:
steps:
- uses: actions/checkout@v3

- name: Install jq
run: sudo apt -y install jq

- name: Get last Ink version
id: version_info
run: echo "latest_ink_version=$(jq -r '.[0]' ./config/versions.json)" >> $GITHUB_OUTPUT

- name: Build docker
run: docker build -f Dockerfile.compiler --tag ink-compiler .
run: docker build -f ./docker/Dockerfile.compiler-${{ steps.version_info.outputs.latest_ink_version }} --tag ink-compiler:${{ steps.version_info.outputs.latest_ink_version }} ./docker

- name: Login to DockerHub
if: github.ref == 'refs/heads/main' && github.repository == 'paritytech/ink-playground'
Expand All @@ -24,8 +31,8 @@ jobs:

- name: Tag Docker image
if: github.ref == 'refs/heads/main' && github.repository == 'paritytech/ink-playground'
run: docker tag ink-compiler:latest ${{ secrets.DOCKER_USER_NAME }}/ink-compiler
run: docker tag ink-compiler:${{ steps.version_info.outputs.latest_ink_version }} ${{ secrets.DOCKER_USER_NAME }}/ink-compiler:${{ steps.version_info.outputs.latest_ink_version }}

- name: Push Docker image
if: github.ref == 'refs/heads/main' && github.repository == 'paritytech/ink-playground'
run: docker push ${{ secrets.DOCKER_USER_NAME }}/ink-compiler
run: docker push ${{ secrets.DOCKER_USER_NAME }}/ink-compiler:${{ steps.version_info.outputs.latest_ink_version }}
5 changes: 4 additions & 1 deletion .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@ jobs:
- name: Tag Docker image
run: docker tag achimcc/ink-playground:latest ink-playground

- name: Add single version to versions list (storage limitation of github actions)
run: echo "[\"4.2.0\"]" > ./config/versions.json

- name: Run docker
run: make docker-run-detach
run: DOCKER_CI_VOLUME_MOUNT="--volume ./config/versions.json:/app/config/versions.json" make docker-run-detach
env:
DOCKER_PORT: 4000

Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ jobs:
- name: Build
run: cargo build --verbose
- name: Pull docker image
run: docker pull docker.io/achimcc/ink-compiler:latest
- name: Tag docker image
run: docker tag docker.io/achimcc/ink-compiler:latest ink-compiler
run: ./scripts/ink-compiler.sh -c pull_specific --specific_version 4.2.0 --docker_user_name radhezeeve
- name: Run tests
run: cargo test --workspace --exclude rust_analyzer_wasm --verbose
15 changes: 12 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,15 @@ FROM base as frontend-builder

RUN apt-get --yes update
RUN apt-get --yes upgrade
RUN apt-get install --yes nodejs npm

ENV NVM_DIR /usr/local/nvm
ENV NODE_VERSION v18.16.1
RUN mkdir -p /usr/local/nvm && apt-get update && echo "y" | apt-get install curl
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
RUN /bin/bash -c "source $NVM_DIR/nvm.sh && nvm install $NODE_VERSION && nvm use --delete-prefix $NODE_VERSION"
ENV NODE_PATH $NVM_DIR/versions/node/$NODE_VERSION/bin
ENV PATH $NODE_PATH:$PATH

RUN npm install --global yarn
RUN make install

Expand Down Expand Up @@ -98,6 +106,8 @@ FROM debian:bullseye-slim

COPY --from=frontend-builder /app/packages/playground/dist /app/packages/playground/dist
COPY --from=backend-builder /app/target/release/backend /app/target/release/backend
COPY ./scripts /app/scripts
COPY ./config/versions.json /app/config/versions.json

# Install Docker
# see: https://www.how2shout.com/linux/install-docker-ce-on-debian-11-bullseye-linux/
Expand All @@ -117,10 +127,9 @@ RUN echo \
RUN apt-get --yes update

RUN apt-get --yes install docker-ce docker-ce-cli \
containerd.io
containerd.io jq

# Provide startup scripts

COPY sysbox/on-start.sh /usr/bin
RUN chmod +x /usr/bin/on-start.sh

Expand Down
12 changes: 11 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ FORMATTING_URL ?= http://localhost:4000/format

ANALYTICS_URL ?= https://api-sa.substrate.io

DOCKER_USER_NAME ?= achimcc
VERSION_LIST_URL ?= http://localhost:4000/version_list

DOCKER_USER_NAME ?= radhezeeve

DOCKER_CI_VOLUME_MOUNT ?=

################################################################################
# GENERATE
Expand Down Expand Up @@ -63,6 +67,7 @@ playground-build:
GIST_LOAD_URL=/gist/load \
GIST_CREATE_URL=/gist/create \
ANALYTICS_URL=$(ANALYTICS_URL) \
VERSION_LIST_URL=/version_list \
yarn workspace playground run build

playground-start:
Expand All @@ -72,6 +77,7 @@ playground-start:
GIST_LOAD_URL=$(GIST_LOAD_URL) \
GIST_CREATE_URL=$(GIST_CREATE_URL) \
ANALYTICS_URL=$(ANALYTICS_URL) \
VERSION_LIST_URL=$(VERSION_LIST_URL) \
yarn workspace playground run start

playground-clean:
Expand Down Expand Up @@ -248,6 +254,7 @@ docker-run-detach:
--name ink-playground-container \
--detach \
--volume /tmp:/tmp \
$(DOCKER_CI_VOLUME_MOUNT) \
--publish $(DOCKER_PORT):4000 \
ink-playground

Expand All @@ -266,6 +273,9 @@ docker-shell:
docker-log:
docker logs ink-playground-container

docker-pull-images:
./scripts/ink-compiler.sh -c pull --docker_user_name ${DOCKER_USER_NAME}

################################################################################
# GLOBAL
################################################################################
Expand Down
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,13 @@ To clone and build the whole project on your local computer, enter:

5. `make build`

Then pull and tag the docker image which is used by the backend to compile, test & format Smart Contracts:
Then pull and tag the docker images which are used by the backend to compile, test & format Smart Contracts:

6. `docker pull achimcc/ink-compiler`

7. `docker tag achimcc/ink-compiler ink-compiler`
6. `make docker-pull-images`

Finally, start the backend with:

6. `make backend-run`
7. `make backend-run`

The last command starts the Rust webserver locally on your computer. You can then access `localhost:4000` from your browser to open the locally compiled ink! Playground open.

Expand Down
1 change: 1 addition & 0 deletions config/versions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
["4.3.0", "4.2.1", "4.2.0", "4.1.0", "4.0.1", "4.0.0"]
7 changes: 7 additions & 0 deletions crates/backend/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ pub struct Opts {
#[arg(short = 'f', long = "frontend_folder")]
pub frontend_folder: Option<String>,

#[arg(
long = "versions_file_path",
default_value = "./config/versions.json",
env = "VERSIONS_FILE_PATH"
)]
pub versions_file_path: String,

#[arg(short = 'g', long = "github_token", env = "GITHUB_GIST_TOKEN")]
pub github_token: Option<String>,

Expand Down
28 changes: 26 additions & 2 deletions crates/backend/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,19 @@ use crate::{
FORMAT_SANDBOXED,
TEST_SANDBOXED,
},
frontend::route_frontend,
frontend::{
route_frontend,
route_frontend_version,
FrontendState,
},
gist::{
create::route_gist_create,
load::route_gist_load,
},
version::{
route_version_list,
AppVersionState,
},
},
};
use actix_cors::Cors;
Expand Down Expand Up @@ -71,6 +79,10 @@ async fn main() -> std::io::Result<()> {
}
}

if !Path::new(&opts.versions_file_path.clone()).is_file() {
panic!("{} is not a valid file.", opts.versions_file_path);
}

async fn health() -> HttpResponse {
HttpResponse::Ok().finish()
}
Expand All @@ -86,6 +98,7 @@ async fn main() -> std::io::Result<()> {
HttpServer::new(move || {
let opts: Opts = opts.clone();
let frontend_folder = opts.frontend_folder.clone();
let versions_file_path = opts.versions_file_path.clone();

let mut app = App::new()
.wrap(prometheus.clone())
Expand All @@ -112,6 +125,12 @@ async fn main() -> std::io::Result<()> {
.route(
"/status",
get().to(route_status),
)
.app_data(web::Data::new(AppVersionState {
versions_file_path,
}))
.service(
web::resource("/version_list").to(route_version_list)
);

match opts.github_token {
Expand Down Expand Up @@ -139,7 +158,12 @@ async fn main() -> std::io::Result<()> {

match frontend_folder {
Some(path) => {
app = app.service(route_frontend("/", path.as_ref()));
app = app
.app_data(web::Data::new(FrontendState {
frontend_folder: path.clone(),
}))
.route("/v{tail:.*}", web::get().to(route_frontend_version))
.service(route_frontend("/", path.as_ref()));
}
None => {
println!("Warning: Starting backend without serving static frontend files due to missing configuration.")
Expand Down
7 changes: 7 additions & 0 deletions crates/backend/src/services/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ pub async fn route_compile(
let compile_result = spawn_blocking(move || {
compile_strategy(CompilationRequest {
source: req.source.to_string(),
version: req.version.to_string(),
})
})
.await
Expand Down Expand Up @@ -103,6 +104,7 @@ pub async fn route_test(
let testing_result = spawn_blocking(move || {
compile_strategy(TestingRequest {
source: req.source.to_string(),
version: req.version.to_string(),
})
})
.await
Expand All @@ -127,6 +129,7 @@ pub async fn route_format(
let formatting_result = spawn_blocking(move || {
formatting_strategy(FormattingRequest {
source: req.source.to_string(),
version: req.version.to_string(),
})
})
.await
Expand Down Expand Up @@ -204,6 +207,7 @@ mod tests {

let req = CompilationRequest {
source: "foo".to_string(),
version: "4.2.0".to_string(),
};
let req = test::TestRequest::post()
.set_json(&req)
Expand Down Expand Up @@ -234,6 +238,7 @@ mod tests {

let req = CompilationRequest {
source: "bar".to_string(),
version: "4.2.0".to_string(),
};

let req = test::TestRequest::post()
Expand Down Expand Up @@ -264,6 +269,7 @@ mod tests {

let req = TestingRequest {
source: "foo".to_string(),
version: "1.0.0".to_string(),
};
let req = test::TestRequest::post()
.set_json(&req)
Expand Down Expand Up @@ -293,6 +299,7 @@ mod tests {

let req = TestingRequest {
source: "bar".to_string(),
version: "1.0.0".to_string(),
};
let req = test::TestRequest::post()
.set_json(&req)
Expand Down
17 changes: 17 additions & 0 deletions crates/backend/src/services/frontend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,28 @@
//! This module contains the service which serves the backend as static files.

use actix_files as fs;
use actix_web::{
web,
Result,
};
use std::path::Path;

pub struct FrontendState {
pub frontend_folder: String,
}

pub fn route_frontend(at: &str, dir: &str) -> actix_files::Files {
fs::Files::new(at, dir).index_file("index.html")
}

pub async fn route_frontend_version(
data: web::Data<FrontendState>,
) -> Result<actix_files::NamedFile> {
Ok(fs::NamedFile::open(
Path::new(&data.frontend_folder).join("index.html"),
)?)
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
1 change: 1 addition & 0 deletions crates/backend/src/services/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@
pub mod contract;
pub mod frontend;
pub mod gist;
pub mod version;
39 changes: 39 additions & 0 deletions crates/backend/src/services/version.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
use std::fs;

use actix_web::{
body::BoxBody,
web,
HttpResponse,
};

pub use sandbox::VersionListResult;
use serde_json::{
json,
Value,
};

pub struct AppVersionState {
pub versions_file_path: String,
}

fn read_json_file(file_path: &str) -> Result<String, std::io::Error> {
fs::read_to_string(file_path)
}

pub async fn route_version_list(
data: web::Data<AppVersionState>,
) -> HttpResponse<BoxBody> {
let versions_file_path = &data.versions_file_path;
let versions_arr_string = read_json_file(versions_file_path).unwrap();
let versions_arr_json: Value =
serde_json::from_str(versions_arr_string.as_str()).expect("Failed to parse JSON");
let versions_json = json!({
"versions": versions_arr_json
});
let versions_json_string =
serde_json::to_string_pretty(&versions_json).expect("Failed to stringify JSON");

HttpResponse::Ok()
.append_header(("Content-Type", "application/json"))
.body(versions_json_string)
}
Loading

0 comments on commit c9c7c14

Please sign in to comment.