Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add access main skeleton #5

Merged
merged 3 commits into from
Jul 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Dockerfile.access
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ RUN apk add --update --no-cache \
FROM scratch

COPY --from=certificates /etc/ssl/cert.pem /etc/ssl/cert.pem
COPY --chmod=0755 --chown=root:root dist/archived-access_linux_arm64/archived-access /archived-access
COPY --chmod=0755 --chown=root:root dist/archived-access_linux_amd64_v3/archived-access /archived-access
COPY --chmod=0644 --chown=root:root presenter/access/html/templates /templates

ENV HTML_TEMPLATE_DIR=/templates

ENTRYPOINT [ "/archived-access" ]
80 changes: 79 additions & 1 deletion cmd/access/main.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,88 @@
package main

import (
"context"
"database/sql"
"net/http"

"github.com/kelseyhightower/envconfig"
echo "github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
"github.com/prometheus/client_golang/prometheus/promhttp"
log "github.com/sirupsen/logrus"
"golang.org/x/sync/errgroup"

htmlPresenter "github.com/teran/archived/presenter/access/html"
"github.com/teran/archived/repositories/metadata/postgresql"
"github.com/teran/archived/service"
)

var (
appVersion = "n/a (dev build)"
buildTimestamp = "undefined"
)

type config struct {
Addr string `envconfig:"ADDR" default:":8080"`
MetricsAddr string `envconfig:"METRICS_ADDR" default:":8081"`

LogLevel log.Level `envconfig:"LOG_LEVEL" default:"info"`

MetadataDSN string `envconfig:"METADATA_DSN" required:"true"`

HTMLTemplateDir string `envconfig:"HTML_TEMPLATE_DIR" required:"true"`
}

func main() {
panic("not implemented")
var cfg config
envconfig.MustProcess("", &cfg)

log.SetLevel(cfg.LogLevel)

lf := new(log.TextFormatter)
lf.FullTimestamp = true
log.SetFormatter(lf)

log.Infof("Initializing archived-access (%s @ %s) ...", appVersion, buildTimestamp)

g, _ := errgroup.WithContext(context.Background())

e := echo.New()
e.Use(middleware.Logger())
e.Use(middleware.Recover())

db, err := sql.Open("postgres", cfg.MetadataDSN)
if err != nil {
panic(err)
}

if err := db.Ping(); err != nil {
panic(err)
}

postgresqlRepo := postgresql.New(db)

// FIXME: Add BLOB repo initialization
AccessSvc := service.NewAccessService(postgresqlRepo, nil)

p := htmlPresenter.New(AccessSvc, cfg.HTMLTemplateDir)
p.Register(e)

g.Go(func() error {
srv := &http.Server{
Addr: cfg.Addr,
Handler: e,
}

return srv.ListenAndServe()
})

g.Go(func() error {
http.Handle("/metrics", promhttp.Handler())
return http.ListenAndServe(cfg.MetricsAddr, nil)
})

if err := g.Wait(); err != nil {
panic(err)
}
}
12 changes: 11 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,23 @@ go 1.22.5
require (
github.com/Masterminds/squirrel v1.5.4
github.com/golang-migrate/migrate/v4 v4.17.1
github.com/kelseyhightower/envconfig v1.4.0
github.com/labstack/echo/v4 v4.12.0
github.com/lib/pq v1.10.9
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.14.0
github.com/sirupsen/logrus v1.9.3
github.com/stretchr/testify v1.9.0
github.com/teran/go-docker-testsuite v0.0.6
github.com/teran/go-ptr v1.1.0
github.com/teran/go-time v0.0.2
golang.org/x/sync v0.7.0
)

require (
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/cilium/ebpf v0.11.0 // indirect
github.com/containerd/cgroups/v3 v3.0.3 // indirect
github.com/containerd/containerd v1.7.16 // indirect
Expand All @@ -32,6 +38,7 @@ require (
github.com/godbus/dbus/v5 v5.1.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
Expand All @@ -47,13 +54,16 @@ require (
github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/moby/docker-image-spec v1.3.1 // indirect
github.com/moby/sys/mountinfo v0.7.1 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.0 // indirect
github.com/opencontainers/runtime-spec v1.1.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/sirupsen/logrus v1.9.3 // 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/stretchr/objx v0.5.2 // indirect
github.com/teran/go-random v0.0.1 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
Expand Down
Loading
Loading