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

Embed default config and attempt to fix tests #29

Merged
merged 2 commits into from
Feb 1, 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
31 changes: 2 additions & 29 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ env:
CARGO_TERM_COLOR: always

jobs:
build:
build-and-test:
runs-on: ubuntu-latest
env:
EARTHLY_TOKEN: ${{ secrets.EARTHLY_TOKEN }}
Expand All @@ -28,31 +28,4 @@ jobs:
- name: Docker Login
run: docker login --username "$DOCKERHUB_USERNAME" --password "$DOCKERHUB_TOKEN"
- name: Run build
run: earthly --org applied-knowledge-systems --sat my-satellite --ci --push +docker-all

build-and-test:
name: Build and Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install system dependencies
run: sudo apt-get update && sudo apt-get install -y libgtk-3-dev libsoup2.4-dev libwebkit2gtk-4.0-dev

- uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy

- uses: Swatinem/rust-cache@v2

- name: cargo check
run: cargo check --workspace

- name: cargo fmt
run: cargo fmt --all -- --check

- name: cargo clippy
run: cargo clippy --workspace --all-targets --all-features -- -D warnings

- name: cargo test
run: cargo test --workspace --exclude terraphim_ai --exclude app --all-targets --all-features
run: earthly --org applied-knowledge-systems --sat my-satellite --ci --push +pipeline
File renamed without changes.
31 changes: 31 additions & 0 deletions .github/workflows/test-on-pr-tauri.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: "test-on-pr"
on: [pull_request]

jobs:
test-tauri:
strategy:
fail-fast: false
matrix:
platform: [macos-latest, ubuntu-latest, windows-latest]

runs-on: ${{ matrix.platform }}
steps:
- uses: actions/checkout@v2
- name: setup node
uses: actions/setup-node@v1
with:
node-version: 16
- name: install Rust stable
uses: actions-rs/toolchain@v1
with:
toolchain: stable
- name: install dependencies (ubuntu only)
if: matrix.platform == 'ubuntu-latest'
run: |
sudo apt-get update
sudo apt-get install -y libgtk-3-dev webkit2gtk-4.0 libappindicator3-dev librsvg2-dev patchelf
- name: install app dependencies and build it
run: yarn && yarn build
- uses: tauri-apps/tauri-action@v0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
47 changes: 20 additions & 27 deletions .github/workflows/test-on-pr.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,24 @@
name: "test-on-pr"
on: [pull_request]
on:
[pull_request]

jobs:
test-tauri:
strategy:
fail-fast: false
matrix:
platform: [macos-latest, ubuntu-latest, windows-latest]
env:
CARGO_TERM_COLOR: always

runs-on: ${{ matrix.platform }}
jobs:
build-and-test:
runs-on: ubuntu-latest
env:
EARTHLY_TOKEN: ${{ secrets.EARTHLY_TOKEN }}
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
FORCE_COLOR: 1
steps:
- uses: actions/checkout@v2
- name: setup node
uses: actions/setup-node@v1
with:
node-version: 16
- name: install Rust stable
uses: actions-rs/toolchain@v1
with:
toolchain: stable
- name: install dependencies (ubuntu only)
if: matrix.platform == 'ubuntu-latest'
run: |
sudo apt-get update
sudo apt-get install -y libgtk-3-dev webkit2gtk-4.0 libappindicator3-dev librsvg2-dev patchelf
- name: install app dependencies and build it
run: yarn && yarn build
- uses: tauri-apps/tauri-action@v0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- uses: earthly/actions-setup@v1
with:
version: v0.7.23
- uses: actions/checkout@v2
- name: Docker Login
run: docker login --username "$DOCKERHUB_USERNAME" --password "$DOCKERHUB_TOKEN"
- name: Run build
run: earthly --org applied-knowledge-systems --sat my-satellite --ci --push +pipeline
40 changes: 32 additions & 8 deletions Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ WORKDIR /code

pipeline:
BUILD desktop+build
BUILD +build-debug
BUILD +fmt
BUILD +lint
BUILD +test
Expand Down Expand Up @@ -46,20 +47,23 @@ install:
RUN update-ca-certificates
RUN rustup component add clippy
RUN rustup component add rustfmt
RUN cargo install cross
DO rust+INIT --keep_fingerprints=true
RUN cargo install cross
#RUN cargo install orogene


source:
FROM +install
WORKDIR /code
COPY --keep-ts Cargo.toml Cargo.lock ./
COPY --keep-ts --dir terraphim-server desktop crates terraphim_types ./
COPY desktop+build/dist /code/terraphim-server/dist
COPY --keep-ts --dir terraphim_server desktop crates terraphim_types ./
DO rust+CARGO --args=fetch

