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

Commit c9c7c14

Browse files
authored
Add version support (#817)
* add version support Signed-off-by: Jasti Sri Radhe Shyam <[email protected]> * add support for versions and code search params in palyground URL Signed-off-by: Jasti Sri Radhe Shyam <[email protected]> * state management fix for versiom and backend test Signed-off-by: Jasti Sri Radhe Shyam <[email protected]> * - change version on click - add routing with version number in backend Signed-off-by: Jasti Sri Radhe Shyam <[email protected]> * add docker compiler file Signed-off-by: Jasti Sri Radhe Shyam <[email protected]> * more precise ink version locking Signed-off-by: Jasti Sri Radhe Shyam <[email protected]> * fix fmt and add multi-version docker calls support in backend Signed-off-by: Jasti Sri Radhe Shyam <[email protected]> * update cspell version Signed-off-by: Jasti Sri Radhe Shyam <[email protected]> * modify frontend version route to access frontend dir from args Signed-off-by: Jasti Sri Radhe Shyam <[email protected]> * - fix inconsistent version update on UI - add ink compiler scripts Signed-off-by: Jasti Sri Radhe Shyam <[email protected]> * fix rust and js formating issues Signed-off-by: Jasti Sri Radhe Shyam <[email protected]> * fix rust github workflow and playground test Signed-off-by: Jasti Sri Radhe Shyam <[email protected]> * modify to build lastest complier using versions list and it's corresponding dockerfile Signed-off-by: Jasti Sri Radhe Shyam <[email protected]> --------- Signed-off-by: Jasti Sri Radhe Shyam <[email protected]>
1 parent beaace9 commit c9c7c14

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+858
-69
lines changed

.cspell.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "0.1",
2+
"version": "0.2",
33
"language": "en",
44
"ignorePaths": [
55
"**/contract/target/**",
@@ -19,7 +19,8 @@
1919
"crates/rust_analyzer_wasm/webdriver.json",
2020
"sysbox/*",
2121
"config/data/*",
22-
"*.svg"
22+
"*.svg",
23+
"docker/*"
2324
],
2425
"words": [
2526
"dcdd",
@@ -74,6 +75,7 @@
7475
"rlib",
7576
"cdylib",
7677
"achimcc",
78+
"radhezeeve",
7779
"prefill",
7880
"deserialization",
7981
"filesets",

.github/workflows/compiler_docker.yml

+10-3
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,15 @@ jobs:
1212
steps:
1313
- uses: actions/checkout@v3
1414

15+
- name: Install jq
16+
run: sudo apt -y install jq
17+
18+
- name: Get last Ink version
19+
id: version_info
20+
run: echo "latest_ink_version=$(jq -r '.[0]' ./config/versions.json)" >> $GITHUB_OUTPUT
21+
1522
- name: Build docker
16-
run: docker build -f Dockerfile.compiler --tag ink-compiler .
23+
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
1724

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

2532
- name: Tag Docker image
2633
if: github.ref == 'refs/heads/main' && github.repository == 'paritytech/ink-playground'
27-
run: docker tag ink-compiler:latest ${{ secrets.DOCKER_USER_NAME }}/ink-compiler
34+
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 }}
2835

2936
- name: Push Docker image
3037
if: github.ref == 'refs/heads/main' && github.repository == 'paritytech/ink-playground'
31-
run: docker push ${{ secrets.DOCKER_USER_NAME }}/ink-compiler
38+
run: docker push ${{ secrets.DOCKER_USER_NAME }}/ink-compiler:${{ steps.version_info.outputs.latest_ink_version }}

.github/workflows/docker.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,11 @@ jobs:
3232
- name: Tag Docker image
3333
run: docker tag achimcc/ink-playground:latest ink-playground
3434

35+
- name: Add single version to versions list (storage limitation of github actions)
36+
run: echo "[\"4.2.0\"]" > ./config/versions.json
37+
3538
- name: Run docker
36-
run: make docker-run-detach
39+
run: DOCKER_CI_VOLUME_MOUNT="--volume ./config/versions.json:/app/config/versions.json" make docker-run-detach
3740
env:
3841
DOCKER_PORT: 4000
3942

.github/workflows/rust.yml

+1-3
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ jobs:
5555
- name: Build
5656
run: cargo build --verbose
5757
- name: Pull docker image
58-
run: docker pull docker.io/achimcc/ink-compiler:latest
59-
- name: Tag docker image
60-
run: docker tag docker.io/achimcc/ink-compiler:latest ink-compiler
58+
run: ./scripts/ink-compiler.sh -c pull_specific --specific_version 4.2.0 --docker_user_name radhezeeve
6159
- name: Run tests
6260
run: cargo test --workspace --exclude rust_analyzer_wasm --verbose

Dockerfile

+12-3
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,15 @@ FROM base as frontend-builder
5757

5858
RUN apt-get --yes update
5959
RUN apt-get --yes upgrade
60-
RUN apt-get install --yes nodejs npm
60+
61+
ENV NVM_DIR /usr/local/nvm
62+
ENV NODE_VERSION v18.16.1
63+
RUN mkdir -p /usr/local/nvm && apt-get update && echo "y" | apt-get install curl
64+
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
65+
RUN /bin/bash -c "source $NVM_DIR/nvm.sh && nvm install $NODE_VERSION && nvm use --delete-prefix $NODE_VERSION"
66+
ENV NODE_PATH $NVM_DIR/versions/node/$NODE_VERSION/bin
67+
ENV PATH $NODE_PATH:$PATH
68+
6169
RUN npm install --global yarn
6270
RUN make install
6371

@@ -98,6 +106,8 @@ FROM debian:bullseye-slim
98106

99107
COPY --from=frontend-builder /app/packages/playground/dist /app/packages/playground/dist
100108
COPY --from=backend-builder /app/target/release/backend /app/target/release/backend
109+
COPY ./scripts /app/scripts
110+
COPY ./config/versions.json /app/config/versions.json
101111

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

119129
RUN apt-get --yes install docker-ce docker-ce-cli \
120-
containerd.io
130+
containerd.io jq
121131

122132
# Provide startup scripts
123-
124133
COPY sysbox/on-start.sh /usr/bin
125134
RUN chmod +x /usr/bin/on-start.sh
126135

Makefile

+11-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ FORMATTING_URL ?= http://localhost:4000/format
3030

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

33-
DOCKER_USER_NAME ?= achimcc
33+
VERSION_LIST_URL ?= http://localhost:4000/version_list
34+
35+
DOCKER_USER_NAME ?= radhezeeve
36+
37+
DOCKER_CI_VOLUME_MOUNT ?=
3438

3539
################################################################################
3640
# GENERATE
@@ -63,6 +67,7 @@ playground-build:
6367
GIST_LOAD_URL=/gist/load \
6468
GIST_CREATE_URL=/gist/create \
6569
ANALYTICS_URL=$(ANALYTICS_URL) \
70+
VERSION_LIST_URL=/version_list \
6671
yarn workspace playground run build
6772

6873
playground-start:
@@ -72,6 +77,7 @@ playground-start:
7277
GIST_LOAD_URL=$(GIST_LOAD_URL) \
7378
GIST_CREATE_URL=$(GIST_CREATE_URL) \
7479
ANALYTICS_URL=$(ANALYTICS_URL) \
80+
VERSION_LIST_URL=$(VERSION_LIST_URL) \
7581
yarn workspace playground run start
7682

7783
playground-clean:
@@ -248,6 +254,7 @@ docker-run-detach:
248254
--name ink-playground-container \
249255
--detach \
250256
--volume /tmp:/tmp \
257+
$(DOCKER_CI_VOLUME_MOUNT) \
251258
--publish $(DOCKER_PORT):4000 \
252259
ink-playground
253260

