chore: update caddy configuration

This commit is contained in:
Prad Nukala 2024-09-26 15:58:49 -04:00
parent 6df798f458
commit 08035b6f85
15 changed files with 351 additions and 65 deletions

7
.envrc
View File

@ -1,7 +0,0 @@
# Automatically sets up your devbox environment whenever you cd into this
# directory via our direnv integration:
eval "$(devbox generate direnv --print-envrc)"
# check out https://www.jetpack.io/devbox/docs/ide_configuration/direnv/
# for more details

View File

@ -299,6 +299,10 @@ sh-testnet: mod-tidy
.PHONY: dwn motr templ .PHONY: dwn motr templ
motr:
@echo "(motr) Building motr gateway"
go build -o ./build/motr ./cmd/motr
dwn: dwn:
@echo "(dwn) Building dwn.wasm -> IPFS Vault" @echo "(dwn) Building dwn.wasm -> IPFS Vault"
GOOS=js GOARCH=wasm go build -o ./x/vault/types/internal/app.wasm ./x/vault/client/dwn/dwn.go GOOS=js GOARCH=wasm go build -o ./x/vault/types/internal/app.wasm ./x/vault/client/dwn/dwn.go
@ -313,6 +317,14 @@ pkl:
go run github.com/apple/pkl-go/cmd/pkl-gen-go ./config/pkl/dwn.pkl go run github.com/apple/pkl-go/cmd/pkl-gen-go ./config/pkl/dwn.pkl
go run github.com/apple/pkl-go/cmd/pkl-gen-go ./config/pkl/orm.pkl go run github.com/apple/pkl-go/cmd/pkl-gen-go ./config/pkl/orm.pkl
start-caddy:
@echo "(start-caddy) Starting caddy"
./build/caddy run --config ./config/caddy/Caddyfile
start-proxy:
@echo "(start-proxy) Starting proxy server"
./build/motr proxy
############################################################################### ###############################################################################
### help ### ### help ###
############################################################################### ###############################################################################

14
cmd/motr/main.go Normal file
View File

@ -0,0 +1,14 @@
package main
import "github.com/spf13/cobra"
func main() {
rootCmd := &cobra.Command{
Use: "motr",
Short: "Manage a local DWN instance for the Sonr blockchain",
}
rootCmd.AddCommand(NewProxyCmd())
if err := rootCmd.Execute(); err != nil {
panic(err)
}
}

55
cmd/motr/proxy.go Normal file
View File

@ -0,0 +1,55 @@
package main
import (
"context"
"net/http"
"os"
"os/signal"
"time"
"github.com/labstack/echo/v4"
"github.com/labstack/gommon/log"
"github.com/onsonr/sonr/nebula"
"github.com/onsonr/sonr/nebula/pages"
"github.com/spf13/cobra"
)
func NewProxyCmd() *cobra.Command {
return &cobra.Command{
Use: "proxy",
Short: "Starts the DWN proxy server for the local IPFS node",
Run: func(cmd *cobra.Command, args []string) {
// Echo instance
e := echo.New()
e.Logger.SetLevel(log.INFO)
// Configure the server
if err := nebula.UseAssets(e); err != nil {
e.Logger.Fatal(err)
}
e.GET("/", pages.Home)
e.GET("/allocate", pages.Profile)
// Start server
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt)
defer stop()
// Start server
go func() {
if err := e.Start(":1323"); err != nil && err != http.ErrServerClosed {
e.Logger.Fatal("shutting down the server")
}
}()
// Wait for interrupt signal to gracefully shutdown the server with a timeout of 10 seconds.
<-ctx.Done()
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
// Shutdown the server with 10 seconds timeout.
if err := e.Shutdown(ctx); err != nil {
e.Logger.Fatal(err)
}
},
}
}

View File