cross-build:
FROM +source
ARG --required TARGET
DO rust+SET_CACHE_MOUNTS_ENV
COPY desktop+build/dist /code/terraphim-server/dist
WITH DOCKER
RUN --mount=$EARTHLY_RUST_CARGO_HOME_CACHE --mount=$EARTHLY_RUST_TARGET_CACHE cross build --target $TARGET --release
END
Expand All @@ -69,20 +73,33 @@ cross-build:

build:
FROM +source
DO rust+SET_CACHE_MOUNTS_ENV
COPY desktop+build/dist /code/terraphim-server/dist
DO rust+CARGO --args="build --offline --release" --output="release/[^/\.]+"
RUN ./target/release/terraphim_server --version
SAVE ARTIFACT ./target/release/terraphim_server AS LOCAL artifact/bin/terraphim_server-$TARGET

test:
build-debug:
FROM +source
DO rust+CARGO --args="test"
DO rust+SET_CACHE_MOUNTS_ENV
COPY desktop+build/dist /code/terraphim-server/dist
DO rust+CARGO --args="build --offline" --output="debug/[^/\.]+"
RUN ./target/debug/terraphim_server --version
SAVE ARTIFACT ./target/debug/terraphim_server AS LOCAL artifact/bin/terraphim_server-debug

test:
FROM +build-debug
DO rust+SET_CACHE_MOUNTS_ENV
COPY --chmod=0755 +build-debug/terraphim_server /terraphim_server_debug
RUN --mount=$EARTHLY_RUST_CARGO_HOME_CACHE --mount=$EARTHLY_RUST_TARGET_CACHE nohup /terraphim_server_debug & sleep 2 & cargo test --offline;
#DO rust+CARGO --args="test --offline"

fmt:
FROM +source
FROM +build-debug
DO rust+CARGO --args="fmt --check"

lint:
FROM +source
FROM +build-debug
DO rust+CARGO --args="clippy --no-deps --all-features --all-targets"

docker-musl:
Expand Down Expand Up @@ -121,4 +138,11 @@ docker-slim:
COPY +build/terraphim_server terraphim_server
EXPOSE 8000
ENTRYPOINT ["./terraphim_server"]
SAVE IMAGE aks/terraphim_server:buster
SAVE IMAGE aks/terraphim_server:buster

docker-scratch:
FROM scratch
COPY +build/terraphim_server terraphim_server
EXPOSE 8000
ENTRYPOINT ["./terraphim_server"]
SAVE IMAGE aks/terraphim_server:scratch
19 changes: 2 additions & 17 deletions crates/settings/default/settings.toml
Original file line number Diff line number Diff line change
@@ -1,29 +1,14 @@
server_hostname = "127.0.0.1:8000"
api_endpoint="http://localhost:8000/api"

[profiles.s3]
type = "s3"
bucket = "test"
region = "${TERRAPHIM_PROFILE_S3_REGION:-us-east-1}"
endpoint = "${TERRAPHIM_PROFILE_S3_ENDPOINT:-http://rpi4node3:8333/}"
access_key_id = "${AWS_ACCESS_KEY_ID}"
secret_access_key = "${AWS_SECRET_ACCESS_KEY}"

[profiles.sled]
type = "sled"
datadir= "/tmp/opendal/sled"
datadir= "/tmp/sled"

[profiles.dash]
type = "dashmap"
root = "/tmp/dashmaptest"

[profiles.rock]
type = "rocksdb"
datadir = "/tmp/opendal/rocksdb"

[profiles.atomicserver]
endpoint = "${TERRAPHIM_PROFILE_ATOMICSERVER}"
type = "atomicserver"
private_key = "${TERRAPHIM_PROFILE_ATOMICSERVER_PRIVATE_KEY}"
public_key = "${TERRAPHIM_PROFILE_ATOMICSERVER_PUBLIC_KEY}"
parent_resource_id="${TERRAPHIM_PROFILE_ATOMICSERVER}"
datadir = "/tmp/rocksdb"
29 changes: 29 additions & 0 deletions crates/settings/default/settings_full.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
server_hostname = "127.0.0.1:8000"
api_endpoint="http://localhost:8000/api"

[profiles.s3]
type = "s3"
bucket = "test"
region = "${TERRAPHIM_PROFILE_S3_REGION:-us-east-1}"
endpoint = "${TERRAPHIM_PROFILE_S3_ENDPOINT:-http://rpi4node3:8333/}"
access_key_id = "${AWS_ACCESS_KEY_ID}"
secret_access_key = "${AWS_SECRET_ACCESS_KEY}"

