Skip to content
This repository has been archived by the owner on Nov 29, 2023. It is now read-only.

Commit

Permalink
chore: ursa gateway fly terraform (#305)
Browse files Browse the repository at this point in the history
* ursa gateway fly terraform

* upgarde terrform provider

* use docker image
  • Loading branch information
b0xtch authored Feb 13, 2023
1 parent 5b02e51 commit 1f9ffbb
Show file tree
Hide file tree
Showing 10 changed files with 158 additions and 22 deletions.
40 changes: 22 additions & 18 deletions Dockerfile-gateway
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,33 @@ WORKDIR /ursa
RUN apt-get update && apt-get install -y \
clang \
cmake \
libclang-dev

RUN --mount=type=cache,target=/usr/local/cargo/registry \
cargo install cargo-strip

libclang-dev \
protobuf-compiler

COPY . .
ENV RUST_BACKTRACE=1

RUN --mount=type=cache,target=/usr/local/cargo/registry \
--mount=type=cache,target=/ursa/target \
cargo build --profile $PROFILE --bin ursa-gateway \
&& cargo strip \
&& mv /ursa/target/release/ursa-gateway /ursa/
RUN --mount=type=cache,target=/ursa/target \
--mount=type=cache,target=/usr/local/cargo/registry \
--mount=type=cache,target=/usr/local/cargo/git \
--mount=type=cache,target=/usr/local/rustup \
set -eux; \
rustup install stable; \
cargo build --profile $PROFILE --bin ursa-gateway; \
objcopy --compress-debug-sections target/release/ursa-gateway ./ursa-gateway

FROM debian:bullseye-slim

RUN apt-get update && apt-get install -y \
libcurl4-openssl-dev \
&& apt-get clean \
&& apt-get purge -y \
&& rm -rf /var/lib/apt/lists*
RUN set -eux; \
export DEBIAN_FRONTEND=noninteractive; \
apt-get update; \
apt-get install --yes --no-install-recommends libcurl4-openssl-dev curl ca-certificates htop; \
apt-get clean autoclean; \
apt-get autoremove --yes; \
rm -rf /var/lib/{apt,dpkg,cache,log}/

# Get compiled binaries from builder's cargo install directory
COPY --from=builder /ursa/ursa-gateway /usr/local/bin
WORKDIR ursa

ENTRYPOINT ["ursa-gateway"]
# Get compiled binaries from builder's cargo install directory
COPY --from=builder /ursa/ursa-gateway ./
CMD ["./ursa-gateway", "daemon"]
4 changes: 2 additions & 2 deletions crates/ursa-gateway/example/local.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
log_level = "DEBUG"

[server]
port = 443
port = 80
addr = "0.0.0.0"
request_timeout = 5000 # 5s
concurrency_limit = 100000
Expand All @@ -10,4 +10,4 @@ key_path = ".ursa/gateway/key.pem"
stream_buf = 2000000 # 2mb

[indexer]
cid_url = "http://0.0.0.0:3000/cid"
cid_url = "https://dev.cid.contact/cid"
1 change: 0 additions & 1 deletion crates/ursa-gateway/example/node.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,3 @@ stream_buf = 2000000 # 2mb

[indexer]
cid_url = "https://cid.contact/cid"

2 changes: 1 addition & 1 deletion crates/ursa-gateway/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ impl Default for GatewayConfig {
stream_buf: 2_000_000, // 2MB
},
indexer: IndexerConfig {
cid_url: "https://dev.cid.contact/cid".into(),
cid_url: "https://cid.contact/cid".into(),
},
}
}
Expand Down
12 changes: 12 additions & 0 deletions docker/cache-node/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh
set -e

echo
echo "Building ursa-gateway node"
echo

docker buildx build \
--push \
--platform linux/amd64 \
--tag fleeknetwork/ursa-gateway:latest \
-f ./Dockerfile-gateway .
36 changes: 36 additions & 0 deletions fly.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# fly.toml file generated for floral-shape-3955 on 2023-02-10T17:33:22-05:00

app = "floral-shape-3955"
kill_signal = "SIGINT"
kill_timeout = 5
processes = []

[env]

[experimental]
auto_rollback = true

[[services]]
http_checks = []
internal_port = 8080
processes = ["app"]
protocol = "tcp"
script_checks = []
[services.concurrency]
hard_limit = 25
soft_limit = 20
type = "connections"

[[services.ports]]
handlers = ["http"]
port = 80

[[services.ports]]
handlers = ["tls", "http"]
port = 443

[[services.tcp_checks]]
grace_period = "1s"
interval = "15s"
restart_limit = 0
timeout = "2s"
6 changes: 6 additions & 0 deletions infra/tf-next/fly.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# regional k8s modules
module "fly_ursa_gateway" {
source = "./fly"
regions = ["yyz", "yul", "ewr", "lax", "ewr", "lhr", "ams"]
fly_domains = ["gateway.ursa.earth"]
}
38 changes: 38 additions & 0 deletions infra/tf-next/fly/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
terraform {
required_providers {
fly = {
source = "fly-apps/fly"
version = "0.0.20"
}
}
}

provider "fly" {
fly_http_endpoint = "api.machines.dev"
}

resource "fly_app" "ursa_gateway" {
name = "ursa-gateway"
org = "fleek-network"
}

resource "fly_volume" "ursa_gateway_volume" {
for_each = toset(var.regions)
app = fly_app.ursa_gateway.name
region = each.key
name = "ursa_data_${each.key}"
size = 15
depends_on = [fly_app.ursa_gateway]
}

resource "fly_ip" "ursa_gateway_ip" {
app = fly_app.ursa_gateway.name
type = "v4"
depends_on = [fly_app.ursa_gateway]
}

resource "fly_ip" "ursa_gateway_ipv6" {
app = fly_app.ursa_gateway.name
type = "v6"
depends_on = [fly_app.ursa_gateway]
}
26 changes: 26 additions & 0 deletions infra/tf-next/fly/ursa-gateway.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
resource "fly_machine" "ursa_gateway_machine" {
for_each = toset(var.regions)
app = fly_app.ursa_gateway.name
region = each.key
name = "ursa-gateway-${each.key}"
image = "fleeknetwork/ursa-gateway:latest"
services = [
{
ports = [
{
port = 443
handlers = ["tls", "http"]
},
{
port = 80
handlers = ["http"]
}
]
"protocol" : "tcp",
"internal_port" : 80
},
]
cpus = 4
memorymb = 8192
depends_on = [fly_app.ursa_gateway]
}
15 changes: 15 additions & 0 deletions infra/tf-next/fly/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
################
# Project #
################

variable "regions" {
type = list(string)
default = ["yyz", "yul", "ewr", "lax", "ewr", "lhr", "ams"]
description = "Default regions for the cluster of gateway nodes"
}

variable "fly_domains" {
type = list(string)
default = ["gateway.ursa.earth"]
description = "Top level domains for the cluster of gateway nodes"
}

0 comments on commit 1f9ffbb

Please sign in to comment.