mirror of
https://github.com/kairos-io/kairos-agent.git
synced 2025-06-03 01:44:53 +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:
|
version:
|
||||||
FROM alpine
|
FROM alpine
|
||||||
RUN apk add git
|
RUN apk add git
|
||||||
|
|
||||||
COPY . ./
|
COPY . ./
|
||||||
|
|
||||||
RUN --no-cache echo $(git describe --always --tags --dirty) > VERSION
|
RUN --no-cache echo $(git describe --always --tags --dirty) > VERSION
|
||||||
|
RUN --no-cache echo $(git describe --always --dirty) > COMMIT
|
||||||
ARG VERSION=$(cat VERSION)
|
ARG VERSION=$(cat VERSION)
|
||||||
|
ARG COMMIT=$(cat COMMIT)
|
||||||
SAVE ARTIFACT VERSION VERSION
|
SAVE ARTIFACT VERSION VERSION
|
||||||
|
SAVE ARTIFACT COMMIT COMMIT
|
||||||
|
|
||||||
build-kairos-agent:
|
build-kairos-agent:
|
||||||
FROM +go-deps
|
FROM +go-deps
|
||||||
@ -45,9 +45,11 @@ build-kairos-agent:
|
|||||||
COPY +webui-deps/node_modules ./internal/webui/public/node_modules
|
COPY +webui-deps/node_modules ./internal/webui/public/node_modules
|
||||||
COPY github.com/kairos-io/kairos-docs:main+docs/public ./internal/webui/public
|
COPY github.com/kairos-io/kairos-docs:main+docs/public ./internal/webui/public
|
||||||
COPY +version/VERSION ./
|
COPY +version/VERSION ./
|
||||||
|
COPY +version/COMMIT ./
|
||||||
ARG VERSION=$(cat VERSION)
|
ARG VERSION=$(cat VERSION)
|
||||||
RUN echo $(cat VERSION)
|
ARG COMMIT=$(cat COMMIT)
|
||||||
ARG LDFLAGS="-s -w -X 'github.com/kairos-io/kairos/v2/internal/common.VERSION=${VERSION}'"
|
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}
|
ENV CGO_ENABLED=${CGO_ENABLED}
|
||||||
RUN go build -o kairos-agent -ldflags "${LDFLAGS}" main.go && upx kairos-agent
|
RUN go build -o kairos-agent -ldflags "${LDFLAGS}" main.go && upx kairos-agent
|
||||||
SAVE ARTIFACT kairos-agent kairos-agent AS LOCAL build/kairos-agent
|
SAVE ARTIFACT kairos-agent kairos-agent AS LOCAL build/kairos-agent
|
||||||
|
@ -1,7 +1,34 @@
|
|||||||
package common
|
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 {
|
func GetVersion() string {
|
||||||
return VERSION
|
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
|
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() {
|
func main() {
|
||||||
|
Loading…
Reference in New Issue
Block a user