Skip to content

Commit

Permalink
[infra] Change Bazel macro locations, add patch/delete for repository…
Browse files Browse the repository at this point in the history
… db controller
  • Loading branch information
auguwu committed Sep 1, 2023
1 parent fdeac75 commit cb1faa8
Show file tree
Hide file tree
Showing 66 changed files with 1,044 additions and 655 deletions.
File renamed without changes.
5 changes: 0 additions & 5 deletions .coder/scripts/pre-init/symlink.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,3 @@ if ! [ -L "/usr/local/bin/buildifier" ]; then
echo "===> Symlinking \`bazel-buildifier\` ~> \`buildifier\`!"
sudo ln -s /usr/local/bin/bazel-buildifier /usr/local/bin/buildifier
fi

if ! [ -L "/usr/local/bin/sync-deps" ]; then
echo "===> Symlinking ./scripts/sync_deps.sh ~> sync-deps"
sudo ln -s $HOME/workspace/scripts/sync_deps.sh /usr/local/bin/sync-deps
fi
6 changes: 0 additions & 6 deletions .github/workflows/CI.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,6 @@ jobs:
- name: Build Helm plugin
run: bazel ${{env.BAZEL_ARGS}} build --disk_cache=${{runner.temp}}/_bazel_${{runner.os}}_${{runner.arch}} //:helm-plugin

- name: Build search indexer
run: bazel ${{env.BAZEL_ARGS}} build --disk_cache=${{runner.temp}}/_bazel_${{runner.os}}_${{runner.arch}} //:search-indexer

- name: Build emails microservice
run: bazel ${{env.BAZEL_ARGS}} build --disk_cache=${{runner.temp}}/_bazel_${{runner.os}}_${{runner.arch}} //:emails

# TODO: include clippy, rustfmt, golangci-lint, and testing ci tailoured
# to GitHub Actions.
- name: Run tests
Expand Down
636 changes: 359 additions & 277 deletions .github/workflows/Release.yaml

Large diffs are not rendered by default.

