Skip to content

Commit 9596f9d

Browse files
authored
Merge pull request #87 from mutablelogic/v5
V5
2 parents d716087 + 3af74b1 commit 9596f9d

File tree

19 files changed

+258
-79
lines changed

19 files changed

+258
-79
lines changed

.github/workflows/docker.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
- name: Install build tools
2929
run: |
3030
sudo apt -y update
31-
sudo apt -y install build-essential git
31+
sudo apt -y install build-essential git npm
3232
git config --global advice.detachedHead false
3333
- name: Checkout
3434
uses: actions/checkout@v4

Makefile

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,25 +44,32 @@ all: clean build
4444
###############################################################################
4545
# BUILD
4646

47-
# Build the commands in the cmd directory
47+
# Compile NPM and build the commands in the cmd directory
4848
.PHONY: build
49-
build: tidy $(NPM_DIR) $(PLUGIN_DIR) $(CMD_DIR)
49+
build: $(NPM_DIR) build-docker
50+
51+
# Build the commands in the cmd directory
52+
.PHONY: build-docker
53+
build-docker: tidy $(PLUGIN_DIR) $(CMD_DIR)
5054

55+
# Build the commands
5156
$(CMD_DIR): go-dep mkdir
5257
@echo Build command $(notdir $@) GOOS=${OS} GOARCH=${ARCH}
5358
@GOOS=${OS} GOARCH=${ARCH} ${GO} build ${BUILD_FLAGS} -o ${BUILD_DIR}/$(notdir $@) ./$@
5459

60+
# Build the plugins
5561
$(PLUGIN_DIR): go-dep mkdir
5662
@echo Build plugin $(notdir $@) GOOS=${OS} GOARCH=${ARCH}
5763
@GOOS=${OS} GOARCH=${ARCH} ${GO} build -buildmode=plugin ${BUILD_FLAGS} -o ${BUILD_DIR}/$(notdir $@).plugin ./$@
5864

65+
# Build the NPM packages
5966
$(NPM_DIR): npm-dep
6067
@echo Build npm $(notdir $@)
6168
@cd $@ && npm install && npm run prod
6269

6370
# Build the docker image
6471
.PHONY: docker
65-
docker: docker-dep
72+
docker: docker-dep ${NPM_DIR}
6673
@echo build docker image ${DOCKER_TAG} OS=${OS} ARCH=${ARCH} SOURCE=${DOCKER_SOURCE} VERSION=${VERSION}
6774
@${DOCKER} build \
6875
--tag ${DOCKER_TAG} \

cmd/server/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ type CLI struct {
3434
auth.UserCommands
3535
auth.TokenCommands
3636
auth.AuthCommands
37+
VersionCommands
3738
}
3839

3940
///////////////////////////////////////////////////////////////////////////////

cmd/server/service.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"context"
5+
"fmt"
56
"net/http"
67

78
// Packages
@@ -32,7 +33,8 @@ type ServiceCommands struct {
3233
}
3334

