Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
HoKim98 committed Jul 9, 2024
0 parents commit f74e51e
Show file tree
Hide file tree
Showing 43 changed files with 2,123 additions and 0 deletions.
59 changes: 59 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Generated by Cargo
# will have compiled files and executables
debug/
dist/
target/

# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
Cargo.lock

# These are backup files generated by rustfmt
**/*.rs.bk

# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb

# RustRover
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

# CI/CD
/.github/
/templates/
**/*.sh
**/*.yaml
**/*.yml

# Dev
/**/.env

# Documentation
**/*.md
/docs/

# Dockerfile
/.containerignore
/.dockerignore
/Containerfile*
/Dockerfile*

# Editor
/.hypothesis/
/.vscode/
/backup/
**/tmp/

# Git
/.git/

# Makefile/Justfile
/Justfile
/Makefile

# Temporary files
/logs
/test-*
36 changes: 36 additions & 0 deletions .github/workflows/pr_check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: pr_check

on:
workflow_dispatch:
push:
pull_request:
branches: [master]

env:
CARGO_TERM_COLOR: always

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: install toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
target: wasm32-unknown-unknown
override: true
profile: minimal

- name: Install trunk
uses: jetli/[email protected]
with:
version: "latest"

- name: Build
run: trunk build './crates/cassette/index.html'

- name: Run tests
run: cargo test --all --verbose
32 changes: 32 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Generated by Cargo
# will have compiled files and executables
debug/
dist/
target/

# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
Cargo.lock

# These are backup files generated by rustfmt
**/*.rs.bk

# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb

# RustRover
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

# Editor
/.hypothesis/
/.vscode/
/backup/
**/tmp/

# Temporary files
/logs
/test-*
53 changes: 53 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
[workspace]
default-members = ["crates/cassette"]
members = [
"crates/cassette",
"crates/cassette-core",
"crates/cassette-gateway",
"crates/cassette-operator",
"crates/cassette-plugin-kubernetes",
]
resolver = "2"

[workspace.package]
authors = ["Ho Kim <[email protected]>"]
description = "Template-based dynamic declarative Web UI Framework"
documentation = "https://docs.rs/cassette"
edition = "2021"
include = ["src/**/*.rs", "Cargo.toml"]
keywords = ["cassette", "kubernetes", "frontend"]
license = "AGPL-3.0-or-later"
readme = "./README.md"
rust-version = "1.78"
homepage = "https://github.com/ulagbulag/cassette"
repository = "https://github.com/ulagbulag/cassette"
version = "0.1.0"

[workspace.lints.clippy]
blocks_in_conditions = "allow" # opentelemetry tracing macro would be noisy

[workspace.dependencies]
ark-core = { git = "https://github.com/ulagbulag/OpenARK" }
ark-core-k8s = { git = "https://github.com/ulagbulag/OpenARK" }

actix-web = { version = "4.8", default-features = false, features = [
"macros",
"rustls",
] }
actix-web-opentelemetry = { version = "0.18", features = ["metrics"] }
anyhow = { version = "1.0", features = ["backtrace"] }
async-trait = { version = "0.1" }
clap = { version = "4.5", features = ["derive", "env", "string"] }
futures = { version = "0.3" }
garde = { version = "0.20", features = ["derive", "regex", "serde", "unicode"] }
k8s-openapi = { version = "0.22", features = ["latest", "schemars"] }
kube = { version = "0.91", default-features = false }
regex = { version = "1.10", default-features = false }
schemars = { version = "0.8", default-features = false, features = ["uuid1"] }
serde = { version = "1.0", default-features = false }
serde_json = { version = "1.0", default-features = false }
tokio = { version = "1.38", default-features = false }
tracing = { version = "0.1" }
uuid = { version = "1.10", default-features = false, features = ["serde"] }
yew = { version = "0.21", features = ["csr"] }
yew-router = { version = "0.18" }
52 changes: 52 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Copyright (c) 2024 Ho Kim ([email protected]). All rights reserved.
# Use of this source code is governed by a GPL-3-style license that can be
# found in the LICENSE file.

# Configure environment variables
ARG DEBIAN_VERSION="bookworm"
ARG PACKAGE="cassette"

# Be ready for serving
FROM docker.io/library/debian:${DEBIAN_VERSION} as server

# Server Configuration
EXPOSE 6080/tcp
WORKDIR /usr/local/bin
ENTRYPOINT [ "/usr/bin/env" ]
CMD [ "trunk", "serve" ]

# Be ready for building
FROM docker.io/library/rust:1-${DEBIAN_VERSION} as builder

# Load source files
ADD . /src
WORKDIR /src

# Install dependencies
RUN \
# Cache build outputs
--mount=type=cache,target=/src/target \
--mount=type=cache,target=/usr/local/cargo/registry \
# Create an output directory
mkdir /out \
# Build
&& cargo install trunk --root /usr/local \
&& cargo install wasm-bindgen-cli --root /usr/local

# Build it!
RUN \
# Cache build outputs
--mount=type=cache,target=/src/target \
--mount=type=cache,target=/usr/local/cargo/registry \
# Build
&& cargo build --all --workspace --release \
&& find ./target/release/ -maxdepth 1 -type f -perm -a=x -print0 | xargs -0 -I {} mv {} /out \
&& cp ./Trunk.toml /out \
&& mv ./LICENSE /LICENSE

# Copy executable files
FROM server
ARG PACKAGE
COPY --from=builder /out/* /usr/local/bin/
COPY --from=builder /usr/local/bin/* /usr/local/bin/
COPY --from=builder /LICENSE /usr/share/licenses/${PACKAGE}/LICENSE
55 changes: 55 additions & 0 deletions Justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Copyright (c) 2024 Ho Kim ([email protected]). All rights reserved.
# Use of this source code is governed by a GPL-3-style license that can be
# found in the LICENSE file.

# Load environment variables
set dotenv-load

# Configure environment variables
export DEBIAN_VERSION := env_var_or_default('DEBIAN_VERSION', 'bookworm')
export OCI_BUILD_LOG_DIR := env_var_or_default('OCI_BUILD_LOG_DIR', './logs/')
export OCI_IMAGE := env_var_or_default('OCI_IMAGE', 'quay.io/ulagbulag/cassette')
export OCI_IMAGE_VERSION := env_var_or_default('OCI_IMAGE_VERSION', 'latest')
export OCI_PLATFORMS := env_var_or_default('OCI_PLATFORMS', 'linux/arm64,linux/amd64')

default: run

fmt:
cargo fmt --all

clippy: fmt
cargo clippy --all --workspace

test: clippy
cargo test --all --workspace

init:
@rustup target list | grep wasm32-unknown-unknown | grep -q '(installed)' || rustup target add wasm32-unknown-unknown
@which trunk >/dev/null || cargo install trunk
@which wasm-bindgen >/dev/null || cargo install wasm-bindgen-cli

_trunk command *ARGS: init
trunk "{{ command }}" './crates/cassette/index.html' {{ ARGS }}

build *ARGS: ( _trunk "build" ARGS )

run *ARGS: ( _trunk "serve" ARGS )

run-gateway *ARGS:
cargo run --package 'cassette-gateway' --release

run-operator *ARGS:
cargo run --package 'cassette-operator' --release

oci-build *ARGS:
mkdir -p "${OCI_BUILD_LOG_DIR}"
docker buildx build \
--file './Dockerfile' \
--tag "${OCI_IMAGE}:${OCI_IMAGE_VERSION}" \
--build-arg DEBIAN_VERSION="${DEBIAN_VERSION}" \
--platform "${OCI_PLATFORMS}" \
--pull \
{{ ARGS }} \
. 2>&1 | tee "${OCI_BUILD_LOG_DIR}/build-base-$( date -u +%s ).log"

oci-push: (oci-build "--push")
Loading

0 comments on commit f74e51e

Please sign in to comment.