mirror of https://github.com/portainer/portainer
version: display dependencies versions (#188)
Co-authored-by: LP B <xAt0mZ@users.noreply.github.com>release/2.25
parent
d393529026
commit
a261f60764
|
@ -1,12 +0,0 @@
|
|||
package build
|
||||
|
||||
import "runtime"
|
||||
|
||||
// Variables to be set during the build time
|
||||
var BuildNumber string
|
||||
var ImageTag string
|
||||
var NodejsVersion string
|
||||
var YarnVersion string
|
||||
var WebpackVersion string
|
||||
var GoVersion string = runtime.Version()
|
||||
var GitCommit string
|
|
@ -10,7 +10,6 @@ import (
|
|||
|
||||
portainer "github.com/portainer/portainer/api"
|
||||
"github.com/portainer/portainer/api/apikey"
|
||||
"github.com/portainer/portainer/api/build"
|
||||
"github.com/portainer/portainer/api/chisel"
|
||||
"github.com/portainer/portainer/api/cli"
|
||||
"github.com/portainer/portainer/api/crypto"
|
||||
|
@ -47,6 +46,7 @@ import (
|
|||
"github.com/portainer/portainer/api/platform"
|
||||
"github.com/portainer/portainer/api/scheduler"
|
||||
"github.com/portainer/portainer/api/stacks/deployments"
|
||||
"github.com/portainer/portainer/pkg/build"
|
||||
"github.com/portainer/portainer/pkg/featureflags"
|
||||
"github.com/portainer/portainer/pkg/libhelm"
|
||||
"github.com/portainer/portainer/pkg/libstack/compose"
|
||||
|
|
|
@ -2,12 +2,11 @@ package system
|
|||
|
||||
import (
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
portainer "github.com/portainer/portainer/api"
|
||||
"github.com/portainer/portainer/api/build"
|
||||
"github.com/portainer/portainer/api/http/client"
|
||||
"github.com/portainer/portainer/api/http/security"
|
||||
"github.com/portainer/portainer/pkg/build"
|
||||
httperror "github.com/portainer/portainer/pkg/libhttp/error"
|
||||
"github.com/portainer/portainer/pkg/libhttp/response"
|
||||
|
||||
|
@ -25,18 +24,9 @@ type versionResponse struct {
|
|||
ServerVersion string
|
||||
ServerEdition string `json:"ServerEdition" example:"CE/EE"`
|
||||
DatabaseVersion string
|
||||
Build BuildInfo
|
||||
}
|
||||
|
||||
type BuildInfo struct {
|
||||
BuildNumber string
|
||||
ImageTag string
|
||||
NodejsVersion string
|
||||
YarnVersion string
|
||||
WebpackVersion string
|
||||
GoVersion string
|
||||
GitCommit string
|
||||
Env []string `json:",omitempty"`
|
||||
Build build.BuildInfo
|
||||
Dependencies build.DependenciesInfo
|
||||
Runtime build.RuntimeInfo
|
||||
}
|
||||
|
||||
// @id systemVersion
|
||||
|
@ -59,19 +49,12 @@ func (handler *Handler) version(w http.ResponseWriter, r *http.Request) *httperr
|
|||
ServerVersion: portainer.APIVersion,
|
||||
DatabaseVersion: portainer.APIVersion,
|
||||
ServerEdition: portainer.Edition.GetEditionLabel(),
|
||||
Build: BuildInfo{
|
||||
BuildNumber: build.BuildNumber,
|
||||
ImageTag: build.ImageTag,
|
||||
NodejsVersion: build.NodejsVersion,
|
||||
YarnVersion: build.YarnVersion,
|
||||
WebpackVersion: build.WebpackVersion,
|
||||
GoVersion: build.GoVersion,
|
||||
GitCommit: build.GitCommit,
|
||||
},
|
||||
Build: build.GetBuildInfo(),
|
||||
Dependencies: build.GetDependenciesInfo(),
|
||||
}
|
||||
|
||||
if isAdmin {
|
||||
result.Build.Env = os.Environ()
|
||||
result.Runtime = build.GetRuntimeInfo()
|
||||
}
|
||||
|
||||
latestVersion := GetLatestVersion()
|
||||
|
|
|
@ -22,6 +22,14 @@ export interface VersionResponse {
|
|||
WebpackVersion: string;
|
||||
GoVersion: string;
|
||||
GitCommit: string;
|
||||
};
|
||||
Dependencies: {
|
||||
DockerVersion: string;
|
||||
HelmVersion: string;
|
||||
KubectlVersion: string;
|
||||
ComposeVersion: string;
|
||||
};
|
||||
Runtime: {
|
||||
Env?: string[];
|
||||
};
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ import {
|
|||
Database,
|
||||
GitCommit,
|
||||
Hash,
|
||||
Link as LinkIcon,
|
||||
Server,
|
||||
Tag,
|
||||
Variable,
|
||||
|
@ -56,7 +57,8 @@ function BuildInfoModal({ closeModal }: { closeModal: () => void }) {
|
|||
}
|
||||
|
||||
const { Edition } = statusQuery.data;
|
||||
const { ServerVersion, DatabaseVersion, Build } = versionQuery.data;
|
||||
const { ServerVersion, DatabaseVersion, Build, Dependencies, Runtime } =
|
||||
versionQuery.data;
|
||||
|
||||
return (
|
||||
<Modal onDismiss={closeModal} aria-label="build-info-modal">
|
||||
|
@ -111,17 +113,39 @@ function BuildInfoModal({ closeModal }: { closeModal: () => void }) {
|
|||
|
||||
<div className={styles.tools}>
|
||||
<span className="text-muted small">
|
||||
Nodejs v{Build.NodejsVersion}
|
||||
Nodejs {Build.NodejsVersion}
|
||||
</span>
|
||||
<span className="text-muted small">Yarn v{Build.YarnVersion}</span>
|
||||
<span className="text-muted small">
|
||||
Webpack v{Build.WebpackVersion}
|
||||
</span>
|
||||
<span className="text-muted small">Go v{Build.GoVersion}</span>
|
||||
<span className="text-muted small">Go {Build.GoVersion}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{isAdmin && Build.Env && (
|
||||
<div className={clsx(styles.toolsList, 'mt-3')}>
|
||||
<span className="inline-flex items-center">
|
||||
<LinkIcon size="13" className="space-right" />
|
||||
Dependencies:
|
||||
</span>
|
||||
|
||||
<div className={styles.tools}>
|
||||
<span className="text-muted small">
|
||||
Docker {Dependencies.DockerVersion}
|
||||
</span>
|
||||
<span className="text-muted small">
|
||||
Helm {Dependencies.HelmVersion}
|
||||
</span>
|
||||
<span className="text-muted small">
|
||||
Kubectl {Dependencies.KubectlVersion}
|
||||
</span>
|
||||
<span className="text-muted small">
|
||||
Compose {Dependencies.ComposeVersion}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{isAdmin && Runtime.Env && (
|
||||
<div className={clsx(styles.toolsList, 'mt-3')}>
|
||||
<span className="inline-flex items-center ">
|
||||
<Variable size="13" className="space-right" />
|
||||
|
@ -131,7 +155,7 @@ function BuildInfoModal({ closeModal }: { closeModal: () => void }) {
|
|||
<div
|
||||
className={clsx(styles.tools, 'max-h-32 space-y-2 overflow-auto')}
|
||||
>
|
||||
{Build.Env.map((envVar) => (
|
||||
{Runtime.Env.map((envVar) => (
|
||||
<div key={envVar}>
|
||||
<code>{envVar}</code>
|
||||
</div>
|
||||
|
|
|
@ -3,4 +3,4 @@
|
|||
"helm": "v3.15.4",
|
||||
"kubectl": "v1.31.0",
|
||||
"mingit": "2.46.0.1"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,14 @@
|
|||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
BUILD_SOURCESDIRECTORY=${BUILD_SOURCESDIRECTORY:-$(pwd)}
|
||||
BINARY_VERSION_FILE="$BUILD_SOURCESDIRECTORY/binary-version.json"
|
||||
|
||||
if [[ ! -f $BINARY_VERSION_FILE ]] ; then
|
||||
echo 'File $BINARY_VERSION_FILE not found, aborting build.'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
mkdir -p dist
|
||||
|
||||
# populate tool versions
|
||||
|
@ -13,6 +21,12 @@ WEBPACK_VERSION=${WEBPACK_VERSION:-$(yarn list webpack --depth=0 | grep webpack
|
|||
GO_VERSION=${GO_VERSION:-$(go version | awk '{print $3}')}
|
||||
GIT_COMMIT_HASH=${GIT_COMMIT_HASH:-$(git rev-parse --short HEAD)}
|
||||
|
||||
# populate dependencies versions
|
||||
DOCKER_VERSION=$(jq -r '.docker' < "${BINARY_VERSION_FILE}")
|
||||
HELM_VERSION=$(jq -r '.helm' < "${BINARY_VERSION_FILE}")
|
||||
KUBECTL_VERSION=$(jq -r '.kubectl' < "${BINARY_VERSION_FILE}")
|
||||
COMPOSE_VERSION=$(go list -m -f '{{.Version}}' github.com/docker/compose/v2)
|
||||
|
||||
# copy templates
|
||||
cp -r "./mustache-templates" "./dist"
|
||||
|
||||
|
@ -23,15 +37,17 @@ go get -t -d -v ./...
|
|||
|
||||
|
||||
ldflags="-s -X 'github.com/portainer/liblicense.LicenseServerBaseURL=https://api.portainer.io' \
|
||||
-X 'github.com/portainer/portainer/api/build.BuildNumber=${BUILDNUMBER}' \
|
||||
-X 'github.com/portainer/portainer/api/build.ImageTag=${CONTAINER_IMAGE_TAG}' \
|
||||
-X 'github.com/portainer/portainer/api/build.NodejsVersion=${NODE_VERSION}' \
|
||||
-X 'github.com/portainer/portainer/api/build.YarnVersion=${YARN_VERSION}' \
|
||||
-X 'github.com/portainer/portainer/api/build.WebpackVersion=${WEBPACK_VERSION}' \
|
||||
-X 'github.com/portainer/portainer/api/build.GitCommit=${GIT_COMMIT_HASH}' \
|
||||
-X 'github.com/portainer/portainer/api/build.GoVersion=${GO_VERSION}'"
|
||||
|
||||
BINARY_VERSION_FILE="../binary-version.json"
|
||||
-X 'github.com/portainer/portainer/pkg/build.BuildNumber=${BUILDNUMBER}' \
|
||||
-X 'github.com/portainer/portainer/pkg/build.ImageTag=${CONTAINER_IMAGE_TAG}' \
|
||||
-X 'github.com/portainer/portainer/pkg/build.NodejsVersion=${NODE_VERSION}' \
|
||||
-X 'github.com/portainer/portainer/pkg/build.YarnVersion=${YARN_VERSION}' \
|
||||
-X 'github.com/portainer/portainer/pkg/build.WebpackVersion=${WEBPACK_VERSION}' \
|
||||
-X 'github.com/portainer/portainer/pkg/build.GitCommit=${GIT_COMMIT_HASH}' \
|
||||
-X 'github.com/portainer/portainer/pkg/build.GoVersion=${GO_VERSION}' \
|
||||
-X 'github.com/portainer/portainer/pkg/build.DepComposeVersion=${COMPOSE_VERSION}' \
|
||||
-X 'github.com/portainer/portainer/pkg/build.DepDockerVersion=${DOCKER_VERSION}' \
|
||||
-X 'github.com/portainer/portainer/pkg/build.DepHelmVersion=${HELM_VERSION}' \
|
||||
-X 'github.com/portainer/portainer/pkg/build.DepKubectlVersion=${KUBECTL_VERSION}'"
|
||||
|
||||
echo "$ldflags"
|
||||
|
||||
|
|
|
@ -0,0 +1,106 @@
|
|||
package build
|
||||
|
||||
import "os"
|
||||
|
||||
/*
|
||||
Package build contains variables that are set at build time using the -X linker flag.
|
||||
|
||||
These variables provide metadata about the build environment and specify the
|
||||
versions of dependencies shipped with the application.
|
||||
|
||||
These variables are typically set during the build process using the -X flag with
|
||||
the go build command, allowing for dynamic injection of build-time information.
|
||||
|
||||
It also contains structs and methods that can be used to display build, dependencies and runtime information.
|
||||
*/
|
||||
|
||||
var (
|
||||
// BuildNumber is the build number of the application.
|
||||
BuildNumber string
|
||||
|
||||
// ImageTag is the Docker image tag associated with this build.
|
||||
ImageTag string
|
||||
|
||||
// NodejsVersion is the version of Node.js used in the build.
|
||||
NodejsVersion string
|
||||
|
||||
// YarnVersion is the version of Yarn used in the build.
|
||||
YarnVersion string
|
||||
|
||||
// WebpackVersion is the version of Webpack used in the build.
|
||||
WebpackVersion string
|
||||
|
||||
// GoVersion is the version of Go used to compile the application.
|
||||
GoVersion string
|
||||
|
||||
// GitCommit is the Git commit hash at the time of the build.
|
||||
GitCommit string
|
||||
|
||||
// DepComposeVersion is the version of the Docker Compose plugin shipped with the application.
|
||||
DepComposeVersion string
|
||||
|
||||
// DepDockerVersion is the version of the Docker binary shipped with the application.
|
||||
DepDockerVersion string
|
||||
|
||||
// DepHelmVersion is the version of the Helm binary shipped with the application.
|
||||
DepHelmVersion string
|
||||
|
||||
// DepKubectlVersion is the version of the Kubectl binary shipped with the application.
|
||||
DepKubectlVersion string
|
||||
)
|
||||
|
||||
type (
|
||||
// BuildInfo contains information about how an application was built
|
||||
BuildInfo struct {
|
||||
BuildNumber string
|
||||
ImageTag string
|
||||
NodejsVersion string
|
||||
YarnVersion string
|
||||
WebpackVersion string
|
||||
GoVersion string
|
||||
GitCommit string
|
||||
}
|
||||
|
||||
// DependenciesInfo contains information about the dependencies of Portainer
|
||||
DependenciesInfo struct {
|
||||
DockerVersion string
|
||||
HelmVersion string
|
||||
KubectlVersion string
|
||||
ComposeVersion string
|
||||
}
|
||||
|
||||
// RuntimeInfo contains information about the runtime environment an application
|
||||
RuntimeInfo struct {
|
||||
Env []string `json:",omitempty"`
|
||||
}
|
||||
)
|
||||
|
||||
// GetBuildInfo is a shortcut method to return the build information
|
||||
func GetBuildInfo() BuildInfo {
|
||||
return BuildInfo{
|
||||
BuildNumber: BuildNumber,
|
||||
ImageTag: ImageTag,
|
||||
NodejsVersion: NodejsVersion,
|
||||
YarnVersion: YarnVersion,
|
||||
WebpackVersion: WebpackVersion,
|
||||
GoVersion: GoVersion,
|
||||
GitCommit: GitCommit,
|
||||
}
|
||||
}
|
||||
|
||||
// GetDependenciesInfo is a shortcut method to return the dependencies information
|
||||
func GetDependenciesInfo() DependenciesInfo {
|
||||
return DependenciesInfo{
|
||||
DockerVersion: DepDockerVersion,
|
||||
HelmVersion: DepHelmVersion,
|
||||
KubectlVersion: DepKubectlVersion,
|
||||
ComposeVersion: DepComposeVersion,
|
||||
}
|
||||
}
|
||||
|
||||
// GetRuntimeInfo is a shortcut method to return the runtime information
|
||||
func GetRuntimeInfo() RuntimeInfo {
|
||||
return RuntimeInfo{
|
||||
Env: os.Environ(),
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue