Skip to content
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
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ FROM alpine:3.21
RUN apk add --no-cache tzdata ca-certificates curl
WORKDIR /
COPY gmc gmc
COPY --chmod=444 binary-checksum /binary-checksum
USER nobody
ENTRYPOINT ["/gmc"]
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
.PHONY: test imports
SHELL := /bin/bash

VERSION?=0.0.1-local
VERSION?=$(shell git rev-parse HEAD )

IMAGE = quay.io/fortnox/gitmachinecontroller

build:
CGO_ENABLED=0 GOOS=linux go build -o gmc ./cmd/gmc
CGO_ENABLED=0 GOOS=linux go build -ldflags "-X main.BuildTime=$(shell date +%FT%T%z) -X main.Version=${VERSION} -X main.BuildCommit=$(shell git rev-parse HEAD)" -o gmc ./cmd/gmc
sha256sum gmc | awk '{print $$1}' > binary-checksum

docker: build
docker build --pull --rm -t $(IMAGE):$(VERSION) .
Expand Down
2 changes: 1 addition & 1 deletion e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ spec:
logrus.SetOutput(buf)
a := admin.NewAdmin("./adminConfig", "", "", admin.WithTLSConfig(trustCert("./cert.pem")))
err = a.Exec(context.TODO(), "uptime")
assert.Equal(t, "websocket: bad handshake", err.Error())
assert.Equal(t, "websocket: error status 401 Unauthorized", err.Error())

assert.Contains(t, buf.String(), "http_request_status=401")
cancel()
Expand Down
4 changes: 2 additions & 2 deletions pkg/admin/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func (a *Admin) Bootstrap(ctx context.Context, hosts []string) error {
return err
}

binaryPath, err := getSelfLocation()
binaryPath, err := GetSelfLocation()
if err != nil {
return err
}
Expand Down Expand Up @@ -206,7 +206,7 @@ func copyFileToServer(client *ssh.Client, src, dst string) error {

return session.Wait()
}
func getSelfLocation() (string, error) {
func GetSelfLocation() (string, error) {
fname, err := exec.LookPath(os.Args[0])
if err != nil {
return "", err
Expand Down
30 changes: 30 additions & 0 deletions pkg/master/webserver/webserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"time"

"github.com/fortnoxab/ginprometheus"
"github.com/fortnoxab/gitmachinecontroller/pkg/admin"
"github.com/fortnoxab/gitmachinecontroller/pkg/agent/config"
"github.com/fortnoxab/gitmachinecontroller/pkg/api/v1/protocol"
"github.com/fortnoxab/gitmachinecontroller/pkg/api/v1/types"
Expand Down Expand Up @@ -79,6 +80,35 @@ func (ws *Webserver) InitTLS() *gin.Engine {
fmt.Fprintf(c.Writer, `<a href="/machines">Machines</a>`)
})
router.GET("/api/up-v1", err(ws.listMasters))
router.GET("/api/download-v1", err(func(c *gin.Context) error {
binaryPath, err := admin.GetSelfLocation()
if err != nil {
return err
}

f, err := os.Open(binaryPath)
if err != nil {
return err
}

defer f.Close()

_, err = io.Copy(c.Writer, f)
return err

}))
router.GET("/api/binary-checksum-v1", err(func(c *gin.Context) error {
f, err := os.Open("/binary-checksum")
if err != nil {
return err
}

defer f.Close()

_, err = io.Copy(c.Writer, f)
return err

}))
router.POST("/api/admin-v1", err(ws.createAdmin))

requireAdmin := router.Group("/")
Expand Down