feat: add actual alloy component
Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
parent
be4d755d51
commit
fcce281da3
199
alloy/Cargo.lock
generated
199
alloy/Cargo.lock
generated
@ -6,6 +6,7 @@ version = 4
|
||||
name = "alloy"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"dirs",
|
||||
"wit-bindgen-rt",
|
||||
]
|
||||
|
||||
@ -15,6 +16,204 @@ version = "2.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de"
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||
|
||||
[[package]]
|
||||
name = "dirs"
|
||||
version = "5.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "44c45a9d03d6676652bcb5e724c7e988de1acad23a711b5217ab9cbecbec2225"
|
||||
dependencies = [
|
||||
"dirs-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dirs-sys"
|
||||
version = "0.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "520f05a5cbd335fae5a99ff7a6ab8627577660ee5cfd6a94a6a929b52ff0321c"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"option-ext",
|
||||
"redox_users",
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "getrandom"
|
||||
version = "0.2.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"wasi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.167"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "09d6582e104315a817dff97f75133544b2e094ee22447d2acf4a74e189ba06fc"
|
||||
|
||||
[[package]]
|
||||
name = "libredox"
|
||||
version = "0.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "option-ext"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.92"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "37d3544b3f2748c54e147655edb5025752e2303145b5aefb3c3ea2c78b973bb0"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.37"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "redox_users"
|
||||
version = "0.4.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ba009ff324d1fc1b900bd1fdb31564febe58a8ccc8a6fdbb93b543d33b13ca43"
|
||||
dependencies = [
|
||||
"getrandom",
|
||||
"libredox",
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.90"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "919d3b74a5dd0ccd15aeb8f93e7006bd9e14c295087c9896a110f490752bcf31"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "1.0.69"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52"
|
||||
dependencies = [
|
||||
"thiserror-impl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror-impl"
|
||||
version = "1.0.69"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83"
|
||||
|
||||
[[package]]
|
||||
name = "wasi"
|
||||
version = "0.11.0+wasi-snapshot-preview1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
|
||||
|
||||
[[package]]
|
||||
name = "windows-sys"
|
||||
version = "0.48.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9"
|
||||
dependencies = [
|
||||
"windows-targets",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-targets"
|
||||
version = "0.48.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c"
|
||||
dependencies = [
|
||||
"windows_aarch64_gnullvm",
|
||||
"windows_aarch64_msvc",
|
||||
"windows_i686_gnu",
|
||||
"windows_i686_msvc",
|
||||
"windows_x86_64_gnu",
|
||||
"windows_x86_64_gnullvm",
|
||||
"windows_x86_64_msvc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_gnullvm"
|
||||
version = "0.48.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8"
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_msvc"
|
||||
version = "0.48.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_gnu"
|
||||
version = "0.48.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_msvc"
|
||||
version = "0.48.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnu"
|
||||
version = "0.48.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnullvm"
|
||||
version = "0.48.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_msvc"
|
||||
version = "0.48.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538"
|
||||
|
||||
[[package]]
|
||||
name = "wit-bindgen-rt"
|
||||
version = "0.36.0"
|
||||
|
@ -4,6 +4,7 @@ version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
dirs = "5.0.1"
|
||||
wit-bindgen-rt = { version = "0.36.0", features = ["bitflags"] }
|
||||
|
||||
[lib]
|
||||
|
84
alloy/files/config.alloy
Normal file
84
alloy/files/config.alloy
Normal file
@ -0,0 +1,84 @@
|
||||
// Sample config for Alloy.
|
||||
//
|
||||
// For a full configuration reference, see https://grafana.com/docs/alloy
|
||||
logging {
|
||||
level = "warn"
|
||||
}
|
||||
|
||||
prometheus.exporter.unix "default" {
|
||||
include_exporter_metrics = true
|
||||
disable_collectors = ["mdadm"]
|
||||
}
|
||||
|
||||
prometheus.scrape "default" {
|
||||
targets = array.concat(
|
||||
prometheus.exporter.unix.default.targets,
|
||||
[{
|
||||
// Self-collect metrics
|
||||
job = "alloy",
|
||||
__address__ = "127.0.0.1:12345",
|
||||
group = "infrastructure",
|
||||
}],
|
||||
)
|
||||
|
||||
forward_to = [
|
||||
// TODO: components to forward metrics to (like prometheus.remote_write or
|
||||
// prometheus.relabel).
|
||||
prometheus.remote_write.default.receiver,
|
||||
]
|
||||
}
|
||||
|
||||
prometheus.remote_write "default" {
|
||||
external_labels = {
|
||||
"node" = "new-node",
|
||||
}
|
||||
|
||||
endpoint {
|
||||
url = "https://prometheus.i.kjuulh.io/api/v1/write"
|
||||
}
|
||||
}
|
||||
|
||||
local.file_match "local_files" {
|
||||
path_targets = [{"__path__" = "/var/log/*.log"}]
|
||||
sync_period = "5s"
|
||||
}
|
||||
|
||||
loki.source.file "log_scrape" {
|
||||
targets = local.file_match.local_files.targets
|
||||
forward_to = [loki.process.filter_logs.receiver]
|
||||
tail_from_end = true
|
||||
}
|
||||
|
||||
loki.source.journal "default" {
|
||||
forward_to = [loki.process.filter_logs.receiver]
|
||||
}
|
||||
|
||||
discovery.docker "linux" {
|
||||
host = "unix:///var/run/docker.sock"
|
||||
}
|
||||
|
||||
loki.source.docker "default" {
|
||||
host = "unix:///var/run/docker.sock"
|
||||
targets = discovery.docker.linux.targets
|
||||
labels = {"app" = "docker"}
|
||||
forward_to = [loki.write.grafana_loki.receiver]
|
||||
}
|
||||
|
||||
loki.process "filter_logs" {
|
||||
stage.drop {
|
||||
source = ""
|
||||
expression = ".*Connection closed by authenticating user root"
|
||||
drop_counter_reason = "noisy"
|
||||
}
|
||||
forward_to = [loki.write.grafana_loki.receiver]
|
||||
}
|
||||
|
||||
loki.write "grafana_loki" {
|
||||
external_labels = {
|
||||
"node" = "new-node",
|
||||
}
|
||||
|
||||
endpoint {
|
||||
url = "https://loki.i.kjuulh.io/loki/api/v1/push"
|
||||
}
|
||||
}
|
@ -1,4 +1,136 @@
|
||||
#[allow(dead_code)]
|
||||
pub mod component {
|
||||
#[allow(dead_code)]
|
||||
pub mod churn_tasks {
|
||||
#[allow(dead_code, clippy::all)]
|
||||
pub mod process {
|
||||
#[used]
|
||||
#[doc(hidden)]
|
||||
static __FORCE_SECTION_REF: fn() = super::super::super::__link_custom_section_describing_imports;
|
||||
use super::super::super::_rt;
|
||||
#[derive(Debug)]
|
||||
#[repr(transparent)]
|
||||
pub struct Process {
|
||||
handle: _rt::Resource<Process>,
|
||||
}
|
||||
impl Process {
|
||||
#[doc(hidden)]
|
||||
pub unsafe fn from_handle(handle: u32) -> Self {
|
||||
Self {
|
||||
handle: _rt::Resource::from_handle(handle),
|
||||
}
|
||||
}
|
||||
#[doc(hidden)]
|
||||
pub fn take_handle(&self) -> u32 {
|
||||
_rt::Resource::take_handle(&self.handle)
|
||||
}
|
||||
#[doc(hidden)]
|
||||
pub fn handle(&self) -> u32 {
|
||||
_rt::Resource::handle(&self.handle)
|
||||
}
|
||||
}
|
||||
unsafe impl _rt::WasmResource for Process {
|
||||
#[inline]
|
||||
unsafe fn drop(_handle: u32) {
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
unreachable!();
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
{
|
||||
#[link(
|
||||
wasm_import_module = "component:churn-tasks/process@0.1.0"
|
||||
)]
|
||||
extern "C" {
|
||||
#[link_name = "[resource-drop]process"]
|
||||
fn drop(_: u32);
|
||||
}
|
||||
drop(_handle);
|
||||
}
|
||||
}
|
||||
}
|
||||
impl Process {
|
||||
#[allow(unused_unsafe, clippy::all)]
|
||||
pub fn new() -> Self {
|
||||
unsafe {
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
#[link(
|
||||
wasm_import_module = "component:churn-tasks/process@0.1.0"
|
||||
)]
|
||||
extern "C" {
|
||||
#[link_name = "[constructor]process"]
|
||||
fn wit_import() -> i32;
|
||||
}
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
fn wit_import() -> i32 {
|
||||
unreachable!()
|
||||
}
|
||||
let ret = wit_import();
|
||||
Process::from_handle(ret as u32)
|
||||
}
|
||||
}
|
||||
}
|
||||
impl Process {
|
||||
#[allow(unused_unsafe, clippy::all)]
|
||||
pub fn run_process(&self, inputs: &[_rt::String]) -> _rt::String {
|
||||
unsafe {
|
||||
#[repr(align(4))]
|
||||
struct RetArea([::core::mem::MaybeUninit<u8>; 8]);
|
||||
let mut ret_area = RetArea(
|
||||
[::core::mem::MaybeUninit::uninit(); 8],
|
||||
);
|
||||
let vec1 = inputs;
|
||||
let len1 = vec1.len();
|
||||
let layout1 = _rt::alloc::Layout::from_size_align_unchecked(
|
||||
vec1.len() * 8,
|
||||
4,
|
||||
);
|
||||
let result1 = if layout1.size() != 0 {
|
||||
let ptr = _rt::alloc::alloc(layout1).cast::<u8>();
|
||||
if ptr.is_null() {
|
||||
_rt::alloc::handle_alloc_error(layout1);
|
||||
}
|
||||
ptr
|
||||
} else {
|
||||
::core::ptr::null_mut()
|
||||
};
|
||||
for (i, e) in vec1.into_iter().enumerate() {
|
||||
let base = result1.add(i * 8);
|
||||
{
|
||||
let vec0 = e;
|
||||
let ptr0 = vec0.as_ptr().cast::<u8>();
|
||||
let len0 = vec0.len();
|
||||
*base.add(4).cast::<usize>() = len0;
|
||||
*base.add(0).cast::<*mut u8>() = ptr0.cast_mut();
|
||||
}
|
||||
}
|
||||
let ptr2 = ret_area.0.as_mut_ptr().cast::<u8>();
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
#[link(
|
||||
wasm_import_module = "component:churn-tasks/process@0.1.0"
|
||||
)]
|
||||
extern "C" {
|
||||
#[link_name = "[method]process.run-process"]
|
||||
fn wit_import(_: i32, _: *mut u8, _: usize, _: *mut u8);
|
||||
}
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
fn wit_import(_: i32, _: *mut u8, _: usize, _: *mut u8) {
|
||||
unreachable!()
|
||||
}
|
||||
wit_import((self).handle() as i32, result1, len1, ptr2);
|
||||
let l3 = *ptr2.add(0).cast::<*mut u8>();
|
||||
let l4 = *ptr2.add(4).cast::<usize>();
|
||||
let len5 = l4;
|
||||
let bytes5 = _rt::Vec::from_raw_parts(l3.cast(), len5, len5);
|
||||
if layout1.size() != 0 {
|
||||
_rt::alloc::dealloc(result1.cast(), layout1);
|
||||
}
|
||||
_rt::string_lift(bytes5)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#[allow(dead_code)]
|
||||
pub mod exports {
|
||||
#[allow(dead_code)]
|
||||
pub mod component {
|
||||
@ -82,6 +214,90 @@ pub mod exports {
|
||||
}
|
||||
}
|
||||
mod _rt {
|
||||
use core::fmt;
|
||||
use core::marker;
|
||||
use core::sync::atomic::{AtomicU32, Ordering::Relaxed};
|
||||
/// A type which represents a component model resource, either imported or
|
||||
/// exported into this component.
|
||||
///
|
||||
/// This is a low-level wrapper which handles the lifetime of the resource
|
||||
/// (namely this has a destructor). The `T` provided defines the component model
|
||||
/// intrinsics that this wrapper uses.
|
||||
///
|
||||
/// One of the chief purposes of this type is to provide `Deref` implementations
|
||||
/// to access the underlying data when it is owned.
|
||||
///
|
||||
/// This type is primarily used in generated code for exported and imported
|
||||
/// resources.
|
||||
#[repr(transparent)]
|
||||
pub struct Resource<T: WasmResource> {
|
||||
handle: AtomicU32,
|
||||
_marker: marker::PhantomData<T>,
|
||||
}
|
||||
/// A trait which all wasm resources implement, namely providing the ability to
|
||||
/// drop a resource.
|
||||
///
|
||||
/// This generally is implemented by generated code, not user-facing code.
|
||||
#[allow(clippy::missing_safety_doc)]
|
||||
pub unsafe trait WasmResource {
|
||||
/// Invokes the `[resource-drop]...` intrinsic.
|
||||
unsafe fn drop(handle: u32);
|
||||
}
|
||||
impl<T: WasmResource> Resource<T> {
|
||||
#[doc(hidden)]
|
||||
pub unsafe fn from_handle(handle: u32) -> Self {
|
||||
debug_assert!(handle != u32::MAX);
|
||||
Self {
|
||||
handle: AtomicU32::new(handle),
|
||||
_marker: marker::PhantomData,
|
||||
}
|
||||
}
|
||||
/// Takes ownership of the handle owned by `resource`.
|
||||
///
|
||||
/// Note that this ideally would be `into_handle` taking `Resource<T>` by
|
||||
/// ownership. The code generator does not enable that in all situations,
|
||||
/// unfortunately, so this is provided instead.
|
||||
///
|
||||
/// Also note that `take_handle` is in theory only ever called on values
|
||||
/// owned by a generated function. For example a generated function might
|
||||
/// take `Resource<T>` as an argument but then call `take_handle` on a
|
||||
/// reference to that argument. In that sense the dynamic nature of
|
||||
/// `take_handle` should only be exposed internally to generated code, not
|
||||
/// to user code.
|
||||
#[doc(hidden)]
|
||||
pub fn take_handle(resource: &Resource<T>) -> u32 {
|
||||
resource.handle.swap(u32::MAX, Relaxed)
|
||||
}
|
||||
#[doc(hidden)]
|
||||
pub fn handle(resource: &Resource<T>) -> u32 {
|
||||
resource.handle.load(Relaxed)
|
||||
}
|
||||
}
|
||||
impl<T: WasmResource> fmt::Debug for Resource<T> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.debug_struct("Resource").field("handle", &self.handle).finish()
|
||||
}
|
||||
}
|
||||
impl<T: WasmResource> Drop for Resource<T> {
|
||||
fn drop(&mut self) {
|
||||
unsafe {
|
||||
match self.handle.load(Relaxed) {
|
||||
u32::MAX => {}
|
||||
other => T::drop(other),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
pub use alloc_crate::string::String;
|
||||
pub use alloc_crate::alloc;
|
||||
pub use alloc_crate::vec::Vec;
|
||||
pub unsafe fn string_lift(bytes: Vec<u8>) -> String {
|
||||
if cfg!(debug_assertions) {
|
||||
String::from_utf8(bytes).unwrap()
|
||||
} else {
|
||||
String::from_utf8_unchecked(bytes)
|
||||
}
|
||||
}
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
pub fn run_ctors_once() {
|
||||
wit_bindgen_rt::run_ctors_once();
|
||||
@ -93,8 +309,6 @@ mod _rt {
|
||||
let layout = alloc::Layout::from_size_align_unchecked(size, align);
|
||||
alloc::dealloc(ptr, layout);
|
||||
}
|
||||
pub use alloc_crate::string::String;
|
||||
pub use alloc_crate::alloc;
|
||||
extern crate alloc as alloc_crate;
|
||||
}
|
||||
/// Generates `#[no_mangle]` functions to export the specified type as the
|
||||
@ -130,13 +344,16 @@ pub(crate) use __export_alloy_impl as export;
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
#[link_section = "component-type:wit-bindgen:0.35.0:component:alloy:alloy:encoded world"]
|
||||
#[doc(hidden)]
|
||||
pub static __WIT_BINDGEN_COMPONENT_TYPE: [u8; 244] = *b"\
|
||||
\0asm\x0d\0\x01\0\0\x19\x16wit-component-encoding\x04\0\x07y\x01A\x02\x01A\x02\x01\
|
||||
B\x06\x01@\0\0s\x04\0\x02id\x01\0\x01@\0\0\x7f\x04\0\x0ashould-run\x01\x01\x01@\0\
|
||||
\x01\0\x04\0\x07execute\x01\x02\x04\0\x20component:churn-tasks/task@0.1.0\x05\0\x04\
|
||||
\0\x15component:alloy/alloy\x04\0\x0b\x0b\x01\0\x05alloy\x03\0\0\0G\x09producers\
|
||||
\x01\x0cprocessed-by\x02\x0dwit-component\x070.220.0\x10wit-bindgen-rust\x060.35\
|
||||
.0";
|
||||
pub static __WIT_BINDGEN_COMPONENT_TYPE: [u8; 390] = *b"\
|
||||
\0asm\x0d\0\x01\0\0\x19\x16wit-component-encoding\x04\0\x07\x8a\x02\x01A\x02\x01\
|
||||
A\x04\x01B\x08\x04\0\x07process\x03\x01\x01i\0\x01@\0\0\x01\x04\0\x14[constructo\
|
||||
r]process\x01\x02\x01h\0\x01ps\x01@\x02\x04self\x03\x06inputs\x04\0s\x04\0\x1b[m\
|
||||
ethod]process.run-process\x01\x05\x03\0#component:churn-tasks/process@0.1.0\x05\0\
|
||||
\x01B\x06\x01@\0\0s\x04\0\x02id\x01\0\x01@\0\0\x7f\x04\0\x0ashould-run\x01\x01\x01\
|
||||
@\0\x01\0\x04\0\x07execute\x01\x02\x04\0\x20component:churn-tasks/task@0.1.0\x05\
|
||||
\x01\x04\0\x15component:alloy/alloy\x04\0\x0b\x0b\x01\0\x05alloy\x03\0\0\0G\x09p\
|
||||
roducers\x01\x0cprocessed-by\x02\x0dwit-component\x070.220.0\x10wit-bindgen-rust\
|
||||
\x060.35.0";
|
||||
#[inline(never)]
|
||||
#[doc(hidden)]
|
||||
pub fn __link_custom_section_describing_imports() {
|
||||
|
144
alloy/src/lib.rs
144
alloy/src/lib.rs
@ -1,8 +1,15 @@
|
||||
use bindings::exports::component::churn_tasks::task::Guest;
|
||||
use std::{io::Write, path::PathBuf};
|
||||
|
||||
use bindings::{
|
||||
component::churn_tasks::process::Process, exports::component::churn_tasks::task::Guest,
|
||||
};
|
||||
|
||||
#[allow(warnings)]
|
||||
mod bindings;
|
||||
|
||||
const ALLOY_CONFIG_PATH: &str = "/etc/alloy/config.alloy";
|
||||
const ALLOY_CONFIG_FILE: &str = include_str!("../files/config.alloy");
|
||||
|
||||
struct Component;
|
||||
|
||||
impl Guest for Component {
|
||||
@ -11,12 +18,143 @@ impl Guest for Component {
|
||||
}
|
||||
|
||||
fn should_run() -> bool {
|
||||
true
|
||||
let output = Process::new().run_process(
|
||||
&["systemctl", "is-enabled", "alloy.service"]
|
||||
.into_iter()
|
||||
.map(|i| i.into())
|
||||
.collect::<Vec<String>>(),
|
||||
);
|
||||
|
||||
if !output.contains("enabled") {
|
||||
return true;
|
||||
}
|
||||
|
||||
let output = Process::new().run_process(
|
||||
&["systemctl", "is-active", "alloy.service"]
|
||||
.into_iter()
|
||||
.map(|i| i.into())
|
||||
.collect::<Vec<String>>(),
|
||||
);
|
||||
|
||||
if output.contains("inactive") {
|
||||
return true;
|
||||
}
|
||||
|
||||
match std::fs::read_to_string(ALLOY_CONFIG_PATH) {
|
||||
Ok(content) => return content != ALLOY_CONFIG_FILE,
|
||||
Err(e) => {
|
||||
if e.kind() == std::io::ErrorKind::NotFound {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
false
|
||||
}
|
||||
|
||||
fn execute() {
|
||||
println!("I was run");
|
||||
println!("running alloy installation");
|
||||
|
||||
let output = Process::new().run_process(
|
||||
&["systemctl", "is-enabled", "alloy.service"]
|
||||
.into_iter()
|
||||
.map(|i| i.into())
|
||||
.collect::<Vec<String>>(),
|
||||
);
|
||||
if !output.contains("enabled") {
|
||||
install_alloy().expect("to be able to install alloy");
|
||||
}
|
||||
|
||||
let restart = match std::fs::read_to_string(ALLOY_CONFIG_PATH) {
|
||||
Ok(content) => {
|
||||
if content != ALLOY_CONFIG_FILE {
|
||||
let mut file = std::fs::File::create(ALLOY_CONFIG_PATH)
|
||||
.expect("to be able to create file");
|
||||
file.write_all(ALLOY_CONFIG_FILE.as_bytes())
|
||||
.expect("to be able to write file");
|
||||
file.flush().expect("to be able to flush file");
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
if e.kind() == std::io::ErrorKind::NotFound {
|
||||
if let Some(parent) = PathBuf::from(ALLOY_CONFIG_PATH).parent() {
|
||||
std::fs::create_dir_all(parent)
|
||||
.expect("to be able to create dir for alloy");
|
||||
}
|
||||
|
||||
let mut file = std::fs::File::create(ALLOY_CONFIG_PATH)
|
||||
.expect("to be able to create file");
|
||||
file.write_all(ALLOY_CONFIG_FILE.as_bytes())
|
||||
.expect("to be able to write file");
|
||||
file.flush().expect("to be able to flush file");
|
||||
|
||||
false
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if restart {
|
||||
restart_alloy().expect("to be able to restart alloy");
|
||||
return;
|
||||
}
|
||||
|
||||
let output = Process::new().run_process(
|
||||
&["systemctl", "is-active", "alloy.service"]
|
||||
.into_iter()
|
||||
.map(|i| i.into())
|
||||
.collect::<Vec<String>>(),
|
||||
);
|
||||
if output.contains("inactive") {
|
||||
run_and_activate_alloy().expect("to be able to active alloy");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn install_alloy() -> Result<(), String> {
|
||||
println!("=== installing alloy ===");
|
||||
run_command(["apt", "install", "gpg"])?;
|
||||
run_command(["mkdir", "-p", "/etc/apt/keyrings/"])?;
|
||||
run_command(["bash", "-c", "wget -q -O - https://apt.grafana.com/gpg.key | gpg --dearmor | sudo tee /etc/apt/keyrings/grafana.gpg > /dev/null && echo \"deb [signed-by=/etc/apt/keyrings/grafana.gpg] https://apt.grafana.com stable main\" | sudo tee /etc/apt/sources.list.d/grafana.list"])?;
|
||||
run_command(["apt-get", "update"])?;
|
||||
run_command(["apt-get", "install", "alloy"])?;
|
||||
println!("=== finished installing alloy ===");
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn restart_alloy() -> Result<(), String> {
|
||||
println!("=== restarting alloy ===");
|
||||
run_command(["systemctl", "restart", "alloy"])?;
|
||||
println!("=== finished restarting alloy ===");
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn run_and_activate_alloy() -> Result<(), String> {
|
||||
println!("=== starting alloy ===");
|
||||
run_command(["systemctl", "start", "alloy"])?;
|
||||
println!("=== finished starting alloy ===");
|
||||
|
||||
println!("=== enabling alloy ===");
|
||||
run_command(["systemctl", "enable", "alloy"])?;
|
||||
println!("=== finished enabling alloy ===");
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn run_command(input: impl IntoIterator<Item = impl Into<String>>) -> Result<(), String> {
|
||||
let args = input.into_iter().map(|i| i.into()).collect::<Vec<String>>();
|
||||
|
||||
println!("running {}", args.join(" "));
|
||||
let output = Process::new().run_process(&args);
|
||||
println!("output: {}", output);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
bindings::export!(Component with_types_in bindings);
|
||||
|
@ -2,5 +2,6 @@ package component:alloy;
|
||||
|
||||
/// An example world for the component to target.
|
||||
world alloy {
|
||||
import component:churn-tasks/process@0.1.0;
|
||||
export component:churn-tasks/task@0.1.0;
|
||||
}
|
||||
|
@ -1,5 +1,12 @@
|
||||
package component:churn-tasks@0.1.0;
|
||||
|
||||
interface process {
|
||||
resource process {
|
||||
constructor();
|
||||
run-process: func(inputs: list<string>) -> string;
|
||||
}
|
||||
}
|
||||
|
||||
interface task {
|
||||
id: func() -> string;
|
||||
should-run: func() -> bool;
|
||||
@ -8,4 +15,5 @@ interface task {
|
||||
|
||||
world churn {
|
||||
export task;
|
||||
export process;
|
||||
}
|
||||
|
16
upload.sh
Executable file
16
upload.sh
Executable file
@ -0,0 +1,16 @@
|
||||
#!/usr/bin/env zsh
|
||||
|
||||
set -e
|
||||
|
||||
echo "signing in to onepass"
|
||||
op signin
|
||||
|
||||
export AWS_ACCESS_KEY_ID=$(op read op://personal/minio.front.kjuulh.io/username)
|
||||
export AWS_SECRET_ACCESS_KEY=$(op read op://personal/minio.front.kjuulh.io/password)
|
||||
export AWS_REGION=eu-west-1
|
||||
|
||||
echo "processing: alloy"
|
||||
echo "building rust project"
|
||||
(cd alloy && cargo component build --release)
|
||||
echo "upload"
|
||||
aws s3 cp alloy/target/wasm32-wasip1/release/alloy.wasm s3://churn-registry/alloy/0.1.0/alloy.wasm --endpoint-url https://api-minio.front.kjuulh.io
|
Loading…
Reference in New Issue
Block a user