@ -1,23 +1,35 @@
{ {
# Global options
email team@sonr.id email team@sonr.id
} }
# Vaults at vault.sonr.id # Services exposed via Cloudflare Tunnel
vault.sonr.id { :1323 {
tls { reverse_proxy localhost:1323
dns cloudflare {env.CLOUDFLARE_API_TOKEN}
resolvers 1.1.1.1
} }
# Match paths that are bech32 addresses :1317 {
reverse_proxy localhost:1317
}
:9090 {
reverse_proxy localhost:9091
}
:26657 {
reverse_proxy localhost:26657
}
vault.sonr.id {
# Since vault.sonr.id has specific configurations, we can specify the hostname
reverse_proxy localhost:8080
@vault path_regexp vaultPath ^/([a-z0-9]{42})(/.*|)$ @vault path_regexp vaultPath ^/([a-z0-9]{42})(/.*|)$
handle @vault { handle @vault {
# Rewrite to IPFS gateway format
uri replace /{re.vaultPath.0} /ipns/{re.vaultPath.1}{re.vaultPath.2} uri replace /{re.vaultPath.0} /ipns/{re.vaultPath.1}{re.vaultPath.2}
reverse_proxy localhost:8080
# Proxy to IPFS gateway
reverse_proxy http://localhost:8080
} }
file_server file_server
@ -25,9 +37,7 @@ vault.sonr.id {
header { header {
Content-Type .wasm application/wasm Content-Type .wasm application/wasm
Service-Worker-Allowed "/" Service-Worker-Allowed "/"
# Add any other necessary headers
} }
# Optional: Enable compression
encode zstd gzip encode zstd gzip
} }

View File

@ -9,4 +9,6 @@ type Config struct {
Motr *Motr `pkl:"motr" json:"motr,omitempty"` Motr *Motr `pkl:"motr" json:"motr,omitempty"`
Schema *Schema `pkl:"schema" json:"schema,omitempty"` Schema *Schema `pkl:"schema" json:"schema,omitempty"`
ProxyUrl string `pkl:"proxyUrl" json:"proxyUrl,omitempty"`
} }

View File

