Skip to content
Snippets Groups Projects
Commit bfb85c07 authored by Hugo Trentesaux's avatar Hugo Trentesaux
Browse files

add Dockerfile (!31)

* working dockerfile

* wip dockerfile

TODO make duniter-polkadot-sdk repo lighter to avoid long download time in docker build

(cherry picked from commit 5f4b716f)

* update subxt and polkadot sdk
parent 76024d27
No related branches found
No related tags found
1 merge request!31add Dockerfile
target/
This diff is collapsed.
...@@ -13,37 +13,37 @@ version = "0.2.10" ...@@ -13,37 +13,37 @@ version = "0.2.10"
[dependencies] [dependencies]
# subxt is main dependency # subxt is main dependency
subxt = { git = 'https://github.com/duniter/subxt', branch = 'subxt-v0.34.0-duniter-substrate-v1.6.0', default-features = false, features = [ subxt = { git = 'https://github.com/duniter/subxt', branch = 'subxt-v0.35.3-duniter-substrate-v1.11.0', default-features = false, features = [
"substrate-compat", "substrate-compat",
"native", "native",
"jsonrpsee", "jsonrpsee",
] } ] }
# substrate primitives dependencies # substrate primitives dependencies
sp-core = { git = "https://github.com/duniter/duniter-polkadot-sdk.git", branch = "duniter-substrate-v1.6.0" } sp-core = { git = "https://github.com/duniter/duniter-polkadot-sdk.git", branch = "duniter-substrate-v1.11.0" }
sp-runtime = { git = "https://github.com/duniter/duniter-polkadot-sdk.git", branch = "duniter-substrate-v1.6.0" } sp-runtime = { git = "https://github.com/duniter/duniter-polkadot-sdk.git", branch = "duniter-substrate-v1.11.0" }
# crates.io dependencies # crates.io dependencies
anyhow = "^1.0" anyhow = "^1.0"
clap = { version = "^4.5.0", features = ["derive"] } clap = { version = "^4.5.4", features = ["derive"] }
codec = { package = "parity-scale-codec", version = "^3.6.9" } codec = { package = "parity-scale-codec", version = "^3.6.12" }
env_logger = "^0.10" env_logger = "^0.10"
futures = "^0.3.30" futures = "^0.3.30"
graphql_client = { version = "^0.13.0", features = ["reqwest-rustls"] } graphql_client = { version = "^0.13.0", features = ["reqwest-rustls"] }
hex = "^0.4.3" hex = "^0.4.3"
log = "^0.4.20" log = "^0.4.21"
reqwest = { version = "^0.11.24", default-features = false, features = [ reqwest = { version = "^0.11.27", default-features = false, features = [
"rustls-tls", "rustls-tls",
] } ] }
rpassword = "^7.3.1" rpassword = "^7.3.1"
serde = { version = "^1.0", features = ["derive"] } serde = { version = "^1.0", features = ["derive"] }
serde_json = "^1.0.113" serde_json = "^1.0.117"
tokio = { version = "^1.36.0", features = ["macros"] } tokio = { version = "^1.37.0", features = ["macros"] }
confy = "^0.5.1" confy = "^0.5.1"
bs58 = "^0.5.0" bs58 = "^0.5.1"
inquire = "^0.6.2" inquire = "^0.6.2"
directories = "^5.0.1" directories = "^5.0.1"
comfy-table = "^7.1.0" comfy-table = "^7.1.1"
# crypto # crypto
scrypt = { version = "^0.11", default-features = false } # for old-style key generation scrypt = { version = "^0.11", default-features = false } # for old-style key generation
......
# FROM rustlang/rust:nightly-slim as build
# nightly needed for -Zgit=shallow-deps build but ahash problem with stdsimd
FROM rust:latest as build
# # Use musl Rust image
# FROM clux/muslrust:1.75.0-stable as build
WORKDIR /app
# Copy the Cargo.toml and Cargo.lock files to leverage Docker's caching mechanism
COPY Cargo.toml Cargo.lock ./
# Build the dependencies of the application separately
RUN --mount=type=cache,target=/app/target \
--mount=type=cache,target=/root/.cargo/registry \
mkdir src \
&& echo "fn main() {}" > src/main.rs \
&& cargo build --release \
&& rm -r src
# Copy the rest of the source code
COPY ./res ./res
COPY ./src ./src
# Build the application
RUN cargo build --release
# Start release stage
FROM debian as release
# Set the working directory to the location of the built application
WORKDIR /app
# Copy the built application from the previous stage
COPY --from=build /app/target/release/gcli .
# Specify the entrypoint for the container
ENTRYPOINT ["/app/gcli"]
\ No newline at end of file
# Docker
Docker image for gcli is useful for people with docker-based infrastructure or old system with old glibc or libssl.
## Build
```sh
./docker/build.sh
```
## Use
To use gcli, run it with docker:
```sh
docker run --rm gcli
```
Ğcli uses folders to store config and vault. You can bind local folders to these locations:
```sh
# create folders
mkdir -p $HOME/.config/gcli/
mkdir -p $HOME/.local/share/gcli/
# run gcli in docker with there folders
docker run --rm \
--mount type=bind,src=$HOME/.config/gcli/,dst=/root/.config/gcli \
--mount type=bind,src=$HOME/.local/share/gcli/,dst=/root/.local/share/gcli \
gcli
```
An alias can be useful:
```sh
# define alias
alias docker_gcli="docker run --rm \
--mount type=bind,src=$HOME/.config/gcli/,dst=/root/.config/gcli \
--mount type=bind,src=$HOME/.local/share/gcli/,dst=/root/.local/share/gcli \
gcli"
# then simply call
docker_gcli --help
```
#!/bin/bash
# Also generated by chatGPT
# Name of your Docker image
IMAGE_NAME="gcli"
# Version of your Docker image
IMAGE_VERSION="latest"
# Build and tag the Docker image using Docker Buildx
docker buildx build -t "$IMAGE_NAME:$IMAGE_VERSION" .
# Optionally, you can push the image to a Docker registry
# docker push "$IMAGE_NAME:$IMAGE_VERSION"
...@@ -29,7 +29,7 @@ pub async fn handle_command(_data: Data, command: Subcommand) -> Result<(), Gcli ...@@ -29,7 +29,7 @@ pub async fn handle_command(_data: Data, command: Subcommand) -> Result<(), Gcli
.unwrap() .unwrap()
}; };
println!("Pubkey (hex): 0x{}", hex::encode(raw_pubkey)); println!("Pubkey (hex): 0x{}", hex::encode(raw_pubkey));
let address: AccountId = sp_core::ed25519::Public(raw_pubkey).into(); let address: AccountId = sp_core::ed25519::Public::from_raw(raw_pubkey).into();
println!("Address (SS58): {}", address); println!("Address (SS58): {}", address);
} }
Subcommand::Prompt => { Subcommand::Prompt => {
...@@ -73,7 +73,7 @@ where ...@@ -73,7 +73,7 @@ where
} }
fn sign(&self, payload: &[u8]) -> T::Signature { fn sign(&self, payload: &[u8]) -> T::Signature {
sp_core::ed25519::Signature( sp_core::ed25519::Signature::from_raw(
nacl::sign::signature(payload, &self.keypair.skey) nacl::sign::signature(payload, &self.keypair.skey)
.unwrap() .unwrap()
.try_into() .try_into()
......
...@@ -107,9 +107,9 @@ pub async fn technical_committee_proposals(client: &Client) -> anyhow::Result<() ...@@ -107,9 +107,9 @@ pub async fn technical_committee_proposals(client: &Client) -> anyhow::Result<()
.at(parent_hash) .at(parent_hash)
.iter(runtime::storage().technical_committee().proposal_of_iter()) .iter(runtime::storage().technical_committee().proposal_of_iter())
.await?; .await?;
while let Some(Ok((proposal_hash, proposal))) = proposals_iter.next().await { while let Some(Ok(item)) = proposals_iter.next().await {
println!("{}", hex::encode(&proposal_hash[32..64])); println!("{}", hex::encode(&item.key_bytes[32..64]));
println!("{proposal:#?}"); println!("{:#?}", item.value);
println!(); println!();
} }
......
...@@ -35,10 +35,10 @@ pub async fn monitor_expirations(data: &Data, blocks: u32, _sessions: u32) -> an ...@@ -35,10 +35,10 @@ pub async fn monitor_expirations(data: &Data, blocks: u32, _sessions: u32) -> an
.iter(runtime::storage().certification().certs_removable_on_iter()) .iter(runtime::storage().certification().certs_removable_on_iter())
.await?; .await?;
let mut basic_certs = BTreeMap::new(); let mut basic_certs = BTreeMap::new();
while let Some(Ok((k, v))) = basic_certs_iter.next().await { while let Some(Ok(item)) = basic_certs_iter.next().await {
let block_number = BlockNumber::from_le_bytes(k[40..44].try_into().unwrap()); let block_number = BlockNumber::from_le_bytes(item.key_bytes[40..44].try_into().unwrap());
if block_number < end_block { if block_number < end_block {
basic_certs.insert(block_number - current_block, v); basic_certs.insert(block_number - current_block, item.value);
} }
} }
...@@ -72,13 +72,13 @@ pub async fn monitor_expirations(data: &Data, blocks: u32, _sessions: u32) -> an ...@@ -72,13 +72,13 @@ pub async fn monitor_expirations(data: &Data, blocks: u32, _sessions: u32) -> an
.iter(runtime::storage().membership().memberships_expire_on_iter()) .iter(runtime::storage().membership().memberships_expire_on_iter())
.await?; .await?;
let mut basic_memberships = BTreeMap::new(); let mut basic_memberships = BTreeMap::new();
while let Some(Ok((k, v))) = basic_membership_iter.next().await { while let Some(Ok(item)) = basic_membership_iter.next().await {
let block_number = BlockNumber::from_le_bytes(k[40..44].try_into().unwrap()); let block_number = BlockNumber::from_le_bytes(item.key_bytes[40..44].try_into().unwrap());
if block_number < end_block { if block_number < end_block {
if block_number < current_block { if block_number < current_block {
dbg!((block_number, current_block)); dbg!((block_number, current_block));
} }
basic_memberships.insert(block_number - current_block, v); basic_memberships.insert(block_number - current_block, item.value);
} }
} }
......
...@@ -65,13 +65,12 @@ pub async fn spam_roll(data: &Data, actual_repart: usize) -> anyhow::Result<()> ...@@ -65,13 +65,12 @@ pub async fn spam_roll(data: &Data, actual_repart: usize) -> anyhow::Result<()>
let dest: AccountId = pairs[i + 1].1.clone(); let dest: AccountId = pairs[i + 1].1.clone();
let watcher = client let watcher = client
.tx() .tx()
.create_signed_with_nonce( .create_signed_offline(
&runtime::tx() &runtime::tx()
.balances() .balances()
.transfer_allow_death(MultiAddress::Id(dest).into(), 1), .transfer_allow_death(MultiAddress::Id(dest).into(), 1),
&pairs[i].0, &pairs[i].0,
nonce, DefaultExtrinsicParamsBuilder::new().nonce(nonce).build(),
DefaultExtrinsicParamsBuilder::new().build(),
)? )?
.submit_and_watch() .submit_and_watch()
.await?; .await?;
......
...@@ -58,18 +58,16 @@ pub async fn submit_call<Payload: TxPayload>( ...@@ -58,18 +58,16 @@ pub async fn submit_call<Payload: TxPayload>(
// sign and submit // sign and submit
match data.keypair() { match data.keypair() {
// sr25519 key pair // sr25519 key pair
KeyPair::Sr25519(keypair) => data.client().tx().create_signed_with_nonce( KeyPair::Sr25519(keypair) => data.client().tx().create_signed_offline(
payload, payload,
&PairSigner::<Runtime, sp_core::sr25519::Pair>::new(keypair), &PairSigner::<Runtime, sp_core::sr25519::Pair>::new(keypair),
nonce, DefaultExtrinsicParamsBuilder::new().nonce(nonce).build(),
Default::default(),
), ),
// nacl key pair // nacl key pair
KeyPair::Nacl(keypair) => data.client().tx().create_signed_with_nonce( KeyPair::Nacl(keypair) => data.client().tx().create_signed_offline(
payload, payload,
&commands::cesium::CesiumSigner::new(keypair), &commands::cesium::CesiumSigner::new(keypair),
nonce, DefaultExtrinsicParamsBuilder::new().nonce(nonce).build(),
Default::default(),
), ),
}? }?
.submit_and_watch() .submit_and_watch()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment