Initial stub
This commit is contained in:
commit
ce342afe2e
9 changed files with 1674 additions and 0 deletions
4
.dockerignore
Normal file
4
.dockerignore
Normal file
|
@ -0,0 +1,4 @@
|
|||
*
|
||||
!src
|
||||
!Cargo.lock
|
||||
!Cargo.toml
|
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
/target
|
||||
/out
|
3
.nyoki
Normal file
3
.nyoki
Normal file
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"instanceId": "08f6038d-7e5b-48be-96bb-a7ad30d1bb0e"
|
||||
}
|
1534
Cargo.lock
generated
Normal file
1534
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load diff
11
Cargo.toml
Normal file
11
Cargo.toml
Normal file
|
@ -0,0 +1,11 @@
|
|||
[package]
|
||||
name = "nyans"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
rocket = { version = "0.5.0-rc.2", features = ["json"]}
|
||||
|
||||
serde = "1.0.143"
|
29
Dockerfile
Normal file
29
Dockerfile
Normal file
|
@ -0,0 +1,29 @@
|
|||
FROM rust:alpine AS build
|
||||
|
||||
# Fix missing crti.o by adding muslc devlibs
|
||||
RUN apk add --no-cache musl-dev
|
||||
|
||||
WORKDIR /usr/src
|
||||
|
||||
COPY . .
|
||||
|
||||
ENV CARGO_HOME=/tmp/cargo
|
||||
|
||||
RUN --mount=type=cache,target=/usr/src/target --mount=type=cache,target=/tmp/cargo cargo build --release
|
||||
RUN --mount=type=cache,target=/usr/src/target cp /usr/src/target/release/nyans /tmp/nyans
|
||||
|
||||
FROM alpine:latest AS runtime
|
||||
|
||||
RUN apk add --no-cache bind bind-tools
|
||||
|
||||
COPY --from=build /tmp/nyans /usr/bin/nyans
|
||||
|
||||
EXPOSE 53/tcp
|
||||
EXPOSE 53/udp
|
||||
EXPOSE 2137/tcp
|
||||
|
||||
ENV ROCKET_ADDRESS=0.0.0.0
|
||||
ENV ROCKET_PORT=2137
|
||||
|
||||
|
||||
ENTRYPOINT [ "/usr/bin/nyans" ]
|
40
build.sh
Executable file
40
build.sh
Executable file
|
@ -0,0 +1,40 @@
|
|||
#!/usr/bin/bash
|
||||
|
||||
NAME="nyans"
|
||||
TRIPLE="x86_64-unknown-linux-musl"
|
||||
|
||||
if [ -z "$DEBUG" ]; then
|
||||
_RELEASE=" --release"
|
||||
MODE="/release"
|
||||
else
|
||||
MODE="/debug"
|
||||
fi
|
||||
|
||||
if [ ! -z $TRIPLE ]; then
|
||||
_TARGET=" --target $TRIPLE"
|
||||
fi
|
||||
|
||||
#cargo build$_RELEASE$_TARGET
|
||||
|
||||
cargo test
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Tests failed..."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
[ ! -d out ] && mkdir out
|
||||
|
||||
cp target$TRIPLE$MODE/$NAME out/$NAME
|
||||
chmod +x out/$NAME
|
||||
|
||||
[ -z "$DEBUG" ] && strip out/$NAME
|
||||
|
||||
docker build -t nyanet/nyans .
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Docker build failed..."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Build done..."
|
30
src/main.rs
Normal file
30
src/main.rs
Normal file
|
@ -0,0 +1,30 @@
|
|||
mod rndc;
|
||||
|
||||
use rocket::{catch, catchers, get, launch, post, routes, serde::json::Json};
|
||||
|
||||
#[get("/all")]
|
||||
fn get_all_zones() -> Json<Vec<rndc::Zone>> {
|
||||
Json(rndc::zone_list(None))
|
||||
}
|
||||
|
||||
#[get("/get/<name>")]
|
||||
fn get_zone(name: String) -> Json<rndc::Zone> {
|
||||
Json(rndc::zone_get(name))
|
||||
}
|
||||
|
||||
#[post("/add")]
|
||||
fn add_zone() -> &'static str {
|
||||
todo!()
|
||||
}
|
||||
|
||||
#[catch(404)]
|
||||
fn not_found() -> &'static str {
|
||||
"nop"
|
||||
}
|
||||
|
||||
#[launch]
|
||||
fn rocket() -> _ {
|
||||
rocket::build()
|
||||
.register("/", catchers![not_found])
|
||||
.mount("/zone", routes![get_all_zones, add_zone, get_zone])
|
||||
}
|
21
src/rndc.rs
Normal file
21
src/rndc.rs
Normal file
|
@ -0,0 +1,21 @@
|
|||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct Zone {
|
||||
class: String,
|
||||
r#type: String,
|
||||
}
|
||||
|
||||
pub fn zone_add() {
|
||||
todo!()
|
||||
}
|
||||
|
||||
pub fn zone_get(name: String) -> Zone {
|
||||
todo!()
|
||||
}
|
||||
|
||||
pub fn zone_list(filter: Option<String>) -> Vec<Zone> {
|
||||
let zones: Vec<Zone> = Vec::new();
|
||||
todo!()
|
||||
}
|
Loading…
Reference in a new issue