@ -24,6 +24,9 @@ class Config {
@JsonField @JsonField
schema: Schema schema: Schema
@JsonField
proxyUrl: String
} }
class IPFS { class IPFS {

View File

@ -1,27 +1,61 @@
{ {
"$schema": "https://raw.githubusercontent.com/jetify-com/devbox/0.12.0/.schema/devbox.schema.json", "$schema": "https://raw.githubusercontent.com/jetify-com/devbox/0.12.0/.schema/devbox.schema.json",
"packages": ["go@1.22", "bun@latest"], "packages": [
"go@1.22",
"bun@latest",
"ipfs@latest",
"skate@latest",
"cloudflared@latest"
],
"env": { "env": {
"CLOUDFLARE_API_TOKEN": "$CLOUDFLARE_API_TOKEN", "CLOUDFLARE_TUNNEL_TOKEN": "$(skate get CLOUDFLARE_TUNNEL_TOKEN)",
"GOPATH": "$HOME/go", "GOPATH": "$HOME/go",
"PATH": "$HOME/go/bin:$PATH", "PATH": "$HOME/go/bin:$PATH",
"TEMPL_EXPERIMENT": "rawgo", "TEMPL_EXPERIMENT": "rawgo",
"CHAIN_ID": "sonr-testnet-1", "CHAIN_ID": "sonr-testnet-1",
"DENOM": "usnr", "DENOM": "usnr",
"KEYRING": "test", "KEYRING": "test",
"MONIKER": "florence", "MONIKER": "florence"
"ENV": "$ENVIRONMENT"
}, },
"shell": { "shell": {
"scripts": { "scripts": {
"install": ["make install"], "install": [
"build": ["bun --cwd nebula run build", "make dwn", "make build"], "make install",
"docker": ["make local-image"], "bun --cwd nebula run fetch:deps"
"proto": ["make proto-gen"], ],
"pkl": ["make pkl"], "build:docker": [
"templ": ["make templ"], "make local-image"
"proxy": ["./build/sonrd dwn-proxy"], ],
"watch:nebula": ["bun --cwd nebula run watch"] "build:dwn": [
"make dwn"
],
"build:motr": [
"make motr"
],
"build:nebula": [
"bun --cwd nebula run build"
],
"build:sonrd": [
"make build"
],
"build:xcaddy": [
"sh scripts/build_xcaddy.sh"
],
"gen:proto": [
"make proto-gen"
],
"gen:pkl": [
"make pkl"
],
"gen:templ": [
"make templ"
],
"start:tunnel": [
"cloudflared tunnel run --token $(skate get CLOUDFLARE_TUNNEL_TOKEN)"
],
"watch:nebula": [
"bun --cwd nebula run watch"
]
} }
} }
} }

View File

@ -49,6 +49,54 @@
} }
} }
}, },
"cloudflared@latest": {
"last_modified": "2024-09-10T15:01:03Z",
"resolved": "github:NixOS/nixpkgs/5ed627539ac84809c78b2dd6d26a5cebeb5ae269#cloudflared",
"source": "devbox-search",
"version": "2024.8.3",
"systems": {
"aarch64-darwin": {
"outputs": [
{
"name": "out",
"path": "/nix/store/nmmh1dx4rvqayxq31c99gxpbwvcchx9w-cloudflared-2024.8.3",
"default": true
}
],
"store_path": "/nix/store/nmmh1dx4rvqayxq31c99gxpbwvcchx9w-cloudflared-2024.8.3"
},
"aarch64-linux": {
"outputs": [
{
"name": "out",
"path": "/nix/store/kwikn13v0rddmr8kjhnj67li8aq8qwa6-cloudflared-2024.8.3",
"default": true
}
],
"store_path": "/nix/store/kwikn13v0rddmr8kjhnj67li8aq8qwa6-cloudflared-2024.8.3"
},
"x86_64-darwin": {
"outputs": [
{
"name": "out",
"path": "/nix/store/9630bavr6jb44g0pcwwqn0zpgin39dc7-cloudflared-2024.8.3",
"default": true
}
],
"store_path": "/nix/store/9630bavr6jb44g0pcwwqn0zpgin39dc7-cloudflared-2024.8.3"
},
"x86_64-linux": {
"outputs": [
{
"name": "out",
"path": "/nix/store/hybva7brncispiqm6f0qrpn897r3y3ja-cloudflared-2024.8.3",
"default": true
}
],
"store_path": "/nix/store/hybva7brncispiqm6f0qrpn897r3y3ja-cloudflared-2024.8.3"
}
}
},
"go@1.22": { "go@1.22": {
"last_modified": "2024-09-12T11:58:09Z", "last_modified": "2024-09-12T11:58:09Z",
"resolved": "github:NixOS/nixpkgs/280db3decab4cbeb22a4599bd472229ab74d25e1#go", "resolved": "github:NixOS/nixpkgs/280db3decab4cbeb22a4599bd472229ab74d25e1#go",
@ -96,6 +144,60 @@
"store_path": "/nix/store/chzgk756zb2cqlzbjr86m0lfxi63cdfy-go-1.22.7" "store_path": "/nix/store/chzgk756zb2cqlzbjr86m0lfxi63cdfy-go-1.22.7"
} }
} }
},
"ipfs@latest": {
"last_modified": "2023-02-24T09:01:09Z",
"resolved": "github:NixOS/nixpkgs/7d0ed7f2e5aea07ab22ccb338d27fbe347ed2f11#ipfs",
"source": "devbox-search",
"version": "0.17.0"
},
"skate@latest": {
"last_modified": "2024-09-10T15:01:03Z",
"resolved": "github:NixOS/nixpkgs/5ed627539ac84809c78b2dd6d26a5cebeb5ae269#skate",
"source": "devbox-search",
"version": "1.0.0",
"systems": {
"aarch64-darwin": {
"outputs": [
{
"name": "out",
"path": "/nix/store/5hn4s18zy08inhimckf3794zszxjn077-skate-1.0.0",
"default": true
}
],
"store_path": "/nix/store/5hn4s18zy08inhimckf3794zszxjn077-skate-1.0.0"
},
"aarch64-linux": {
"outputs": [
{
"name": "out",
"path": "/nix/store/jxwx4fn5qbaz2nan3gmpydqx6vv8ldp1-skate-1.0.0",
"default": true
}
],
"store_path": "/nix/store/jxwx4fn5qbaz2nan3gmpydqx6vv8ldp1-skate-1.0.0"
},
"x86_64-darwin": {
"outputs": [
{
"name": "out",
"path": "/nix/store/zs6ik66kpz9q8mdmzxqmgjv51y39r76h-skate-1.0.0",
"default": true
}
],
"store_path": "/nix/store/zs6ik66kpz9q8mdmzxqmgjv51y39r76h-skate-1.0.0"
},
"x86_64-linux": {
"outputs": [
{
"name": "out",
"path": "/nix/store/6zbyhj72wh0645lj6b9c392aqqg11a84-skate-1.0.0",
"default": true
}
],
"store_path": "/nix/store/6zbyhj72wh0645lj6b9c392aqqg11a84-skate-1.0.0"
}
}
} }
} }
} }

View File

@ -50,14 +50,6 @@ func loginView(c echo.Context) templ.Component {
}() }()
} }
ctx = templ.InitializeContext(ctx) ctx = templ.InitializeContext(ctx)
templ_7745c5c3_Err = blocks.Head("Sonr.ID", true).Render(ctx, templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" ")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Var3 := templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { templ_7745c5c3_Var3 := templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W) templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)

View File

