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

Rustfinity Runner v0.2.0 #44

Merged
merged 3 commits into from
Nov 17, 2024
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
3 changes: 2 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
name: Test and publish crates

on:
push:
pull_request:
branches:
- main

env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
Expand Down
25 changes: 4 additions & 21 deletions .github/workflows/rustfinity-runner.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,8 @@ name: Build Rustfinity Runner

on:
push:
branches:
- main
- staging
paths:
- ".github/workflows/rustfinity-runner.yaml"
- "crates/rustfinity-runner/**"
- "challenges/**"
workflow_dispatch:
tags:
- v*

jobs:
publish:
Expand All @@ -30,21 +24,10 @@ jobs:
- name: Login to GitHub Container Registry
run: echo "${{ github.token }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin

- name: Determine tag and Dockerfile
id: vars
run: |
if [[ "${GITHUB_REF#refs/heads/}" == "main" ]]; then
echo "TAG_NAME=latest" >> $GITHUB_ENV
echo "DOCKERFILE_PATH=crates/rustfinity-runner/Dockerfile" >> $GITHUB_ENV
elif [[ "${GITHUB_REF#refs/heads/}" == "staging" ]]; then
echo "TAG_NAME=staging" >> $GITHUB_ENV
echo "DOCKERFILE_PATH=crates/rustfinity-runner/Dockerfile.staging" >> $GITHUB_ENV
fi

- name: Build and push
uses: docker/build-push-action@v6
with:
file: ${{ env.DOCKERFILE_PATH }}
file: crates/rustfinity-runner/Dockerfile
push: true
tags: |
ghcr.io/${{ github.repository_owner }}/rustfinity-runner:${{ env.TAG_NAME }}
ghcr.io/${{ github.repository_owner }}/rustfinity-runner:${{ github.ref_name }}
16 changes: 8 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions crates/rustfinity-runner/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ version = "0.1.0"
edition = "2021"

[dependencies]
anyhow = "1.0.86"
anyhow = "1.0.93"
base64 = "0.22.1"
clap = { version = "4.5.11", features = ["derive"] }
clap = { version = "4.5.21", features = ["derive"] }
dotenvy = "0.15.7"
duct = "0.13.7"
regex = "1.10.6"
Expand Down
37 changes: 16 additions & 21 deletions crates/rustfinity-runner/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,37 +1,32 @@
# Stage 1: Clone the repository
FROM alpine/git AS git
# --- Stage 1 ---
FROM rust:slim-buster AS builder
WORKDIR /app
RUN git clone https://github.com/dcodesdev/rustfinity.com

# Stage 2: Build the Runner CLI and the rustfinity.com project
FROM rust:slim-buster
COPY crates/rustfinity-runner .
RUN cargo build --release

# --- Stage 2 ---

FROM rust:slim-buster AS runner
LABEL rustfinity-runner="true"

# Install OpenSSL development packages and pkg-config
RUN apt-get update && apt-get install -y \
pkg-config \
libssl-dev \
heaptrack \
&& rm -rf /var/lib/apt/lists/*

# Build the Runner CLI
WORKDIR /app/runner
COPY . .
RUN cargo build --release
WORKDIR /app

COPY crates/syntest crates/syntest
COPY crates/rustfinity-runner/docker/Cargo.toml Cargo.toml

# Move the Runner CLI executable
RUN mv target/release/rustfinity-runner /app/
RUN cargo new challenges/playground && rm -rf challenges/playground/.git

# Build the rustfinity.com project
WORKDIR /app/rustfinity.com
COPY --from=git /app/rustfinity.com .
RUN cargo build

# Create a new project for (rustfinity.com/playground)
WORKDIR /app
RUN cargo new playground
COPY --from=builder /app/target/release/rustfinity-runner /app/

# The final structure:
# /app/rustfinity-runner (executable)
# /app/rustfinity.com/ (project directory)
# /app/playground/ (project directory)
# /app/challenges/playground (project)
# /app/crates/syntest (library)
37 changes: 0 additions & 37 deletions crates/rustfinity-runner/Dockerfile.staging

This file was deleted.

17 changes: 12 additions & 5 deletions crates/rustfinity-runner/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,18 @@ docker run -i \
--cpus=1 \
-m=500m \
rustfinity-runner \
/bin/bash -c "/app/rustfinity-runner run --code 'cHViIGZuIGhlbGxvX3dvcmxkKCkgewogICAgcHJpbnRsbiEoIkdvb2Qgam9iLCB5b3UgZGVjb2RlZCBpdCA6RCIpCn0K' --challenge 'printing-hello-world'"
/bin/bash -c "/app/rustfinity-runner playground --code 'cHViIGZuIGhlbGxvX3dvcmxkKCkgewogICAgcHJpbnRsbiEoIkdvb2Qgam9iLCB5b3UgZGVjb2RlZCBpdCA6RCIpCn0K'"
```

### Arguments
### Commands

- `--code`: The base64 encoded code to run.
- `--challenge`: The challenge name. This is used to identify the challenge in the logs.
- `--n-tests` or `n`: The number of tests to run (takes the minimum amount of time in `ms` and prints it).
- `test`: Runs a [rustfinity challenge](../../challenges/), requires a few arguments:

- `--code`: Base64 encoded code (user submitted)
- `--tests`: Base64 encoded tests file
- `--cargo-toml`: Base64 encoded Cargo.toml file for that challenge
- `--n-tests` (optional): How many times the benchmarks should run (default = 1)

- `playground`: Runs a provided snippet of code, used in [rustfinity.com/playground](https://www.rustfinity.com/playground), requires one argument:

- `--code`: Base64 encoded code (user submitted)
3 changes: 3 additions & 0 deletions crates/rustfinity-runner/docker/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[workspace]
members = ["challenges/*", "crates/*"]
resolver = "2"
1 change: 1 addition & 0 deletions crates/rustfinity-runner/docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This content is only used in the Docker image.
4 changes: 4 additions & 0 deletions crates/rustfinity-runner/example-playground.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh

cargo -q run playground \
--code Zm4gbWFpbigpIHsKICAgIHByaW50bG4hKCJIZWxsbywgV29ybGQhIik7Cn0K
6 changes: 0 additions & 6 deletions crates/rustfinity-runner/example.sh

This file was deleted.

7 changes: 2 additions & 5 deletions crates/rustfinity-runner/makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
TAG ?= staging

.PHONY: build
build:
ifeq ($(TAG), staging)
docker build --no-cache -t rustfinity-runner:$(TAG) . -f Dockerfile.staging
else
docker build --no-cache -t rustfinity-runner:$(TAG) . -f Dockerfile
endif
docker build -t rustfinity-runner:$(TAG) ../../ -f Dockerfile
21 changes: 16 additions & 5 deletions crates/rustfinity-runner/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,29 @@ pub struct Cli {

#[derive(Debug, Subcommand)]
pub enum Commands {
#[clap(about = "Run and test the code based on the challenge and code provided")]
Run {
#[clap(long)]
#[clap(about = "Run the code based on the code, tests, and cargo toml file provided")]
Test {
/// Code base64 encoded
#[clap(long)]
code: String,

/// Tests base64 encoded
#[clap(long)]
/// Challenge slug
challenge: Option<String>,
tests: String,

/// Cargo toml base64 encoded
#[clap(long)]
cargo_toml: String,

#[clap(long = "n-tests", short)]
/// number of tests to take the minimum time of
n_tests: Option<usize>,
},

#[clap(about = "Run and test the code based on the challenge and code provided")]
Playground {
/// Code base64 encoded
#[clap(long)]
code: String,
},
}
Loading
Loading