-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
30 changed files
with
2,396 additions
and
187 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
name: Deploy prod images to GHCR | ||
|
||
on: | ||
push: | ||
tags: | ||
- 'v[0-9]+.[0-9]+.[0-9]+' | ||
|
||
jobs: | ||
push-store-image: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: 'Checkout GitHub Action' | ||
uses: actions/checkout@main | ||
|
||
- name: 'Login to GitHub Container Registry' | ||
uses: docker/login-action@v1 | ||
with: | ||
registry: ghcr.io | ||
username: ${{github.actor}} | ||
password: ${{secrets.GITHUB_TOKEN}} | ||
|
||
- name: 'Build Inventory Image' | ||
run: | | ||
docker build . --tag ghcr.io/qubic/go-qubic:${{github.ref_name}} | ||
docker push ghcr.io/qubic/go-qubic:${{github.ref_name}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
FROM golang:1.22 AS builder | ||
ENV CGO_ENABLED=0 | ||
|
||
WORKDIR /src | ||
COPY . /src | ||
|
||
RUN go mod tidy | ||
RUN go build -o "/src/bin/go-node-proxy" | ||
|
||
# We don't need golang to run binaries, just use alpine. | ||
FROM ubuntu:22.04 | ||
RUN apt-get update && apt-get install -y ca-certificates | ||
COPY --from=builder /src/bin/go-node-proxy /app/go-node-proxy | ||
RUN chmod +x /app/go-node-proxy | ||
|
||
EXPOSE 8000 | ||
EXPOSE 8001 | ||
|
||
WORKDIR /app | ||
|
||
ENTRYPOINT ["./go-node-proxy"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"github.com/pkg/errors" | ||
"github.com/qubic/go-qubic/internal/connector" | ||
"github.com/qubic/go-qubic/server" | ||
"log" | ||
"os" | ||
"os/signal" | ||
"syscall" | ||
"time" | ||
|
||
"github.com/ardanlabs/conf" | ||
) | ||
|
||
const prefix = "QUBIC_NODE_PROXY" | ||
|
||
func main() { | ||
if err := run(); err != nil { | ||
log.Fatalf("main: exited with error: %s", err.Error()) | ||
} | ||
} | ||
|
||
func run() error { | ||
var cfg struct { | ||
Server struct { | ||
HttpListenAddr string `conf:"default:0.0.0.0:8000"` | ||
GrpcListenAddr string `conf:"default:0.0.0.0:8001"` | ||
ReadTimeout time.Duration `conf:"default:5s"` | ||
WriteTimeout time.Duration `conf:"default:5s"` | ||
ShutdownTimeout time.Duration `conf:"default:5s"` | ||
} | ||
Pool struct { | ||
NodeFetcherUrl string `conf:"default:http://127.0.0.1:8080/status"` | ||
NodeFetcherTimeout time.Duration `conf:"default:5s"` | ||
InitialCap int `conf:"default:5"` | ||
MaxIdle int `conf:"default:6"` | ||
MaxCap int `conf:"default:10"` | ||
IdleTimeout time.Duration `conf:"default:15s"` | ||
} | ||
NodeConnector struct { | ||
ConnectionPort string `conf:"default:21841"` | ||
ConnectionTimeout time.Duration `conf:"default:5s"` | ||
HandlerRequestTimeout time.Duration `conf:"default:5s"` | ||
} | ||
} | ||
|
||
if err := conf.Parse(os.Args[1:], prefix, &cfg); err != nil { | ||
switch { | ||
case errors.Is(err, conf.ErrHelpWanted): | ||
usage, err := conf.Usage(prefix, &cfg) | ||
if err != nil { | ||
return errors.Wrap(err, "generating config usage") | ||
} | ||
fmt.Println(usage) | ||
return nil | ||
case errors.Is(err, conf.ErrVersionWanted): | ||
version, err := conf.VersionString(prefix, &cfg) | ||
if err != nil { | ||
return errors.Wrap(err, "generating config version") | ||
} | ||
fmt.Println(version) | ||
return nil | ||
} | ||
return errors.Wrap(err, "parsing config") | ||
} | ||
|
||
out, err := conf.String(&cfg) | ||
if err != nil { | ||
return errors.Wrap(err, "generating config for output") | ||
} | ||
log.Printf("main: Config :\n%v\n", out) | ||
|
||
pfConfig := connector.PoolFetcherConfig{ | ||
URL: cfg.Pool.NodeFetcherUrl, | ||
RequestTimeout: cfg.Pool.NodeFetcherTimeout, | ||
} | ||
cConfig := connector.Config{ | ||
ConnectionPort: cfg.NodeConnector.ConnectionPort, | ||
ConnectionTimeout: cfg.NodeConnector.ConnectionTimeout, | ||
HandlerRequestTimeout: cfg.NodeConnector.HandlerRequestTimeout, | ||
} | ||
pConfig := connector.PoolConfig{ | ||
InitialCap: cfg.Pool.InitialCap, | ||
MaxCap: cfg.Pool.MaxCap, | ||
MaxIdle: cfg.Pool.MaxIdle, | ||
IdleTimeout: cfg.Pool.IdleTimeout, | ||
} | ||
conn, err := connector.NewPoolConnector(pfConfig, cConfig, pConfig) | ||
if err != nil { | ||
return errors.Wrap(err, "creating pool connector") | ||
} | ||
|
||
srv := server.NewServer(cfg.Server.GrpcListenAddr, cfg.Server.HttpListenAddr, conn) | ||
err = srv.Start() | ||
if err != nil { | ||
return errors.Wrap(err, "starting server") | ||
} | ||
|
||
shutdown := make(chan os.Signal, 1) | ||
signal.Notify(shutdown, os.Interrupt, syscall.SIGTERM) | ||
|
||
for { | ||
select { | ||
case <-shutdown: | ||
return errors.New("shutting down") | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.