From: Matthieu Date: Tue, 7 Sep 2021 19:21:11 +0000 (+0400) Subject: add docker publishing X-Git-Tag: v0.1~64^2^2~32 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=3710e8c619bb4d82de51d8e6104c51ae941fa7c3;p=matthieu%2Fnova.git add docker publishing --- diff --git a/.github/workflows/bazel-build.yml b/.github/workflows/bazel-build.yml index 889db34..3e423f9 100644 --- a/.github/workflows/bazel-build.yml +++ b/.github/workflows/bazel-build.yml @@ -36,6 +36,10 @@ jobs: with: path: "~/.cache/bazel" key: bazel-${{ matrix.os }} + - name: Execute Bazel tests + shell: bash + run: | + bazel test ...:all # Runs a set of commands using the runners shell - name: Execute build script shell: bash @@ -46,16 +50,20 @@ jobs: uses: actions/upload-artifact@v2 with: name: all-${{ matrix.os }} - path: bazel-bin*/package_* - - - name: Bazel artifacts zip - uses: actions/upload-artifact@v2 - with: - name: all-${{ matrix.os }} - path: bazel-bin*/package_zip.zip + path: | + bazel-bin*/package_* + bazel-bin*/package_zip.zip + bazel-bin*/package_tar.tar.gz - - name: Bazel artifacts tar - uses: actions/upload-artifact@v2 + - name: Setup docker + - uses: docker-practice/actions-setup-docker@master + - name: Login to GitHub Container Registry + uses: docker/login-action@v1 with: - name: all-${{ matrix.os }} - path: bazel-bin*/package_tar.tar.gz \ No newline at end of file + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Publish docker images + shell: bash + run: | + bazel run //:publish \ No newline at end of file diff --git a/BUILD b/BUILD index 93b5e96..78fd897 100644 --- a/BUILD +++ b/BUILD @@ -1,5 +1,7 @@ load("@bazel_gazelle//:def.bzl", "gazelle") load("@rules_pkg//:pkg.bzl", "pkg_zip", "pkg_tar") +load("@io_bazel_rules_docker//container:container.bzl", "container_bundle") +load("@io_bazel_rules_docker//contrib:push-all.bzl", "container_push") # gazelle:prefix github.com/discordnova/nova gazelle(name = "gazelle") @@ -14,6 +16,20 @@ filegroup( }), ) +container_bundle( + name = "bundle", + + images = { + "ghcr.io/discordnova/nova/novactl:latest": "//novactl:image", + } +) + +container_push( + name = "publish", + bundle = ":bundle", + format = "OCI" +) + pkg_tar( name = "package_tar", extension = "tar.gz", diff --git a/WORKSPACE b/WORKSPACE index d93408c..30926a5 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -1,25 +1,24 @@ +#@unused load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") http_archive( - name = "io_bazel_rules_go", - sha256 = "8e968b5fcea1d2d64071872b12737bbb5514524ee5f0a4f54f5920266c261acb", + name = "com_google_protobuf", + sha256 = "d0f5f605d0d656007ce6c8b5a82df3037e1d8fe8b121ed42e536f569dec16113", + strip_prefix = "protobuf-3.14.0", urls = [ - "https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.28.0/rules_go-v0.28.0.zip", - "https://github.com/bazelbuild/rules_go/releases/download/v0.28.0/rules_go-v0.28.0.zip", + "https://mirror.bazel.build/github.com/protocolbuffers/protobuf/archive/v3.14.0.tar.gz", + "https://github.com/protocolbuffers/protobuf/archive/v3.14.0.tar.gz", ], ) -# Used to generate the go dependencies & build files http_archive( - name = "bazel_gazelle", - sha256 = "62ca106be173579c0a167deb23358fdfe71ffa1e4cfdddf5582af26520f1c66f", + name = "rules_pkg", + sha256 = "a89e203d3cf264e564fcb96b6e06dd70bc0557356eb48400ce4b5d97c2c3720d", urls = [ - "https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/v0.23.0/bazel-gazelle-v0.23.0.tar.gz", - "https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.23.0/bazel-gazelle-v0.23.0.tar.gz", + "https://mirror.bazel.build/github.com/bazelbuild/rules_pkg/releases/download/0.5.1/rules_pkg-0.5.1.tar.gz", + "https://github.com/bazelbuild/rules_pkg/releases/download/0.5.1/rules_pkg-0.5.1.tar.gz", ], ) - -# Used to compile Rust code http_archive( name = "rules_rust", sha256 = "531bdd470728b61ce41cf7604dc4f9a115983e455d46ac1d0c1632f613ab9fc3", @@ -30,64 +29,42 @@ http_archive( ], ) -# Used to generate the protobuf files for go http_archive( - name = "com_google_protobuf", - sha256 = "d0f5f605d0d656007ce6c8b5a82df3037e1d8fe8b121ed42e536f569dec16113", - strip_prefix = "protobuf-3.14.0", + name = "io_bazel_rules_go", + sha256 = "8e968b5fcea1d2d64071872b12737bbb5514524ee5f0a4f54f5920266c261acb", urls = [ - "https://mirror.bazel.build/github.com/protocolbuffers/protobuf/archive/v3.14.0.tar.gz", - "https://github.com/protocolbuffers/protobuf/archive/v3.14.0.tar.gz", + "https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.28.0/rules_go-v0.28.0.zip", + "https://github.com/bazelbuild/rules_go/releases/download/v0.28.0/rules_go-v0.28.0.zip", ], ) http_archive( - name = "rules_pkg", - sha256 = "a89e203d3cf264e564fcb96b6e06dd70bc0557356eb48400ce4b5d97c2c3720d", + name = "bazel_gazelle", + sha256 = "62ca106be173579c0a167deb23358fdfe71ffa1e4cfdddf5582af26520f1c66f", urls = [ - "https://mirror.bazel.build/github.com/bazelbuild/rules_pkg/releases/download/0.5.1/rules_pkg-0.5.1.tar.gz", - "https://github.com/bazelbuild/rules_pkg/releases/download/0.5.1/rules_pkg-0.5.1.tar.gz", + "https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/v0.23.0/bazel-gazelle-v0.23.0.tar.gz", + "https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.23.0/bazel-gazelle-v0.23.0.tar.gz", ], ) -# golang configuration -load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps") - -protobuf_deps() - -load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies") - -go_register_toolchains(version = "1.16.5") - -go_rules_dependencies() - -load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies", "go_repository") -load("//:deps.bzl", "go_dependencies") - -# gazelle:repository_macro deps.bzl%go_dependencies -go_dependencies() - -gazelle_dependencies() - -go_repository( - name = "org_golang_google_grpc", - build_file_proto_mode = "disable", - importpath = "google.golang.org/grpc", - sum = "h1:2dTRdpdFEEhJYQD8EMLB61nnrzSCTbG38PhqdhvOltg=", - version = "v1.26.0", +http_archive( + name = "io_bazel_rules_docker", + sha256 = "1f4e59843b61981a96835dc4ac377ad4da9f8c334ebe5e0bb3f58f80c09735f4", + strip_prefix = "rules_docker-0.19.0", + urls = [ + "https://github.com/bazelbuild/rules_docker/releases/download/v0.19.0/rules_docker-v0.19.0.tar.gz" + ], ) -load("@rules_rust//rust:repositories.bzl", "rust_repositories") - -rust_repositories( - edition = "2018", - iso_date = "2021-06-16", - version = "nightly", -) +load("//bazel:utils.bzl", "get_toolchain_utils_protocolbuffers", "get_toolchain_utils_rules_pkg") +get_toolchain_utils_protocolbuffers() +get_toolchain_utils_rules_pkg() -load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies") +load("//bazel:rust.bzl", "load_rust_toolchains") +load_rust_toolchains() -rules_pkg_dependencies() +load("//bazel:go.bzl", "load_golang_toolchains") +load_golang_toolchains() -load("//cargo:crates.bzl", "raze_fetch_remote_crates") -raze_fetch_remote_crates() \ No newline at end of file +load("//bazel:docker.bzl", "load_docker") +load_docker() \ No newline at end of file diff --git a/bazel/BUILD b/bazel/BUILD new file mode 100644 index 0000000..e69de29 diff --git a/bazel/docker.bzl b/bazel/docker.bzl new file mode 100644 index 0000000..54ac81c --- /dev/null +++ b/bazel/docker.bzl @@ -0,0 +1,18 @@ +""" +""" +load("@io_bazel_rules_docker//toolchains/docker:toolchain.bzl", "toolchain_configure") +load("@io_bazel_rules_docker//repositories:repositories.bzl", "repositories") +load("@io_bazel_rules_docker//repositories:deps.bzl", "deps") +load("@io_bazel_rules_docker//container:container.bzl", "container_pull") +load( + "@io_bazel_rules_docker//go:image.bzl", + _go_image_repos = "repositories", +) + +def load_docker(): + toolchain_configure( + name = "docker_config" + ) + repositories() + deps() + _go_image_repos() \ No newline at end of file diff --git a/bazel/go.bzl b/bazel/go.bzl new file mode 100644 index 0000000..5d25e17 --- /dev/null +++ b/bazel/go.bzl @@ -0,0 +1,29 @@ +""" +Utilities used by the workspace to load the golang toolchain +""" +load("//:deps.bzl", "go_dependencies") +load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies") +load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies", "go_repository") + +def load_golang_toolchains(): + """ + Loads the golang toolchain + """ + + go_register_toolchains(version = "1.16.5") + go_rules_dependencies() + + # Used to generate the go dependencies & build files + + # gazelle:repository_macro deps.bzl%go_dependencies + go_dependencies() + gazelle_dependencies() + + # Fixes a bug with the protobuf generation + go_repository( + name = "org_golang_google_grpc", + build_file_proto_mode = "disable", + importpath = "google.golang.org/grpc", + sum = "h1:2dTRdpdFEEhJYQD8EMLB61nnrzSCTbG38PhqdhvOltg=", + version = "v1.26.0", + ) diff --git a/bazel/rust.bzl b/bazel/rust.bzl new file mode 100644 index 0000000..a6d3e4f --- /dev/null +++ b/bazel/rust.bzl @@ -0,0 +1,17 @@ +""" +Utilities used by the workspace to load the rust toolchain +""" +load("//cargo:crates.bzl", "raze_fetch_remote_crates") +load("@rules_rust//rust:repositories.bzl", "rust_repositories") + +def load_rust_toolchains(): + """ + A simple macro that loads the rust toolchain + """ + rust_repositories( + edition = "2018", + iso_date = "2021-06-16", + version = "nightly", + ) + + raze_fetch_remote_crates() diff --git a/bazel/utils.bzl b/bazel/utils.bzl new file mode 100644 index 0000000..c0143fd --- /dev/null +++ b/bazel/utils.bzl @@ -0,0 +1,17 @@ +""" +Loads the utilities for all the projects +""" +load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps") +load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies") + +def get_toolchain_utils_protocolbuffers(): + """ + Loads protocolbuffers + """ + protobuf_deps() + +def get_toolchain_utils_rules_pkg(): + """ + Load the utilities for packaging the build results + """ + rules_pkg_dependencies() diff --git a/cargo/crates.bzl b/cargo/crates.bzl index c090acb..04782c4 100644 --- a/cargo/crates.bzl +++ b/cargo/crates.bzl @@ -12,8 +12,8 @@ load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") # buildifier: di # EXPERIMENTAL -- MAY CHANGE AT ANY TIME: A mapping of package names to a set of normal dependencies for the Rust targets of that package. _DEPENDENCIES = { "webhook": { - "base64": "@raze__base64__0_13_0//:base64", "config": "@raze__config__0_11_0//:config", + "hex": "@raze__hex__0_4_3//:hex", "hyper": "@raze__hyper__0_14_12//:hyper", "libsodium-sys": "@raze__libsodium_sys__0_2_7//:libsodium_sys", "log": "@raze__log__0_4_14//:log", @@ -578,6 +578,16 @@ def raze_fetch_remote_crates(): build_file = Label("//cargo/remote:BUILD.hermit-abi-0.1.19.bazel"), ) + maybe( + http_archive, + name = "raze__hex__0_4_3", + url = "https://crates.io/api/v1/crates/hex/0.4.3/download", + type = "tar.gz", + sha256 = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70", + strip_prefix = "hex-0.4.3", + build_file = Label("//cargo/remote:BUILD.hex-0.4.3.bazel"), + ) + maybe( http_archive, name = "raze__http__0_2_4", diff --git a/cargo/remote/BUILD.hex-0.4.3.bazel b/cargo/remote/BUILD.hex-0.4.3.bazel new file mode 100644 index 0000000..a0bb458 --- /dev/null +++ b/cargo/remote/BUILD.hex-0.4.3.bazel @@ -0,0 +1,62 @@ +""" +@generated +cargo-raze crate build file. + +DO NOT EDIT! Replaced on runs of cargo-raze +""" + +# buildifier: disable=load +load("@bazel_skylib//lib:selects.bzl", "selects") + +# buildifier: disable=load +load( + "@rules_rust//rust:rust.bzl", + "rust_binary", + "rust_library", + "rust_test", +) + +package(default_visibility = [ + # Public for visibility by "@raze__crate__version//" targets. + # + # Prefer access through "//cargo", which limits external + # visibility to explicit Cargo.toml dependencies. + "//visibility:public", +]) + +licenses([ + "notice", # MIT from expression "MIT OR Apache-2.0" +]) + +# Generated Targets + +# Unsupported target "hex" with type "bench" omitted + +rust_library( + name = "hex", + srcs = glob(["**/*.rs"]), + crate_features = [ + "alloc", + "default", + "std", + ], + crate_root = "src/lib.rs", + crate_type = "lib", + data = [], + edition = "2018", + rustc_flags = [ + "--cap-lints=allow", + ], + tags = [ + "cargo-raze", + "manual", + ], + version = "0.4.3", + # buildifier: leave-alone + deps = [ + ], +) + +# Unsupported target "serde" with type "test" omitted + +# Unsupported target "version-number" with type "test" omitted diff --git a/common/Cargo.toml b/common/Cargo.toml new file mode 100644 index 0000000..cc36f14 --- /dev/null +++ b/common/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "common" +version = "0.1.0" +edition = "2018" + +[dependencies] +tonic = "0.5" +prost = "0.8" +tokio = { version = "1", features = ["full"] } + + +[build-dependencies] +tonic-build = { version = "0.5", features = ["transport", "prost"], default-features = false } + +[dev-dependencies] +tonic-build = { version = "0.5", features = ["transport", "prost"], default-features = false } + diff --git a/common/lib/lib.rs b/common/lib/lib.rs new file mode 100644 index 0000000..45c84fe --- /dev/null +++ b/common/lib/lib.rs @@ -0,0 +1,48 @@ +use std::env; + +use config::{Config, ConfigError, Environment, File}; +use log::info; +use serde::Deserialize; + +/// Executes the required configuration steps for the program, +/// excluding build information, Sentry and logging. +pub fn setup_program(_name: &str) { + pretty_env_logger::init(); +} + +#[derive(Debug, Deserialize, Clone)] +pub struct Server { + pub port: u16, + pub address: String, +} + +#[derive(Debug, Deserialize, Clone)] +pub struct Discord { + pub public_key: String, + pub client_id: u32, +} + +#[derive(Debug, Deserialize, Clone)] +pub struct Settings { + pub server: Server, + pub discord: Discord, +} + +impl Settings { + pub fn new() -> Result { + let mut default = Config::default(); + default.merge(File::with_name("config/default"))?; + let mode = env::var("ENV").unwrap_or_else(|_| "development".into()); + info!("Configuration Environment: {}", mode); + + default.merge(File::with_name(&format!("config/{}", mode)).required(false))?; + default.merge(File::with_name("config/local").required(false))?; + default.merge(Environment::with_prefix("NOVA_GATEWAY"))?; + + println!("Debug mode: {:?}", default.get_bool("debug")); + + let config: Self = default.try_into().unwrap(); + + Ok(config) + } +} diff --git a/novactl/BUILD.bazel b/novactl/BUILD.bazel index 774f6fd..44d9a19 100644 --- a/novactl/BUILD.bazel +++ b/novactl/BUILD.bazel @@ -1,4 +1,5 @@ load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library") +load("@io_bazel_rules_docker//go:image.bzl", "go_image") go_library( name = "novactl_lib", @@ -16,3 +17,9 @@ go_binary( embed = [":novactl_lib"], visibility = ["//visibility:public"], ) + +go_image( + name = "image", + embed = [":novactl_lib"], + visibility = ["//visibility:public"], +) \ No newline at end of file diff --git a/ratelimiter/lib/lib.rs b/ratelimiter/lib/lib.rs deleted file mode 100644 index 6eda7c4..0000000 --- a/ratelimiter/lib/lib.rs +++ /dev/null @@ -1 +0,0 @@ -// Some implementation here. \ No newline at end of file diff --git a/ratelimiter/proto/BUILD.bazel b/ratelimiter/proto/BUILD.bazel index ffb258d..247554e 100644 --- a/ratelimiter/proto/BUILD.bazel +++ b/ratelimiter/proto/BUILD.bazel @@ -1,26 +1 @@ -load("@rules_proto//proto:defs.bzl", "proto_library") -load("@io_bazel_rules_go//go:def.bzl", "go_library") -load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library") - exports_files(["nova.ratelimit.v1.proto"]) - -proto_library( - name = "nova_ratelimit_v1_proto", - srcs = ["nova.ratelimit.v1.proto"], - visibility = ["//visibility:public"], -) - -go_proto_library( - name = "nova_ratelimit_v1_go_proto", - compilers = ["@io_bazel_rules_go//proto:go_grpc"], - importpath = "github.com/discordnova/nova/ratelimiter/proto", - proto = ":nova_ratelimit_v1_proto", - visibility = ["//visibility:public"], -) - -go_library( - name = "proto", - embed = [":nova_ratelimit_v1_go_proto"], - importpath = "github.com/discordnova/nova/ratelimiter/proto", - visibility = ["//visibility:public"], -) diff --git a/webhook/cargo/BUILD.bazel b/webhook/cargo/BUILD.bazel index f65c3b7..cb1c9cd 100644 --- a/webhook/cargo/BUILD.bazel +++ b/webhook/cargo/BUILD.bazel @@ -13,8 +13,8 @@ licenses([ # Aliased targets alias( - name = "base64", - actual = "@raze__base64__0_13_0//:base64", + name = "config", + actual = "@raze__config__0_11_0//:config", tags = [ "cargo-raze", "manual", @@ -22,8 +22,8 @@ alias( ) alias( - name = "config", - actual = "@raze__config__0_11_0//:config", + name = "hex", + actual = "@raze__hex__0_4_3//:hex", tags = [ "cargo-raze", "manual", diff --git a/webhook/src/handle.rs b/webhook/src/handle.rs index ef3ebe1..d240d2b 100644 --- a/webhook/src/handle.rs +++ b/webhook/src/handle.rs @@ -89,7 +89,7 @@ impl Service> for HandlerService { if t == 1 { info!("success!"); - + return Ok(Response::builder().header("Content-Type", "application/json").body(serde_json::to_string(&Ping { t: 1 }).unwrap().into()).unwrap()); @@ -141,16 +141,16 @@ mod test { #[test] fn validate_signature_test() { - let signature = "VD7DVH1X+d2x7ExcNlA+vyiP/aPaPVEHZMmknCq7V2kO+XTGPRdHcb3SSB3hBmlm9Xq77BKj7Bcbn24jc4NwAg=="; - let public_key = "7v4MJEc3N8sgNSMuO065HCBvChRoQWjzUD99gxYFjW8="; + let signature = "543ec3547d57f9ddb1ec4c5c36503ebf288ffda3da3d510764c9a49c2abb57690ef974c63d174771bdd2481de1066966f57abbec12a3ec171b9f6e2373837002"; + let public_key = "eefe0c24473737cb2035232e3b4eb91c206f0a14684168f3503f7d8316058d6f"; let content = "message de test incroyable".as_bytes().to_vec(); assert!(validate_signature(public_key, &content, signature)) } #[test] fn validate_signature_reverse_test() { - let signature = "VD7DVH1X+d2x7ExcNlA+vyiP/aPaPVEHZMmknCq7V2kO+XTGPRdHcb3SSB3hBmlm9Xq77BKj7Bcbn24jc4NwAg=="; - let public_key = "wCnuoYQ3KSyHxirsNOfRvU44/mEm8/fERt5jddxmYEQ="; + let signature = "543ec3547d57f9ddb1ec4c5c36503ebf288ffda3da3d510764c9a49c2abb57690ef974c63d174771bdd2481de1066966f57abbec12a3ec171b9f6e2373837002"; + let public_key = "c029eea18437292c87c62aec34e7d1bd4e38fe6126f3f7c446de6375dc666044"; let content = "ceci est un test qui ne fonctionnera pas!" .as_bytes() .to_vec(); @@ -158,7 +158,7 @@ mod test { } #[test] - fn invalid_base64() { + fn invalid_hex() { let signature = "zzz"; let public_key = "zzz"; let content = "ceci est un test qui ne fonctionnera pas!"