Skip to content

Commit

Permalink
feat: dynamic server nomad calls
Browse files Browse the repository at this point in the history
  • Loading branch information
AngelOnFira authored and NathanFlurry committed Jul 8, 2024
1 parent 8760618 commit 3ea53b6
Show file tree
Hide file tree
Showing 146 changed files with 19,015 additions and 1,276 deletions.
3 changes: 3 additions & 0 deletions .vscode/rivet.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,8 @@
{
"path": "../lib/bolt",
},
{
"path": "../svc",
}
],
}
File renamed without changes.
10 changes: 10 additions & 0 deletions errors/servers/servers_must_specify_routing_type.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
name = "SERVERS_MUST_SPECIFY_ROUTING_TYPE"
description = "Must specify routing type."
http_status = 400
---

# Must Specify Routing Type

Must specify either `game_guard` or `host` routing type.

File renamed without changes.
File renamed without changes.
10 changes: 10 additions & 0 deletions errors/servers/servers_unsupported_host_protocol.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
name = "SERVERS_UNSUPPORTED_HOST_PROTOCOL"
description = "Unsupported host protocol."
http_status = 400
---

# Unsupported Host Protocol

Host protocol must use the TCP or UDP protocol.

57 changes: 26 additions & 31 deletions fern/definition/servers/common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@ types:
datacenter_id: uuid
cluster_id: uuid
metadata: unknown
image_id: uuid
arguments: optional<list<string>>
environment: optional<map<string, string>>
network: Network
resources: Resources
kill_timeout:
docs: >-
The duration to wait for in milliseconds before killing the server.
This should be set to a safe default, and can be overridden during a
DELETE request if needed.
type: optional<long>
runtime: Runtime
create_ts: long
destroy_ts: optional<long>

Expand All @@ -31,48 +34,40 @@ types:
docs: The amount of memory in megabytes
type: integer

Runtime:
properties:
docker: optional<DockerRuntime>

DockerRuntime:
properties:
image_id: uuid
args: optional<list<string>>
environment: optional<map<string, string>>
network: DockerNetwork

DockerNetwork:
Network:
properties:
mode: optional<DockerNetworkMode>
ports: map<string, DockerPort>
mode: optional<NetworkMode>
ports: map<string, Port>

DockerNetworkMode:
NetworkMode:
enum:
- bridge
- host

DockerPort:
Port:
properties:
port: optional<integer>
routing: DockerPortRouting
protocol: PortProtocol
server_port: optional<integer>
public_hostname: optional<string>
public_port: optional<integer>
routing: PortRouting

DockerPortRouting:
properties:
game_guard: optional<DockerGameGuardRouting>
host: optional<DockerHostRouting>

DockerGameGuardRouting:
properties:
protocol: optional<GameGuardProtocol>

GameGuardProtocol:
PortProtocol:
enum:
- http
- https
- tcp
- tcp_tls
- udp

DockerHostRouting:
properties: {}
PortRouting:
properties:
game_guard: optional<GameGuardRouting>
host: optional<HostRouting>

GameGuardRouting:
properties: {}

HostRouting:
properties: {}

29 changes: 28 additions & 1 deletion fern/definition/servers/servers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ service:
auth: true
base-path: /servers/servers
endpoints:
get:
path: "/{server_id}"
method: GET
docs: Gets a dynamic server.
path-parameters:
server_id:
docs: The id of the server to destroy
type: uuid
response: GetServerResponse
create:
path: ""
method: POST
Expand Down Expand Up @@ -34,20 +43,38 @@ service:
response: DestroyServerResponse

types:
GetServerResponse:
properties:
servers: list<commons.Server>
CreateServerRequest:
properties:
datacenter:
docs: The name ID of the datacenter
type: string
metadata: unknown
image_id: uuid
arguments: optional<list<string>>
environment: optional<map<string, string>>
network: CreateServerNetworkRequest
resources: commons.Resources
kill_timeout:
docs: >-
The duration to wait for in milliseconds before killing the server.
This should be set to a safe default, and can be overridden during a
DELETE request if needed.
type: optional<long>
runtime: commons.Runtime

CreateServerNetworkRequest:
properties:
mode: optional<commons.NetworkMode>
ports: map<string, CreateServerPortRequest>

CreateServerPortRequest:
properties:
protocol: commons.PortProtocol
server_port: optional<integer>
routing: optional<commons.PortRouting>

CreateServerResponse:
properties:
server:
Expand Down
25 changes: 25 additions & 0 deletions infra/default-builds/dockerfiles/test-ds-echo/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Created by https://www.toptal.com/developers/gitignore/api/rust
# Edit at https://www.toptal.com/developers/gitignore?templates=rust

### Rust ###
# Generated by Cargo
# will have compiled files and executables
debug/
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

# End of https://www.toptal.com/developers/gitignore/api/rust

.dockerignore
.gitignore
Dockerfile

21 changes: 21 additions & 0 deletions infra/default-builds/dockerfiles/test-ds-echo/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Created by https://www.toptal.com/developers/gitignore/api/rust
# Edit at https://www.toptal.com/developers/gitignore?templates=rust

### Rust ###
# Generated by Cargo
# will have compiled files and executables
debug/
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

# End of https://www.toptal.com/developers/gitignore/api/rust

16 changes: 16 additions & 0 deletions infra/default-builds/dockerfiles/test-ds-echo/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "test-ds-echo"
version = "0.1.0"
edition = "2021"

[dependencies]
tokio = { version = "1.29", features = ["full"] }
reqwest = "0.11"
anyhow = "1.0"
hyper = { version = "0.14", features = ["server"] }

[profile.release]
opt-level = 'z'
lto = true
codegen-units = 1

18 changes: 18 additions & 0 deletions infra/default-builds/dockerfiles/test-ds-echo/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM clux/muslrust:1.77.2-stable AS build
RUN cargo new --bin /app
WORKDIR /app
COPY Cargo.toml ./
RUN cargo build --release
RUN rm -r src
COPY ./src ./src
RUN touch src/main.rs && \
cargo build --release && \
strip target/x86_64-unknown-linux-musl/release/test-ds-echo

FROM alpine:latest
COPY --from=build /app/target/x86_64-unknown-linux-musl/release/test-ds-echo /usr/local/bin/app
RUN chmod +x /usr/local/bin/app
RUN adduser -D app
USER app
CMD ["/usr/local/bin/app"]

Loading

0 comments on commit 3ea53b6

Please sign in to comment.