Skip to content

Commit

Permalink
upgraded modules (#30)
Browse files Browse the repository at this point in the history
* added a caddy router service

* added a caddy router service

* added a caddy router service

* fixed the router dockerfile

* fixed the router dockerfile

* upgraded various modules
  • Loading branch information
mickume authored Feb 18, 2023
1 parent fe0530c commit 246a984
Show file tree
Hide file tree
Showing 10 changed files with 1,195 additions and 64 deletions.
File renamed without changes.
57 changes: 57 additions & 0 deletions .github/workflows/build_router.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: build_router

on:
push:
branches: [develop]

env:
CONTEXT_DIR: cmd/router
CONTAINER_IMAGE: router
CONTAINER_VERSION: 0.1.0
REPOSITORY: ${{ secrets.REPOSITORY }}
REPOSITORY_HOST: ${{ secrets.REPOSITORY_HOST }}
GITHUB_SHA: ${{ github.sha }}

jobs:
build_router:
runs-on: ubuntu-latest

steps:
- name: setup go
uses: actions/setup-go@v2
with:
go-version: ^1.19
id: go

- name: checkout code
uses: actions/checkout@v3

- name: authenticate gcloud SDK
uses: google-github-actions/auth@v1
with:
credentials_json: "${{ secrets.GCP_SA_KEY }}"
id: auth

- name: setup gcloud SDK
uses: google-github-actions/setup-gcloud@v1

- run: gcloud auth configure-docker $REPOSITORY_HOST

- name: build the service
run: |
cd $CONTEXT_DIR
go get -v -t -d ./...
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o svc main.go
- name: build the container
run: |
cd $CONTEXT_DIR
docker build --rm=true -t "$REPOSITORY_HOST"/"$REPOSITORY"/"$CONTAINER_IMAGE":"$GITHUB_SHA" .
- name: push the container
run: |
docker push $REPOSITORY_HOST/$REPOSITORY/$CONTAINER_IMAGE:$GITHUB_SHA
docker tag $REPOSITORY_HOST/$REPOSITORY/$CONTAINER_IMAGE:$GITHUB_SHA $REPOSITORY_HOST/$REPOSITORY/$CONTAINER_IMAGE:latest
docker tag $REPOSITORY_HOST/$REPOSITORY/$CONTAINER_IMAGE:$GITHUB_SHA $REPOSITORY_HOST/$REPOSITORY/$CONTAINER_IMAGE:$CONTAINER_VERSION
docker push $REPOSITORY_HOST/$REPOSITORY/$CONTAINER_IMAGE:latest
docker push $REPOSITORY_HOST/$REPOSITORY/$CONTAINER_IMAGE:$CONTAINER_VERSION
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ test:
.PHONY: test_build
test_build:
go mod verify && go mod tidy
cd cmd/router && go build main.go && rm main
cd examples/service && go build main.go && rm main
cd examples/cli && go build cli.go && rm cli
cd examples/appengine && go build main.go && rm main
Expand Down
4 changes: 4 additions & 0 deletions cmd/router/Caddyfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{{ inventory_hostname }} {
root * /data/public/default
file_server
}
57 changes: 57 additions & 0 deletions cmd/router/Caddyfile.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{{ inventory_hostname }} {
root * /data/public/default
file_server
}
podops.dev {
encode zstd gzip
root * /data/public/podops.dev

rewrite /s/* s/_id.html
rewrite /e/* e/_id.html
redir /s/*/feed.xml https://cdn.podops.dev{path}

file_server
log {
output file /data/caddy/logs/podops_dev.log
}
}

storage.podops.dev {
encode zstd gzip
root * /data/storage

route {
cdn_storage
file_server
}
log {
output file /data/caddy/logs/cdn.log
}
}

cdn.podops.dev {
reverse_proxy api:8080

log {
output file /data/caddy/logs/api.log
}
}

localhost {
encode zstd gzip
root * ./data/public

rewrite /s/* s/_id.html
rewrite /e/* e/_id.html

reverse_proxy /q/* localhost:8080
reverse_proxy /c/* localhost:8080

route {
file_server
}

log {
output file ./data/logs/cdn.log
}
}
34 changes: 34 additions & 0 deletions cmd/router/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
FROM registry.access.redhat.com/ubi8-minimal

USER root

ENV SVC_NAME svc

ENV CADDYFILE /config/router/Caddyfile

EXPOSE 80 443 2019

# See https://caddyserver.com/docs/conventions#file-locations for details
ENV XDG_CONFIG_HOME=/config
ENV XDG_DATA_HOME=/data

RUN set -eux; \
mkdir -p \
/config/router \
/data/router \
/etc/router

# Copy extra files to the image
COPY ./run /root/usr/bin/

VOLUME /config
VOLUME /data

# copy the binary
COPY $SVC_NAME /usr/bin/svc

# make it executable
RUN chmod +x /usr/bin/svc

# Entrypoint
CMD ["/root/usr/bin/run"]
31 changes: 31 additions & 0 deletions cmd/router/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package main

import (
caddycmd "github.com/caddyserver/caddy/v2/cmd"

// plug in Caddy modules here
_ "github.com/caddyserver/caddy/v2/modules/standard"
//_ "github.com/txsvc/httpservice/internal/cdn/modules"
)

/*
func init() {
// initialize the platform first
if !env.Assert("PROJECT_ID") {
log.Fatal("Missing env variable 'PROJECT_ID'")
}
local.InitLocalProviders()
p := platform.DefaultPlatform()
err := p.RegisterProviders(true, google.GoogleCloudLoggingConfig, google.GoogleCloudMetricsConfig)
if err != nil {
log.Fatal("error initializing the platform services")
}
platform.RegisterPlatform(p) // redundant, but in case we return a copy in the future ...
}
*/

func main() {
caddycmd.Main()
}
3 changes: 3 additions & 0 deletions cmd/router/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

/usr/bin/svc run --config $CADDYFILE --adapter caddyfile
167 changes: 157 additions & 10 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,20 +1,167 @@
module github.com/txsvc/apikit

go 1.16
go 1.19

require (
github.com/Bytom/bytom v1.1.1
github.com/PuerkitoBio/rehttp v1.1.0
github.com/alecthomas/chroma v0.10.0
github.com/bytom/bytom v1.1.1 // indirect
github.com/labstack/echo/v4 v4.8.0
github.com/labstack/gommon v0.3.1
github.com/caddyserver/caddy/v2 v2.6.4
github.com/labstack/echo/v4 v4.10.0
github.com/labstack/gommon v0.4.0
github.com/logrusorgru/aurora v2.0.3+incompatible
github.com/mailgun/mailgun-go/v4 v4.8.1
github.com/mailgun/mailgun-go/v4 v4.8.2
github.com/miguelmota/go-ethereum-hdwallet v0.1.1
github.com/stretchr/testify v1.8.0
github.com/txsvc/stdlib/v2 v2.3.0
github.com/urfave/cli/v2 v2.11.2
github.com/ziflex/lecho/v3 v3.1.0
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5
github.com/stretchr/testify v1.8.1
github.com/txsvc/stdlib/v2 v2.4.0
github.com/urfave/cli/v2 v2.24.4
github.com/ziflex/lecho/v3 v3.5.0
golang.org/x/crypto v0.6.0
)

require (
filippo.io/edwards25519 v1.0.0 // indirect
github.com/AndreasBriese/bbloom v0.0.0-20190825152654-46b345b51c96 // indirect
github.com/BurntSushi/toml v1.2.1 // indirect
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Masterminds/semver/v3 v3.2.0 // indirect
github.com/Masterminds/sprig/v3 v3.2.3 // indirect
github.com/Microsoft/go-winio v0.6.0 // indirect
github.com/alecthomas/chroma/v2 v2.5.0 // indirect
github.com/antlr/antlr4/runtime/Go/antlr v1.4.10 // indirect
github.com/aryann/difflib v0.0.0-20210328193216-ff5ff6dc229b // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/btcsuite/btcd v0.21.0-beta // indirect
github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce // indirect
github.com/bytom/bytom v1.1.1 // indirect
github.com/caddyserver/certmagic v0.17.2 // indirect
github.com/cenkalti/backoff/v4 v4.1.2 // indirect
github.com/cespare/xxhash v1.1.0 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dgraph-io/badger v1.6.2 // indirect
github.com/dgraph-io/badger/v2 v2.2007.4 // indirect
github.com/dgraph-io/ristretto v0.1.0 // indirect
github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13 // indirect
github.com/dlclark/regexp2 v1.7.0 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/ethereum/go-ethereum v1.10.4 // indirect
github.com/felixge/httpsnoop v1.0.3 // indirect
github.com/fxamacker/cbor/v2 v2.4.0 // indirect
github.com/go-chi/chi v4.1.2+incompatible // indirect
github.com/go-kit/kit v0.10.0 // indirect
github.com/go-logfmt/logfmt v0.5.1 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-sql-driver/mysql v1.6.0 // indirect
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 // indirect
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
github.com/golang/glog v1.0.0 // indirect
github.com/golang/mock v1.6.0 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/cel-go v0.13.0 // indirect
github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/gorilla/mux v1.8.0 // indirect
github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect
github.com/huandu/xstrings v1.3.3 // indirect
github.com/imdario/mergo v0.3.12 // indirect
github.com/inconshreveable/mousetrap v1.0.1 // indirect
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
github.com/jackc/pgconn v1.13.0 // indirect
github.com/jackc/pgio v1.0.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgproto3/v2 v2.3.1 // indirect
github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b // indirect
github.com/jackc/pgtype v1.12.0 // indirect
github.com/jackc/pgx/v4 v4.17.2 // indirect
github.com/johngb/langreg v0.0.0-20150123211413-5c6abc6d19d2 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.15.15 // indirect
github.com/klauspost/cpuid/v2 v2.2.3 // indirect
github.com/libdns/libdns v0.2.1 // indirect
github.com/manifoldco/promptui v0.9.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.16 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect
github.com/mholt/acmez v1.1.0 // indirect
github.com/micromdm/scep/v2 v2.1.0 // indirect
github.com/miekg/dns v1.1.50 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/go-ps v1.0.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/onsi/ginkgo/v2 v2.2.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.14.0 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.37.0 // indirect
github.com/prometheus/procfs v0.8.0 // indirect
github.com/quic-go/qpack v0.4.0 // indirect
github.com/quic-go/qtls-go1-18 v0.2.0 // indirect
github.com/quic-go/qtls-go1-19 v0.2.0 // indirect
github.com/quic-go/qtls-go1-20 v0.1.0 // indirect
github.com/quic-go/quic-go v0.32.0 // indirect
github.com/rs/xid v1.4.0 // indirect
github.com/rs/zerolog v1.29.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/shopspring/decimal v1.2.0 // indirect
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
github.com/sirupsen/logrus v1.9.0 // indirect
github.com/slackhq/nebula v1.6.1 // indirect
github.com/smallstep/certificates v0.23.2 // indirect
github.com/smallstep/nosql v0.5.0 // indirect
github.com/smallstep/truststore v0.12.1 // indirect
github.com/spf13/cast v1.4.1 // indirect
github.com/spf13/cobra v1.6.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stoewer/go-strcase v1.2.0 // indirect
github.com/tailscale/tscert v0.0.0-20230124224810-c6dc1f4049b2 // indirect
github.com/tyler-smith/go-bip39 v1.0.1-0.20181017060643-dbb3b84ba2ef // indirect
github.com/urfave/cli v1.22.12 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.2 // indirect
github.com/x448/float16 v0.8.4 // indirect
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
github.com/yuin/goldmark v1.5.4 // indirect
github.com/yuin/goldmark-highlighting/v2 v2.0.0-20220924101305-151362477c87 // indirect
go.etcd.io/bbolt v1.3.6 // indirect
go.mozilla.org/pkcs7 v0.0.0-20210826202110-33d05740a352 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.39.0 // indirect
go.opentelemetry.io/otel v1.13.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.4.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.4.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.4.0 // indirect
go.opentelemetry.io/otel/metric v0.36.0 // indirect
go.opentelemetry.io/otel/sdk v1.13.0 // indirect
go.opentelemetry.io/otel/trace v1.13.0 // indirect
go.opentelemetry.io/proto/otlp v0.12.0 // indirect
go.step.sm/cli-utils v0.7.5 // indirect
go.step.sm/crypto v0.23.2 // indirect
go.step.sm/linkedca v0.19.0 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
go.uber.org/zap v1.24.0 // indirect
golang.org/x/exp v0.0.0-20221205204356-47842c84f3db // indirect
golang.org/x/mod v0.6.0 // indirect
golang.org/x/net v0.7.0 // indirect
golang.org/x/sync v0.1.0 // indirect
golang.org/x/sys v0.5.0 // indirect
golang.org/x/term v0.5.0 // indirect
golang.org/x/text v0.7.0 // indirect
golang.org/x/time v0.2.0 // indirect
golang.org/x/tools v0.2.0 // indirect
google.golang.org/genproto v0.0.0-20230202175211-008b39050e57 // indirect
google.golang.org/grpc v1.52.3 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
gopkg.in/square/go-jose.v2 v2.6.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
howett.net/plist v1.0.0 // indirect
)
Loading

0 comments on commit 246a984

Please sign in to comment.