mirror of
https://github.com/kairos-io/kairos-agent.git
synced 2025-04-27 11:21:44 +00:00
✨ Add extended version command (#37)
This commit is contained in:
parent
b55e3e0800
commit
ba72c14346
12
Earthfile
12
Earthfile
@ -30,13 +30,13 @@ test:
|
||||
version:
|
||||
FROM alpine
|
||||
RUN apk add git
|
||||
|
||||
COPY . ./
|
||||
|
||||
RUN --no-cache echo $(git describe --always --tags --dirty) > VERSION
|
||||
|
||||
RUN --no-cache echo $(git describe --always --dirty) > COMMIT
|
||||
ARG VERSION=$(cat VERSION)
|
||||
ARG COMMIT=$(cat COMMIT)
|
||||
SAVE ARTIFACT VERSION VERSION
|
||||
SAVE ARTIFACT COMMIT COMMIT
|
||||
|
||||
build-kairos-agent:
|
||||
FROM +go-deps
|
||||
@ -45,9 +45,11 @@ build-kairos-agent:
|
||||
COPY +webui-deps/node_modules ./internal/webui/public/node_modules
|
||||
COPY github.com/kairos-io/kairos-docs:main+docs/public ./internal/webui/public
|
||||
COPY +version/VERSION ./
|
||||
COPY +version/COMMIT ./
|
||||
ARG VERSION=$(cat VERSION)
|
||||
RUN echo $(cat VERSION)
|
||||
ARG LDFLAGS="-s -w -X 'github.com/kairos-io/kairos/v2/internal/common.VERSION=${VERSION}'"
|
||||
ARG COMMIT=$(cat COMMIT)
|
||||
RUN --no-cache echo "Building Version: ${VERSION} and Commit: ${COMMIT}"
|
||||
ARG LDFLAGS="-s -w -X github.com/kairos-io/kairos/v2/internal/common.VERSION=${VERSION} -X github.com/kairos-io/kairos/v2/internal/common.gitCommit=$COMMIT"
|
||||
ENV CGO_ENABLED=${CGO_ENABLED}
|
||||
RUN go build -o kairos-agent -ldflags "${LDFLAGS}" main.go && upx kairos-agent
|
||||
SAVE ARTIFACT kairos-agent kairos-agent AS LOCAL build/kairos-agent
|
||||
|
@ -1,7 +1,34 @@
|
||||
package common
|
||||
|
||||
var VERSION = "0.0.0"
|
||||
import "runtime"
|
||||
|
||||
var (
|
||||
VERSION = "v0.0.1"
|
||||
// gitCommit is the git sha1 + dirty if build from a dirty git.
|
||||
gitCommit = "none"
|
||||
)
|
||||
|
||||
func GetVersion() string {
|
||||
return VERSION
|
||||
}
|
||||
|
||||
// BuildInfo describes the compiled time information.
|
||||
type BuildInfo struct {
|
||||
// Version is the current semver.
|
||||
Version string `json:"version,omitempty"`
|
||||
// GitCommit is the git sha1.
|
||||
GitCommit string `json:"git_commit,omitempty"`
|
||||
// GoVersion is the version of the Go compiler used.
|
||||
GoVersion string `json:"go_version,omitempty"`
|
||||
}
|
||||
|
||||
// Get returns build info.
|
||||
func Get() BuildInfo {
|
||||
v := BuildInfo{
|
||||
Version: GetVersion(),
|
||||
GitCommit: gitCommit,
|
||||
GoVersion: runtime.Version(),
|
||||
}
|
||||
|
||||
return v
|
||||
}
|
||||
|
20
main.go
20
main.go
@ -580,6 +580,26 @@ The validate command expects a configuration file as its only argument. Local fi
|
||||
return nil
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "version",
|
||||
Description: "Print kairos-agent version",
|
||||
Usage: "Print kairos-agent version",
|
||||
Flags: []cli.Flag{
|
||||
&cli.BoolFlag{
|
||||
Name: "long",
|
||||
Usage: "Print long version info",
|
||||
Aliases: []string{"l"},
|
||||
},
|
||||
},
|
||||
Action: func(c *cli.Context) error {
|
||||
if c.Bool("long") {
|
||||
fmt.Printf("%+v\n", common.Get())
|
||||
} else {
|
||||
fmt.Println(common.VERSION)
|
||||
}
|
||||
return nil
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
Loading…
Reference in New Issue
Block a user