Skip to content

Commit 4776bdc

Browse files
authored
Fortuna CI workflows (#1120)
* CI and docker * cleanup * erc * whoops
1 parent d87cd7c commit 4776bdc

File tree

12 files changed

+138
-44
lines changed

12 files changed

+138
-44
lines changed

.github/workflows/ci-fortuna.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Check Fortuna
2+
3+
on:
4+
pull_request:
5+
paths: [fortuna/**]
6+
push:
7+
branches: [main]
8+
paths: [fortuna/**]
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v2
14+
- uses: actions-rs/toolchain@v1
15+
with:
16+
profile: minimal
17+
toolchain: nightly-2023-07-23
18+
override: true
19+
- name: Run executor tests
20+
run: cargo test --manifest-path ./fortuna/Cargo.toml
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Build and Push Fortuna Image
2+
on:
3+
push:
4+
tags:
5+
- fortuna-v*
6+
workflow_dispatch:
7+
inputs:
8+
dispatch_description:
9+
description: "Dispatch description"
10+
required: true
11+
type: string
12+
permissions:
13+
contents: read
14+
id-token: write
15+
jobs:
16+
fortuna-image:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- uses: actions/checkout@v2
20+
- name: Set image tag to version of the git tag
21+
if: ${{ startsWith(github.ref, 'refs/tags/fortuna-v') }}
22+
run: |
23+
PREFIX="refs/tags/fortuna-"
24+
VERSION="${GITHUB_REF:${#PREFIX}}"
25+
echo "IMAGE_TAG=${VERSION}" >> "${GITHUB_ENV}"
26+
- name: Set image tag to the git commit hash
27+
if: ${{ !startsWith(github.ref, 'refs/tags/fortuna-v') }}
28+
run: |
29+
echo "IMAGE_TAG=${{ github.sha }}" >> "${GITHUB_ENV}"
30+
- uses: aws-actions/configure-aws-credentials@8a84b07f2009032ade05a88a28750d733cc30db1
31+
with:
32+
role-to-assume: arn:aws:iam::192824654885:role/github-actions-ecr
33+
aws-region: eu-west-2
34+
- uses: docker/login-action@v2
35+
with:
36+
registry: public.ecr.aws
37+
env:
38+
AWS_REGION: us-east-1
39+
- run: |
40+
DOCKER_BUILDKIT=1 docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG -f fortuna/Dockerfile .
41+
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
42+
env:
43+
ECR_REGISTRY: public.ecr.aws
44+
ECR_REPOSITORY: pyth-network/fortuna

fortuna/Cargo.lock

Lines changed: 31 additions & 31 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

fortuna/Dockerfile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
ARG RUST_VERSION=1.66.1
2+
3+
FROM rust:${RUST_VERSION} AS build
4+
5+
# Set default toolchain
6+
RUN rustup default nightly-2023-07-23
7+
8+
# Build
9+
WORKDIR /src
10+
COPY fortuna fortuna
11+
12+
WORKDIR /src/fortuna
13+
14+
RUN --mount=type=cache,target=/root/.cargo/registry cargo build --release
15+
16+
17+
FROM rust:${RUST_VERSION}
18+
# Copy artifacts from other images
19+
COPY --from=build /src/fortuna/target/release/fortuna /usr/local/bin/

fortuna/src/command/generate.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ use {
88
ethereum::SignablePythContract,
99
},
1010
anyhow::Result,
11+
base64::{
12+
engine::general_purpose::STANDARD as base64_standard_engine,
13+
Engine as _,
14+
},
1115
std::sync::Arc,
1216
};
1317

@@ -40,7 +44,10 @@ pub async fn generate(opts: &GenerateOptions) -> Result<()> {
4044
.json::<GetRandomValueResponse>()
4145
.await?;
4246

43-
tracing::info!(response = resp, "Retrieved the provider's random value.",);
47+
tracing::info!(
48+
response = base64_standard_engine.encode(resp.value),
49+
"Retrieved the provider's random value.",
50+
);
4451
let provider_randomness = resp.value;
4552

4653
// Submit the provider's and our values to the contract to reveal the random number.
@@ -53,7 +60,10 @@ pub async fn generate(opts: &GenerateOptions) -> Result<()> {
5360
)
5461
.await?;
5562

56-
tracing::info!(number = random_value, "Random number generated.");
63+
tracing::info!(
64+
number = base64_standard_engine.encode(random_value),
65+
"Random number generated."
66+
);
5767

5868
Ok(())
5969
}

fortuna/src/config.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ pub enum Options {
6464
pub struct ConfigOptions {
6565
/// Path to a configuration file containing the list of supported blockchains
6666
#[arg(long = "config")]
67-
#[arg(env = "PYTH_CONFIG")]
67+
#[arg(env = "FORTUNA_CONFIG")]
6868
#[arg(default_value = "config.yaml")]
6969
pub config: String,
7070
}
@@ -75,13 +75,13 @@ pub struct ConfigOptions {
7575
pub struct RandomnessOptions {
7676
/// A secret used for generating new hash chains. A 64-char hex string.
7777
#[arg(long = "secret")]
78-
#[arg(env = "PYTH_SECRET")]
78+
#[arg(env = "FORTUNA_SECRET")]
7979
#[arg(default_value = "0000000000000000000000000000000000000000000000000000000000000000")]
8080
pub secret: String,
8181

8282
/// The length of the hash chain to generate.
8383
#[arg(long = "chain-length")]
84-
#[arg(env = "PYTH_CHAIN_LENGTH")]
84+
#[arg(env = "FORTUNA_CHAIN_LENGTH")]
8585
#[arg(default_value = "32")]
8686
pub chain_length: u64,
8787
}

fortuna/src/config/generate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub struct GenerateOptions {
1717

1818
/// Retrieve a randomness request to this provider
1919
#[arg(long = "chain-id")]
20-
#[arg(env = "PYTH_CHAIN_ID")]
20+
#[arg(env = "FORTUNA_CHAIN_ID")]
2121
pub chain_id: ChainId,
2222

2323
/// A 20-byte (40 char) hex encoded Ethereum private key.

fortuna/src/config/get_request.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,18 @@ pub struct GetRequestOptions {
1616

1717
/// Retrieve a randomness request to this provider
1818
#[arg(long = "chain-id")]
19-
#[arg(env = "PYTH_CHAIN_ID")]
19+
#[arg(env = "FORTUNA_CHAIN_ID")]
2020
pub chain_id: ChainId,
2121

2222
/// Retrieve a randomness request to this provider
2323
#[arg(long = "provider")]
24-
#[arg(env = "PYTH_PROVIDER")]
24+
#[arg(env = "FORTUNA_PROVIDER")]
2525
#[arg(default_value = "0x368397bDc956b4F23847bE244f350Bde4615F25E")]
2626
pub provider: Address,
2727

2828
/// The sequence number of the request to retrieve
2929
#[arg(long = "sequence")]
30-
#[arg(env = "PYTH_SEQUENCE")]
30+
#[arg(env = "FORTUNA_SEQUENCE")]
3131
#[arg(default_value = "0")]
3232
pub sequence: u64,
3333
}

fortuna/src/config/register_provider.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub struct RegisterProviderOptions {
1919

2020
/// Retrieve a randomness request to this provider
2121
#[arg(long = "chain-id")]
22-
#[arg(env = "PYTH_CHAIN_ID")]
22+
#[arg(env = "FORTUNA_CHAIN_ID")]
2323
pub chain_id: ChainId,
2424

2525
/// A 20-byte (40 char) hex encoded Ethereum private key.

fortuna/src/config/request_randomness.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub struct RequestRandomnessOptions {
1616

1717
/// Request randomness on this blockchain.
1818
#[arg(long = "chain-id")]
19-
#[arg(env = "PYTH_CHAIN_ID")]
19+
#[arg(env = "FORTUNA_CHAIN_ID")]
2020
pub chain_id: ChainId,
2121

2222
/// A 20-byte (40 char) hex encoded Ethereum private key.
@@ -27,7 +27,7 @@ pub struct RequestRandomnessOptions {
2727

2828
/// Submit a randomness request to this provider
2929
#[arg(long = "provider")]
30-
#[arg(env = "PYTH_PROVIDER")]
30+
#[arg(env = "FORTUNA_PROVIDER")]
3131
#[arg(default_value = "0x368397bDc956b4F23847bE244f350Bde4615F25E")]
3232
pub provider: Address,
3333
}

0 commit comments

Comments
 (0)