18 changes: 3 additions & 15 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -41,30 +41,18 @@ exports_files([

alias(
name = "helm-plugin",
actual = "//tools/helm-plugin:binary",
actual = "//tools/helm-plugin",
visibility = ["//visibility:public"],
)

alias(
name = "cli",
actual = "//cli:binary",
actual = "//cli",
visibility = ["//visibility:public"],
)

alias(
name = "devtools",
actual = "//tools/devtools:release_binary",
visibility = ["//visibility:public"],
)

alias(
name = "search-indexer",
actual = "//services/search-indexer:binary",
visibility = ["//visibility:public"],
)

alias(
name = "emails",
actual = "//services/emails:binary",
actual = "//tools/devtools",
visibility = ["//visibility:public"],
)
1 change: 1 addition & 0 deletions Cargo.lock

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

21 changes: 13 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ To build charted-server from the canonical Git repository, you are required to h

* [Bazel](https://bazel.build)
* [Git](https://git-scm.com)
* 10GB of storage
* 2GB of system RAM
* 4GB of storage

To clone the repository, you can use the `git pull` command:

Expand All @@ -32,33 +32,38 @@ $ git pull https://github.com/charted-dev/charted
$ git pull git@github.com:charted-dev/charted
```

Once you cloned the repository, you can `cd` into it and run `bazel build //cli:release_binary`:
Once you cloned the repository, you can `cd` into it and run `bazel build //cli`:

```shell
$ bazel build //cli:release_binary
$ bazel build //cli
```

This will build the charted CLI in release mode, to run it, you can use `run` instead of `build`:

```shell
$ bazel run //cli:release_binary
$ bazel run //cli
```

This will run the actual CLI, to run the server, you will need to append `-- server --config=$PWD/config.yml`:

```shell
$ bazel run //cli:release_binary -- server --config=$PWD/config.yml
$ bazel run //cli -- server --config=$PWD/config.yml
```

> **Note**: The `--config=$PWD/config.yml` is required when you invoke Bazel by itself since it'll run it in
> the sandbox if you're on Linux or macOS.
## FAQ
### :question: Why Bazel? Couldn't you done this with `node`, `cargo`, and `go` together?
**Bazel** is a build tool by Google to provide fast and correct builds, and can handle multiple languages in the same workspace. While it is possible to use `node` (Node.js), `cargo` (Rust), and `go` (Golang) together, we don't recommend it as we are tailouring the workflow to Bazel only.
### :question: Why Bazel? Couldn't you done this with `node` and `cargo` together?
**Bazel** is a build tool by Google to provide fast and correct builds, and can handle multiple languages in the same workspace. While it is possible to use `node` (Node.js) and `cargo` (Rust) together, we don't recommend it as we are tailouring the workflow to Bazel only.

### :question: Can I use `cargo install` from the Git repository?
Yes, but soon we plan to drop Cargo support since Cargo is only available for [rust-analyzer](https://github.com/rust-lang/rust-analyzer) and IDE support.
Yes! We will try to keep Cargo as a second alternative for people who use `cargo install` and for IDE support like Visual Studio Code. Since the repository has multiple binaries, here is what binary to pass in what you want:

* [charted CLI](https://charts.noelware.org/docs/cli/latest): `cargo install https://github.com/charted-dev/charted charted-cli`
* [charted Helm plugin](https://charts.noelware.org/docs/helm-plugin/latest): `cargo install https://github.com/charted-dev/charted charted-helm-plugin`

We don't recommend installing `charted-devtools` as it will require a Bazel installation.

## License
**charted-server** is released under the **Apache 2.0** License with love by Noelware, LLC.! If you wish to know more,
Expand Down
File renamed without changes.
36 changes: 13 additions & 23 deletions build/rust_project.bzl → build/rust.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@

""" Common macro through-out all Rust crates. """

load("@rules_rust//rust:defs.bzl", "rust_binary", "rust_doc_test", "rust_library", "rust_proc_macro", "rust_test")
load("@rules_rust//cargo:defs.bzl", "cargo_build_script")
load("@crate_index//:defs.bzl", "aliases")
load("@rules_rust//cargo:defs.bzl", "cargo_build_script")
load("@rules_rust//rust:defs.bzl", "rust_binary", "rust_doc_test", "rust_library", "rust_proc_macro", "rust_test", "rust_test_suite")

def rust_project(
name,
Expand Down Expand Up @@ -71,7 +71,7 @@ def rust_project(
rust_library(
# We need it as charted_<name> so it can be referenced with Bazel
# without using 'extern crate {name}'!
name = "charted_{name}".format(name = name),
name = "charted_%s" % name,
aliases = aliases(),
data = external_data,
srcs = native.glob(["src/**/*.rs"], exclude = ["src/main.rs"]) + srcs,
Expand All @@ -84,7 +84,15 @@ def rust_project(
if include_tests:
rust_test(
name = "tests",
srcs = native.glob(["src/**/*.rs", "tests/**/*.rs"], exclude = ["src/main.rs"]),
srcs = native.glob(["src/**/*.rs"], exclude = ["src/main.rs"]),
deps = [":charted_{name}".format(name = name)] + deps + test_deps,
compile_data = external_data,
proc_macro_deps = proc_macro_deps,
)

rust_test_suite(
name = "integ_tests",
srcs = native.glob(["tests/**/*.rs"]),
deps = [":charted_{name}".format(name = name)] + deps + test_deps,
compile_data = external_data,
proc_macro_deps = proc_macro_deps,
Expand All @@ -98,31 +106,13 @@ def rust_project(

if is_binary:
rust_binary(
name = "binary",
name = name,
srcs = ["src/main.rs"],
deps = [":charted_{name}".format(name = name)] + deps,
rustc_flags = ["-C", "incremental=true"],
visibility = ["//visibility:public"],
)

rust_binary(
name = "release_binary",
srcs = ["src/main.rs"],
deps = [":charted_{name}".format(name = name)] + deps,
rustc_flags = [
"-C",
"debug-assertions=off",
"-C",
"opt-level=s",
"-C",
"lto=fat",
"-C",
"incremental=true",
"-Dwarnings",
],
visibility = ["//visibility:public"],
)

if build_script:
cargo_build_script(
name = "buildscript",
Expand Down
3 changes: 2 additions & 1 deletion cli/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

load("//:build/rust_project.bzl", "rust_project")
load("//:build/rust.bzl", "rust_project")

exports_files(["Cargo.toml"])

Expand All @@ -24,6 +24,7 @@ rust_project(
deps = [
"//crates/common:charted_common",
"//crates/config:charted_config",
"//crates/database:charted_database",
"//crates/logging:charted_logging",
"//server:charted_server",
"@crate_index//:ansi_term",
Expand Down
1 change: 1 addition & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,4 @@ sysinfo = "0.29.4"
tokio = { version = "1.29.1", features = ["full"] }
tracing = "0.1.37"
tracing-subscriber = "0.3.17"
charted-database = { version = "0.0.0-devel.0", path = "../crates/database" }
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,3 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use super::Service;

#[derive(Debug, Clone, Copy)]
pub struct Emails;

impl Service for Emails {
fn targets(&self) -> (&'static str, &'static str) {
("//services/emails:release_binary", "//services/emails:binary")
}
}
37 changes: 22 additions & 15 deletions cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,41 @@
// See the License for the specific language governing permissions and
// limitations under the License.

mod gc;
mod generate_config;
mod migrations;
mod openapi;
mod organizations;
mod repositories;
mod search;
mod server;
mod users;
mod version;

use crate::commands::generate_config::*;
use crate::commands::openapi::*;
use crate::commands::server::*;
use crate::commands::version::*;
use charted_common::cli::*;
use clap::Subcommand;
use eyre::Result;

#[derive(Debug, Clone, Subcommand)]
pub enum Commands {
GenerateConfig(GenerateConfig),
GenerateConfig(generate_config::GenerateConfig),
OpenAPI(openapi::OpenAPI),
Version(version::Version),
Server(server::Server),

#[command(name = "openapi")]
OpenAPI(OpenAPI),
Server(Box<Server>),
Version(Version),
#[command(subcommand)]
Users(users::Users),
}

pub async fn execute(command: &Commands) -> Result<()> {
match command {
Commands::Server(server) => server.execute().await,
Commands::Version(version) => version.execute(),
Commands::OpenAPI(openapi) => openapi.execute(),
Commands::GenerateConfig(generate) => generate.execute().await,
#[async_trait]
impl AsyncExecute for Commands {
async fn execute(&self) -> Result<()> {
match self {
Commands::Server(server) => server.execute().await,
Commands::Users(users) => users.execute().await,
Commands::Version(version) => version.execute(),
Commands::OpenAPI(openapi) => openapi.execute(),
Commands::GenerateConfig(generate) => generate.execute().await,
}
}
}
5 changes: 4 additions & 1 deletion cli/src/commands/openapi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ use std::{
};

#[derive(Debug, Clone, clap::Parser)]
#[command(about = "Generates the OpenAPI document without running the API server")]
#[command(
name = "openapi",
about = "Generates the OpenAPI document without running the API server"
)]
pub struct OpenAPI {
#[arg(help = "Output file to use. If this is not specified, then it will be written to stdout.")]
output: Option<PathBuf>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,3 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use super::Service;

#[derive(Debug, Clone, Copy)]
pub struct SearchIndexer;

impl Service for SearchIndexer {
fn targets(&self) -> (&'static str, &'static str) {
("//services/search-indexer:binary", "//services/search-indexer:binary")
}
}
14 changes: 14 additions & 0 deletions cli/src/commands/repositories/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// 🐻‍❄️📦 charted-server: Free, open source, and reliable Helm Chart registry made in Rust
// Copyright 2022-2023 Noelware, LLC. <team@noelware.org>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
14 changes: 14 additions & 0 deletions cli/src/commands/search/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// 🐻‍❄️📦 charted-server: Free, open source, and reliable Helm Chart registry made in Rust
// Copyright 2022-2023 Noelware, LLC. <team@noelware.org>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
14 changes: 14 additions & 0 deletions cli/src/commands/users/create.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// 🐻‍❄️📦 charted-server: Free, open source, and reliable Helm Chart registry made in Rust
// Copyright 2022-2023 Noelware, LLC. <team@noelware.org>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
14 changes: 14 additions & 0 deletions cli/src/commands/users/delete.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// 🐻‍❄️📦 charted-server: Free, open source, and reliable Helm Chart registry made in Rust
// Copyright 2022-2023 Noelware, LLC. <team@noelware.org>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
Loading

0 comments on commit cb1faa8

Please sign in to comment.