@ -13,14 +13,23 @@ processes:
namespace: testnet namespace: testnet
command: "make sh-testnet" command: "make sh-testnet"
restart: on_failure restart: on_failure
max_restarts: 3 max_restarts: 1
depends: depends:
- ipfs - ipfs
proxy: motr:
namespace: testnet namespace: testnet
command: "devbox run proxy" command: "make start-proxy"
restart: on_failure restart: on_failure
max_restarts: 3 max_restarts: 1
depends: depends:
- sonr - sonr
- ipfs
tunnel:
namespace: public
command: "devbox run start:tunnel"
restart: on_failure
max_restarts: 1
depends:
- caddy

View File

@ -1,8 +1,17 @@
#!/bin/bash #!/bin/bash
# Exit immediately if a command exits with a non-zero status.
set -e
# Initialize IPFS # Initialize IPFS
ipfs init ipfs init
# Optimize local discovery and connectivity
ipfs config --json Discovery.MDNS.Enabled true
ipfs config --json Routing.Type "dhtclient"
ipfs config --json Swarm.ConnMgr.LowWater 200
ipfs config --json Swarm.ConnMgr.HighWater 500
# Set up the Cloudflare IPFS gateway peers # Set up the Cloudflare IPFS gateway peers
ipfs config --json Peering.Peers '[ ipfs config --json Peering.Peers '[
{"ID": "QmcFf2FH3CEgTNHeMRGhN7HNHU1EXAxoEk6EFuSyXCsvRE", "Addrs": ["/dnsaddr/node-1.ingress.cloudflare-ipfs.com"]}, {"ID": "QmcFf2FH3CEgTNHeMRGhN7HNHU1EXAxoEk6EFuSyXCsvRE", "Addrs": ["/dnsaddr/node-1.ingress.cloudflare-ipfs.com"]},
@ -18,3 +27,14 @@ ipfs config --json Peering.Peers '[
{"ID": "Qmcfuo1TM9uUiJp6dTbm915Rf1aTqm3a3dnmCdDQLHgvL5", "Addrs": ["/dnsaddr/node-11.ingress.cloudflare-ipfs.com"]}, {"ID": "Qmcfuo1TM9uUiJp6dTbm915Rf1aTqm3a3dnmCdDQLHgvL5", "Addrs": ["/dnsaddr/node-11.ingress.cloudflare-ipfs.com"]},
{"ID": "QmcfV2sg9zaq7UUHVCGuSvT2M2rnLBAPsiE79vVyK3Cuev", "Addrs": ["/dnsaddr/node-12.ingress.cloudflare-ipfs.com"]} {"ID": "QmcfV2sg9zaq7UUHVCGuSvT2M2rnLBAPsiE79vVyK3Cuev", "Addrs": ["/dnsaddr/node-12.ingress.cloudflare-ipfs.com"]}
]' ]'
# Configure API and Gateway addresses to listen on localhost only
ipfs config Addresses.API /ip4/127.0.0.1/tcp/5001
ipfs config Addresses.Gateway /ip4/127.0.0.1/tcp/8080
# Enable experimental features
ipfs config --json Experimental.FilestoreEnabled true
ipfs config --json Experimental.UrlstoreEnabled true
# Start the IPFS daemon with additional options for better performance and compatibility
ipfs daemon --enable-gc --migrate --enable-pubsub-experiment --enable-namesys-pubsub

40
scripts/build_xcaddy.sh Executable file
View File

@ -0,0 +1,40 @@
#!/bin/bash
# Exit immediately if a command exits with a non-zero status.
set -e
# Function to check if a command exists.
command_exists() {
command -v "$1" >/dev/null 2>&1
}
echo "Starting the build process for Caddy with Cloudflare DNS module..."
# Check if Go is installed
if ! command_exists go; then
echo "Go is not installed. Please install Go before running this script."
exit 1
fi
# Set Go environment variables
export GOPATH=$(go env GOPATH)
export GOBIN=$GOPATH/bin
export PATH=$PATH:$GOBIN
# Install xcaddy if not present
if ! command_exists xcaddy; then
echo "xcaddy not found. Installing xcaddy..."
curl -sSfL https://raw.githubusercontent.com/caddyserver/xcaddy/master/install.sh | bash -s -- -b $GOBIN
fi
# Build Caddy with the Cloudflare DNS module
echo "Building Caddy with the Cloudflare DNS module..."
xcaddy build --with github.com/caddy-dns/cloudflare
mv caddy ../build/caddy
echo "Caddy has been built successfully with the Cloudflare DNS module."
# Optional: Move the caddy binary to /usr/local/bin (requires sudo)
# echo "Moving caddy to /usr/local/bin (requires sudo)..."
# sudo mv caddy /usr/local/bin/
# echo "Caddy has been installed to /usr/local/bin."

Binary file not shown.