Compare commits

...

2 Commits

Author SHA1 Message Date
Urko 01ea05330c feat: add Dockerfile 2023-04-03 19:29:11 +02:00
Urko da303b27e0 feat: add crono to rest 2023-04-03 19:01:32 +02:00
3 changed files with 35 additions and 9 deletions

28
Dockerfile Normal file
View File

@ -0,0 +1,28 @@
FROM golang:1.19-buster as builder
# Create and change to the app directory.
WORKDIR /app
# Retrieve application dependencies.
# This allows the container build to reuse cached dependencies.
# Expecting to copy go.mod and if present go.sum.
COPY go.* ./
RUN go mod download
# Copy local code to the container image.
COPY . ./
# Build the binary.
RUN go build -v -o etl ./cmd/etl/main.go
# Use the official Debian slim image for a lean production container.
FROM debian:buster-slim
RUN set -x && apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \
ca-certificates && \
rm -rf /var/lib/apt/lists/*
# Copy the binary to the production image from the builder stage.
COPY --from=builder /app/etl /app/etl
# Run the web service on container startup.
CMD ["/app/etl"]

View File

@ -42,19 +42,17 @@ func main() {
professionalRepo := employee_wi.NewRepo(employeeWICollection)
restServer := http.
NewRestServer(cfg).
NewRestServer(cfg, cr).
WithProfessionalHandler(services.NewEmployeeWIService(ctx, professionalRepo))
cr.MarkAndRestart("dependencies loaded")
log.Println(cfg)
go func() {
cr.Restart()
if err = restServer.Start(cfg.ApiPort, ""); err != nil {
log.Fatalln("restServer.Start", err)
cancel()
}
cr.MarkAndRestart("server up")
}()
<-ctx.Done()
restServer.Shutdown()
log.Println("gracefully shutdown")

View File

@ -7,6 +7,7 @@ import (
"gitea.urkob.com/urko/ess-etl-go/config"
"gitea.urkob.com/urko/ess-etl-go/internal/api/http/handler"
"gitea.urkob.com/urko/ess-etl-go/internal/services"
"gitea.urkob.com/urko/ess-etl-go/pkg/crono"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/cors"
@ -15,12 +16,14 @@ import (
type restServer struct {
app *fiber.App
cfg *config.Config
cr *crono.Crono
employeeWIHdl *handler.EmployeeWorkInformationHandler
}
func NewRestServer(cfg *config.Config) *restServer {
func NewRestServer(cfg *config.Config, cr *crono.Crono) *restServer {
return &restServer{
cfg: cfg,
cr: cr,
}
}
@ -42,10 +45,7 @@ func (s *restServer) Start(apiPort, bearerToken string) error {
return s.employeeWIHdl.Get(c)
})
s.app.Get("/employee_wi/:id", func(c *fiber.Ctx) error {
return s.employeeWIHdl.Get(c)
})
s.cr.MarkAndRestart("server up")
if err := s.app.Listen(":" + apiPort); err != nil {
return fmt.Errorf("app.Listen: %s", err)
}