[profiles.sled]
type = "sled"
datadir= "/tmp/opendal/sled"

[profiles.dash]
type = "dashmap"
root = "/tmp/dashmaptest"

[profiles.rock]
type = "rocksdb"
datadir = "/tmp/opendal/rocksdb"

[profiles.atomicserver]
endpoint = "${TERRAPHIM_PROFILE_ATOMICSERVER}"
type = "atomicserver"
private_key = "${TERRAPHIM_PROFILE_ATOMICSERVER_PRIVATE_KEY}"
public_key = "${TERRAPHIM_PROFILE_ATOMICSERVER_PUBLIC_KEY}"
parent_resource_id="${TERRAPHIM_PROFILE_ATOMICSERVER}"
9 changes: 6 additions & 3 deletions crates/settings/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl Settings {
}
}
};

println!("Reading config_file: {:?}", config_file);
Ok(Settings::with_layers(&[
Layer::Toml(config_file),
Layer::Env(Some(String::from("TERRAPHIM_"))),
Expand All @@ -54,13 +54,16 @@ fn create_config_folder(path: &PathBuf) -> Result<PathBuf, std::io::Error> {
std::fs::create_dir_all(path)?;
}
let filename = path.join("settings.toml");

let default_config = include_str!("../default/settings.toml");
if filename.exists() {
log::warn!("File exists");
log::warn!("{:?}", filename);
} else {
log::warn!("File does not exist");
std::fs::copy("default/settings.toml", &filename)?;
// FIXME: the logic of settings that each app - desktop or server have their own default settings.toml
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mre I want your opinion on how to design it better - see FIXME: comment.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could have an environment variable for the config path that could be overwritten.
Then we could use it here.

TERRAPHIM_CONFIG_PATH=...

It could be set to a sane default.
Just an idea.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the path variable for default cargo run and cargo test? We can put the default config into that path, and it will pick it up automatically for run and test, but then subfolders in the Axum server and desktop can have their own when run.

// this is a quickfix to make testing sane
println!("Writing default config to: {:?}", filename);
std::fs::write( &filename,default_config)?;
}
Ok(filename)
}
Expand Down
14 changes: 14 additions & 0 deletions default/settings.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
server_hostname = "${TERRAPHIM_SERVER_HOSTNAME}-127.0.0.1:8000"
api_endpoint="${TERRAPHIM_SERVER_API_ENDPOINT}-http://localhost:8000/api"

[profiles.sled]
type = "sled"
datadir= "/tmp/sled"

[profiles.dash]
type = "dashmap"
root = "/tmp/dashmaptest"

[profiles.rock]
type = "rocksdb"
datadir = "/tmp/rocksdb"
29 changes: 29 additions & 0 deletions default/settings_default_desktop.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
server_hostname = "${TERRAPHIM_SERVER_HOSTNAME}-127.0.0.1:8000"
api_endpoint="${TERRAPHIM_SERVER_API_ENDPOINT}-http://localhost:8000/api"

[profiles.s3]
type = "s3"
bucket = "test"
region = "${TERRAPHIM_PROFILE_S3_REGION:-us-east-1}"
endpoint = "${TERRAPHIM_PROFILE_S3_ENDPOINT:-http://rpi4node3:8333/}"
access_key_id = "${AWS_ACCESS_KEY_ID}"
secret_access_key = "${AWS_SECRET_ACCESS_KEY}"

[profiles.sled]
type = "sled"
datadir= "/tmp/opendal/sled"

[profiles.dash]
type = "dashmap"
root = "/tmp/dashmaptest"

[profiles.rock]
type = "rocksdb"
datadir = "/tmp/opendal/rocksdb"

[profiles.atomicserver]
endpoint = "${TERRAPHIM_PROFILE_ATOMICSERVER}"
type = "atomicserver"
private_key = "${TERRAPHIM_PROFILE_ATOMICSERVER_PRIVATE_KEY}"
public_key = "${TERRAPHIM_PROFILE_ATOMICSERVER_PUBLIC_KEY}"
parent_resource_id="${TERRAPHIM_PROFILE_ATOMICSERVER}"
6 changes: 3 additions & 3 deletions desktop/Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ WORKDIR frontend

deps:
# COPY package.json tsconfig.json yarn.lock vite.config.ts tsconfig.node.json index.html ./
COPY . .
COPY --dir src src
COPY --dir public public
COPY --keep-ts . .
# COPY --dir src src
# COPY --dir public public
RUN yarn

build:
Expand Down
Loading
Loading