3435
type ServiceRunCommand struct {
35-
Router struct {
36+
Plugins []string `help:"Plugin paths"`
37+
Router struct {
3638
httprouter.Config `embed:"" prefix:"router."` // Router configuration
3739
} `embed:""`
3840
Server struct {
@@ -62,6 +64,15 @@ type ServiceRunCommand struct {
6264
// PUBLIC METHODS
6365

6466
func (cmd *ServiceRunCommand) Run(app server.Cmd) error {
67+
// Load plugins
68+
plugins, err := provider.LoadPluginsForPattern(cmd.Plugins...)
69+
if err != nil {
70+
return err
71+
}
72+
for _, plugin := range plugins {
73+
fmt.Println("TODO: Loaded plugins:", plugin.Name())
74+
}
75+
6576
// Set the server listener and router prefix
6677
cmd.Server.Listen = app.GetEndpoint()
6778
cmd.Router.Prefix = types.NormalisePath(cmd.Server.Listen.Path)

cmd/server/version.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package main
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
7+
// Packages
8+
server "github.com/mutablelogic/go-server"
9+
version "github.com/mutablelogic/go-server/pkg/version"
10+
)
11+
12+
///////////////////////////////////////////////////////////////////////////////
13+
// TYPES
14+
15+
type VersionCommands struct {
16+
Version VersionCommand `cmd:"" group:"MISC" help:"Print version information"`
17+
}
18+
19+
type VersionCommand struct{}
20+
21+
///////////////////////////////////////////////////////////////////////////////
22+
// PUBLIC METHODS
23+
24+
func (cmd *VersionCommand) Run(app server.Cmd) error {
25+
// Print version information
26+
data, err := json.MarshalIndent(version.Map(), "", " ")
27+
if err != nil {
28+
return err
29+
}
30+
fmt.Println(string(data))
31+
return nil
32+
}

etc/docker/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ COPY . .
1111
# Build the server
1212
RUN \
1313
apt update -y && apt upgrade -y && \
14-
OS=${OS} ARCH=${ARCH} make build
14+
OS=${OS} ARCH=${ARCH} make build-docker
1515

1616
# Copy binaries to /usr/local/bin
1717
FROM --platform=${OS}/${ARCH} debian:bookworm-slim

go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ go 1.23.5
44

55
require (
66
github.com/alecthomas/kong v1.10.0
7+
github.com/djthorpe/go-marshaler v0.0.15
78
github.com/djthorpe/go-pg v1.0.5
89
github.com/golang-jwt/jwt/v5 v5.2.2
910
github.com/mutablelogic/go-client v1.0.12
@@ -31,6 +32,8 @@ require (
3132
github.com/go-ole/go-ole v1.2.6 // indirect
3233
github.com/gogo/protobuf v1.3.2 // indirect
3334
github.com/google/uuid v1.6.0 // indirect
35+
github.com/hashicorp/errwrap v1.1.0 // indirect
36+
github.com/hashicorp/go-multierror v1.1.1 // indirect
3437
github.com/jackc/pgpassfile v1.0.0 // indirect
3538
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
3639
github.com/jackc/pgx/v5 v5.7.3 // indirect

go.sum

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ github.com/distribution/reference v0.6.0 h1:0IXCQ5g4/QMHHkarYzh5l+u8T3t73zM5Qvfr
3232
github.com/distribution/reference v0.6.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E=
3333
github.com/djthorpe/go-errors v1.0.3 h1:GZeMPkC1mx2vteXLI/gvxZS0Ee9zxzwD1mcYyKU5jD0=
3434
github.com/djthorpe/go-errors v1.0.3/go.mod h1:HtfrZnMd6HsX75Mtbv9Qcnn0BqOrrFArvCaj3RMnZhY=
35+
github.com/djthorpe/go-marshaler v0.0.15 h1:ZXq5YHCsbREbbYJtc0ie9hz7HJ7vIeeDlMbe7cGh0C0=
36+
github.com/djthorpe/go-marshaler v0.0.15/go.mod h1:xCXhTzj52UL3YStRsqUSfrKses7ofmfTXYQfVedn8Lw=
3537
github.com/djthorpe/go-pg v1.0.5 h1:UYCV5fSXOJEFTafem1wB57RK2J0V7Nr9nCquC5sO+ZE=
3638
github.com/djthorpe/go-pg v1.0.5/go.mod h1:XHl/w8+66Hs746nOYd+gdjqPImNuLVZ5UsXLI47rb4c=
3739
github.com/docker/docker v27.1.1+incompatible h1:hO/M4MtV36kzKldqnA37IWhebRA+LnqqcqDja6kVaKY=
@@ -61,6 +63,11 @@ github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
6163
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
6264
github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 h1:YBftPWNWd4WwGqtY2yeZL2ef8rHAxPBD8KFhJpmcqms=
6365
github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0/go.mod h1:YN5jB8ie0yfIUg6VvR9Kz84aCaG7AsGZnLjhHbUqwPg=
66+
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
67+
github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I=
68+
github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
69+
github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo=
70+
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
6471
github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM=
6572
github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg=
6673
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=

pkg/cert/config/config.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,14 @@ func (c Config) New(ctx context.Context) (server.Task, error) {
7171
certhandler.RegisterCert(ctx, c.Router, c.Prefix, certmanager)
7272
}
7373

74-
// Queue task to check for SSL expiry
74+
// Queue ticker and queue to check for SSL expiry
7575
if c.Queue != nil {
76-
c.Queue.RegisterTicker(ctx, pgqueue.TickerMeta{
77-
Ticker: c.Name(),
78-
Interval: types.DurationPtr(time.Minute),
79-
}, func(ctx context.Context, _ any) error {
80-
ref.Log(ctx).Print(ctx, "Checking for SSL expiry...")
76+
if _, err := c.Queue.RegisterTicker(ctx, pgqueue.TickerMeta{Ticker: c.Name(), Interval: types.DurationPtr(time.Hour)}, func(ctx context.Context, _ any) error {
77+
ref.Log(ctx).Print(ctx, "TODO: Checking for SSL expiry...")
8178
return nil
82-
})
79+
}); err != nil {
80+
return nil, err
81+
}
8382
}
8483

8584
// Return the task

pkg/httpserver/httpserver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"time"
1212

1313
// Packages
14-
"github.com/mutablelogic/go-server/pkg/httpresponse"
14+
httpresponse "github.com/mutablelogic/go-server/pkg/httpresponse"
1515
ref "github.com/mutablelogic/go-server/pkg/ref"
1616
)
1717

0 commit comments

Comments
 (0)