@@ -266,6 +273,9 @@ docker-shell:
266273
docker-log:
267274
docker logs ink-playground-container
268275

276+
docker-pull-images:
277+
./scripts/ink-compiler.sh -c pull --docker_user_name ${DOCKER_USER_NAME}
278+
269279
################################################################################
270280
# GLOBAL
271281
################################################################################

README.md

+3-5
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,13 @@ To clone and build the whole project on your local computer, enter:
6161

6262
5. `make build`
6363

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

66-
6. `docker pull achimcc/ink-compiler`
67-
68-
7. `docker tag achimcc/ink-compiler ink-compiler`
66+
6. `make docker-pull-images`
6967

7068
Finally, start the backend with:
7169

72-
6. `make backend-run`
70+
7. `make backend-run`
7371

7472
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.
7573

config/versions.json

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
["4.3.0", "4.2.1", "4.2.0", "4.1.0", "4.0.1", "4.0.0"]

crates/backend/src/cli.rs

+7
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ pub struct Opts {
2525
#[arg(short = 'f', long = "frontend_folder")]
2626
pub frontend_folder: Option<String>,
2727

28+
#[arg(
29+
long = "versions_file_path",
30+
default_value = "./config/versions.json",
31+
env = "VERSIONS_FILE_PATH"
32+
)]
33+
pub versions_file_path: String,
34+
2835
#[arg(short = 'g', long = "github_token", env = "GITHUB_GIST_TOKEN")]
2936
pub github_token: Option<String>,
3037

crates/backend/src/main.rs

+26-2
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,19 @@ use crate::{
2727
FORMAT_SANDBOXED,
2828
TEST_SANDBOXED,
2929
},
30-
frontend::route_frontend,
30+
frontend::{
31+
route_frontend,
32+
route_frontend_version,
33+
FrontendState,
34+
},
3135
gist::{
3236
create::route_gist_create,
3337
load::route_gist_load,
3438
},
39+
version::{
40+
route_version_list,
41+
AppVersionState,
42+
},
3543
},
3644
};
3745
use actix_cors::Cors;
@@ -71,6 +79,10 @@ async fn main() -> std::io::Result<()> {
7179
}
7280
}
7381

