Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
157bfbdd33 | ||
|
|
3a2eb1f4d2 |
+5
-1
@@ -1,4 +1,8 @@
|
|||||||
.git
|
# .git is sent without its config. Without a VERSION build argument the
|
||||||
|
# stage that compiles runs `git describe --tags --always` on .git, which
|
||||||
|
# does not need .git/config; that file can hold a credential, such as a
|
||||||
|
# password in a remote URL or the token the CI checkout step stores there.
|
||||||
|
.git/config
|
||||||
.gitignore
|
.gitignore
|
||||||
.DS_Store
|
.DS_Store
|
||||||
.env*
|
.env*
|
||||||
|
|||||||
+12
-20
@@ -112,15 +112,13 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
Appname string = "CHANGEME"
|
Appname string = "CHANGEME"
|
||||||
Version string
|
Version string
|
||||||
Buildarch string
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
globals.Appname = Appname
|
globals.Appname = Appname
|
||||||
globals.Version = Version
|
globals.Version = Version
|
||||||
globals.Buildarch = Buildarch
|
|
||||||
|
|
||||||
fx.New(
|
fx.New(
|
||||||
fx.Provide(
|
fx.Provide(
|
||||||
@@ -859,7 +857,7 @@ func (l *Logger) Identify() {
|
|||||||
l.log.Info("starting",
|
l.log.Info("starting",
|
||||||
"appname", l.params.Globals.Appname,
|
"appname", l.params.Globals.Appname,
|
||||||
"version", l.params.Globals.Version,
|
"version", l.params.Globals.Version,
|
||||||
"buildarch", l.params.Globals.Buildarch,
|
"arch", runtime.GOARCH,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -979,23 +977,20 @@ import "go.uber.org/fx"
|
|||||||
|
|
||||||
// Package-level variables (set from main)
|
// Package-level variables (set from main)
|
||||||
var (
|
var (
|
||||||
Appname string
|
Appname string
|
||||||
Version string
|
Version string
|
||||||
Buildarch string
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Struct for DI
|
// Struct for DI
|
||||||
type Globals struct {
|
type Globals struct {
|
||||||
Appname string
|
Appname string
|
||||||
Version string
|
Version string
|
||||||
Buildarch string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(lc fx.Lifecycle) (*Globals, error) {
|
func New(lc fx.Lifecycle) (*Globals, error) {
|
||||||
n := &Globals{
|
n := &Globals{
|
||||||
Appname: Appname,
|
Appname: Appname,
|
||||||
Buildarch: Buildarch,
|
Version: Version,
|
||||||
Version: Version,
|
|
||||||
}
|
}
|
||||||
return n, nil
|
return n, nil
|
||||||
}
|
}
|
||||||
@@ -1006,15 +1001,13 @@ func New(lc fx.Lifecycle) (*Globals, error) {
|
|||||||
```go
|
```go
|
||||||
// cmd/httpd/main.go
|
// cmd/httpd/main.go
|
||||||
var (
|
var (
|
||||||
Appname string = "CHANGEME" // Default, overridden by build
|
Appname string = "CHANGEME" // Default, overridden by build
|
||||||
Version string // Set at build time
|
Version string // Set at build time
|
||||||
Buildarch string // Set at build time
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
globals.Appname = Appname
|
globals.Appname = Appname
|
||||||
globals.Version = Version
|
globals.Version = Version
|
||||||
globals.Buildarch = Buildarch
|
|
||||||
// ...
|
// ...
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -1025,10 +1018,9 @@ Use ldflags to inject version information at build time:
|
|||||||
|
|
||||||
```makefile
|
```makefile
|
||||||
VERSION := $(shell git describe --tags --always)
|
VERSION := $(shell git describe --tags --always)
|
||||||
BUILDARCH := $(shell go env GOARCH)
|
|
||||||
|
|
||||||
build:
|
build:
|
||||||
go build -ldflags "-X main.Version=$(VERSION) -X main.Buildarch=$(BUILDARCH)" ./cmd/httpd
|
go build -ldflags "-X main.Version=$(VERSION)" ./cmd/httpd
|
||||||
```
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|||||||
+18
-7
@@ -43,13 +43,24 @@ COPY . .
|
|||||||
RUN make test
|
RUN make test
|
||||||
|
|
||||||
# VERSION is declared here, not earlier: a new value reruns only the
|
# VERSION is declared here, not earlier: a new value reruns only the
|
||||||
# build, not script/bootstrap or the tests. CGO stays enabled for
|
# build, not script/bootstrap or the tests. Given none, the version is
|
||||||
# govips; -trimpath keeps build paths out of the binary, and -s -w
|
# `git describe --tags --always` of the .git in the build context (git
|
||||||
# leave out the symbol table and debug information.
|
# comes from script/bootstrap): the tag on a tagged commit, tag-N-gHASH
|
||||||
ARG VERSION=dev
|
# after one, the short commit when no tag is reachable. A context that
|
||||||
RUN CGO_ENABLED=1 GOTOOLCHAIN=auto go build -trimpath \
|
# carries .git and still yields no version fails the build; one without
|
||||||
-ldflags "-s -w -X main.Version=${VERSION}" \
|
# .git, as from a source tarball, stamps an empty version. CGO stays
|
||||||
-o /pixad ./cmd/pixad
|
# enabled for govips; -trimpath keeps build paths out of the binary, and
|
||||||
|
# -s -w leave out the symbol table and debug information.
|
||||||
|
ARG VERSION
|
||||||
|
RUN version="${VERSION:-$(git describe --tags --always)}"; \
|
||||||
|
if [ -e .git ] && { [ -z "$version" ] || [ "$version" = dev ] || \
|
||||||
|
[ "$version" = unknown ]; }; then \
|
||||||
|
echo "the build context carries .git but yields no version" >&2; \
|
||||||
|
exit 1; \
|
||||||
|
fi; \
|
||||||
|
CGO_ENABLED=1 GOTOOLCHAIN=auto go build -trimpath \
|
||||||
|
-ldflags "-s -w -X main.Version=${version}" \
|
||||||
|
-o /pixad ./cmd/pixad
|
||||||
|
|
||||||
# Runtime stage
|
# Runtime stage
|
||||||
# alpine:3.21, 2026-02-25
|
# alpine:3.21, 2026-02-25
|
||||||
|
|||||||
@@ -29,6 +29,13 @@ P2: security: referer blacklist
|
|||||||
|
|
||||||
# Completed Steps
|
# Completed Steps
|
||||||
|
|
||||||
|
- 2026-10-02 a plain `docker build .` stamps the tag or short commit, not
|
||||||
|
`dev` (closes #166): `.dockerignore` lets `.git` into the build context,
|
||||||
|
without `.git/config`; with no `VERSION` build argument the `Dockerfile`
|
||||||
|
takes the version from `git describe --tags --always`, and fails the build if
|
||||||
|
the context carries `.git` and no version comes out; `ARG VERSION` has no
|
||||||
|
default; pixad logs its version, with its name and architecture, as its first
|
||||||
|
log line at startup.
|
||||||
- 2026-09-29 the container makes `/var/lib/pixa` usable by itself (closes
|
- 2026-09-29 the container makes `/var/lib/pixa` usable by itself (closes
|
||||||
#159): `deploy/docker-entrypoint.sh` creates the directory if it is missing,
|
#159): `deploy/docker-entrypoint.sh` creates the directory if it is missing,
|
||||||
gives the directory and everything in it to `pixad` when the directory or one
|
gives the directory and everything in it to `pixad` when the directory or one
|
||||||
|
|||||||
+4
-1
@@ -56,6 +56,9 @@ func run(_ *cobra.Command, _ []string) {
|
|||||||
middleware.New,
|
middleware.New,
|
||||||
healthcheck.New,
|
healthcheck.New,
|
||||||
),
|
),
|
||||||
fx.Invoke(func(*server.Server) {}),
|
fx.Invoke(
|
||||||
|
func(log *logger.Logger) { log.Identify() },
|
||||||
|
func(*server.Server) {},
|
||||||
|
),
|
||||||
).Run()
|
).Run()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user