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
2 changes: 2 additions & 0 deletions .github/workflows/publish-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ jobs:
./docker-bake.hcl
cwd://${{ steps.meta.outputs.bake-file }}
targets: release
set: |
release.args.VERSION=${{ inputs.tag }}
push: true

# release-please creates the release as a draft so it only becomes visible
Expand Down
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ RUN go mod download
COPY *.go ./
ARG TARGETOS=linux
ARG TARGETARCH
RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build -trimpath -ldflags="-s -w" -o /out/doormouse .
ARG VERSION=dev
RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build -trimpath -ldflags="-s -w -X main.version=$VERSION" -o /out/doormouse .

FROM alpine:3.22

Expand Down
12 changes: 11 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ type Logger interface {

const tcpScheme = "tcp://"

// version is replaced by the release build. Keep a useful value for local
// builds and tests that do not supply linker flags.
var version = "dev"

// shutdownGrace is how long in-flight requests get to finish on shutdown.
const shutdownGrace = 15 * time.Second

Expand Down Expand Up @@ -1728,6 +1732,10 @@ func (l *StdLogger) Error(msg string, args ...interface{}) {
log.Printf("[ERROR] "+msg, args...)
}

func logStartup(logger Logger, version string) {
logger.Info("Starting doormouse version `%s`", version)
}

// warnUnreadableSSHKeys reports SSH keys the process cannot open. The key is
// otherwise read only when a machine has gone idle, so a permissions mistake
// stays invisible until the first shutdown silently fails, up to an
Expand Down Expand Up @@ -1760,6 +1768,9 @@ func warnUnreadableSSHKeys(config *ProxyConfig, logger Logger) {

// Main function
func main() {
logger := &StdLogger{}
logStartup(logger, version)

if len(os.Args) < 2 {
log.Fatal("Usage: doormouse <config.toml>")
}
Expand All @@ -1768,7 +1779,6 @@ func main() {

// Load configuration
clock := RealClock{}
logger := &StdLogger{}

MigrateConfigFile(configFile, logger)

Expand Down
26 changes: 26 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,32 @@ type noopLogger struct{}
func (noopLogger) Info(_ string, _ ...interface{}) {}
func (noopLogger) Error(_ string, _ ...interface{}) {}

type startupLogger struct {
info []string
error []string
}

func (l *startupLogger) Info(msg string, args ...interface{}) {
l.info = append(l.info, fmt.Sprintf(msg, args...))
}

func (l *startupLogger) Error(msg string, args ...interface{}) {
l.error = append(l.error, fmt.Sprintf(msg, args...))
}

func TestLogStartup_LogsDoormouseVersionAtInfoLevel(t *testing.T) {
logger := &startupLogger{}

logStartup(logger, "2.1.0")

if len(logger.info) != 1 || logger.info[0] != "Starting doormouse version `2.1.0`" {
t.Fatalf("info logs = %q, want one startup version line", logger.info)
}
if len(logger.error) != 0 {
t.Fatalf("error logs = %q, want none", logger.error)
}
}

// ---------------------------------------------------------------------------
// Test helpers
// ---------------------------------------------------------------------------
Expand Down