82+
if !Path::new(&opts.versions_file_path.clone()).is_file() {
83+
panic!("{} is not a valid file.", opts.versions_file_path);
84+
}
85+
7486
async fn health() -> HttpResponse {
7587
HttpResponse::Ok().finish()
7688
}
@@ -86,6 +98,7 @@ async fn main() -> std::io::Result<()> {
8698
HttpServer::new(move || {
8799
let opts: Opts = opts.clone();
88100
let frontend_folder = opts.frontend_folder.clone();
101+
let versions_file_path = opts.versions_file_path.clone();
89102

90103
let mut app = App::new()
91104
.wrap(prometheus.clone())
@@ -112,6 +125,12 @@ async fn main() -> std::io::Result<()> {
112125
.route(
113126
"/status",
114127
get().to(route_status),
128+
)
129+
.app_data(web::Data::new(AppVersionState {
130+
versions_file_path,
131+
}))
132+
.service(
133+
web::resource("/version_list").to(route_version_list)
115134
);
116135

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

140159
match frontend_folder {
141160
Some(path) => {
142-
app = app.service(route_frontend("/", path.as_ref()));
161+
app = app
162+
.app_data(web::Data::new(FrontendState {
163+
frontend_folder: path.clone(),
164+
}))
165+
.route("/v{tail:.*}", web::get().to(route_frontend_version))
166+
.service(route_frontend("/", path.as_ref()));
143167
}
144168
None => {
145169
println!("Warning: Starting backend without serving static frontend files due to missing configuration.")

crates/backend/src/services/contract.rs

+7
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ pub async fn route_compile(
6767
let compile_result = spawn_blocking(move || {
6868
compile_strategy(CompilationRequest {
6969
source: req.source.to_string(),
70+
version: req.version.to_string(),
7071
})
7172
})
7273
.await
@@ -103,6 +104,7 @@ pub async fn route_test(
103104
let testing_result = spawn_blocking(move || {
104105
compile_strategy(TestingRequest {
105106
source: req.source.to_string(),
107+
version: req.version.to_string(),
106108
})
107109
})
108110
.await
@@ -127,6 +129,7 @@ pub async fn route_format(
127129
let formatting_result = spawn_blocking(move || {
128130
formatting_strategy(FormattingRequest {
129131
source: req.source.to_string(),
132+
version: req.version.to_string(),
130133
})
131134
})
132135
.await
@@ -204,6 +207,7 @@ mod tests {
204207

205208
let req = CompilationRequest {
206209
source: "foo".to_string(),
210+
version: "4.2.0".to_string(),
207211
};
208212
let req = test::TestRequest::post()
209213
.set_json(&req)
@@ -234,6 +238,7 @@ mod tests {
234238

235239
let req = CompilationRequest {
236240
source: "bar".to_string(),
241+
version: "4.2.0".to_string(),
237242
};
238243

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

265270
let req = TestingRequest {
266271
source: "foo".to_string(),
272+
version: "1.0.0".to_string(),
267273
};
268274
let req = test::TestRequest::post()
269275
.set_json(&req)
@@ -293,6 +299,7 @@ mod tests {
293299

294300
let req = TestingRequest {
295301
source: "bar".to_string(),
302+
version: "1.0.0".to_string(),
296303
};
297304
let req = test::TestRequest::post()
298305
.set_json(&req)

crates/backend/src/services/frontend.rs

+17
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,28 @@
1515
//! This module contains the service which serves the backend as static files.
1616
1717
use actix_files as fs;
18+
use actix_web::{
19+
web,
20+
Result,
21+
};
22+
use std::path::Path;
23+
24+
pub struct FrontendState {
25+
pub frontend_folder: String,
26+
}
1827

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

32+
pub async fn route_frontend_version(
33+
data: web::Data<FrontendState>,
34+
) -> Result<actix_files::NamedFile> {
35+
Ok(fs::NamedFile::open(
36+
Path::new(&data.frontend_folder).join("index.html"),
37+
)?)
38+
}
39+
2340
#[cfg(test)]
2441
mod tests {
2542
use super::*;

crates/backend/src/services/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@
2020
pub mod contract;
2121
pub mod frontend;
2222
pub mod gist;
23+
pub mod version;
+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
use std::fs;
2+
3+
use actix_web::{
4+
body::BoxBody,
5+
web,
6+
HttpResponse,
7+
};
8+
9+
pub use sandbox::VersionListResult;
10+
use serde_json::{
11+
json,
12+
Value,
13+
};
14+
15+
pub struct AppVersionState {
16+
pub versions_file_path: String,
17+
}
18+
19+
fn read_json_file(file_path: &str) -> Result<String, std::io::Error> {
20+
fs::read_to_string(file_path)
21+
}
22+
23+
pub async fn route_version_list(
24+
data: web::Data<AppVersionState>,
25+
) -> HttpResponse<BoxBody> {
26+
let versions_file_path = &data.versions_file_path;
27+
let versions_arr_string = read_json_file(versions_file_path).unwrap();
28+
let versions_arr_json: Value =
29+
serde_json::from_str(versions_arr_string.as_str()).expect("Failed to parse JSON");
30+
let versions_json = json!({
31+
"versions": versions_arr_json
32+
});
33+
let versions_json_string =
34+
serde_json::to_string_pretty(&versions_json).expect("Failed to stringify JSON");
35+
36+
HttpResponse::Ok()
37+
.append_header(("Content-Type", "application/json"))
38+
.body(versions_json_string)
39+
}

0 commit comments

Comments
 (0)