From 6c97a670c651c5943ea6934cf24bb737b712dfcd Mon Sep 17 00:00:00 2001 From: Victor Lacasse-Beaudoin Date: Mon, 13 Nov 2023 16:49:20 -0500 Subject: [PATCH] Ajouter version subcommand MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Affiche la version de l'exécutable tel que défini at build time. Autres changements: - [DOCKERFILE] Ajouter `ARG agecem_org_version` - [FEATURE] Ajouter package version/ - [DOCKERFILE] `ADD version/` - [DOCKERFILE] Retirer installsuffix de build step - [DOCKERFILE] Utiliser `agecem_org_version` pour remplir version.version dans l'exécutabe - [DOCKERFILE] Nommer deuxième stage `run` - [DOCKER-COMPOSE] Standardiser valeurs --- Dockerfile | 12 +++++++----- cmd/version.go | 21 +++++++++++++++++++++ docker-compose.yaml | 10 +++++----- version/version.go | 19 +++++++++++++++++++ 4 files changed, 52 insertions(+), 10 deletions(-) create mode 100644 cmd/version.go create mode 100644 version/version.go diff --git a/Dockerfile b/Dockerfile index 73284c7..0bd3c53 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,6 @@ -FROM golang:1.21.1 as build +FROM golang:1.21.1 AS build + +ARG agecem_org_version LABEL author="Victor Lacasse-Beaudoin " @@ -24,17 +26,17 @@ ADD models/ models/ ADD templates/ templates/ +ADD version/ version/ + ADD web_handlers/ web_handlers/ Add webresponse/ webresponse/ -RUN CGO_ENABLED=0 go build -a -installsuffix cgo -o agecem-org . +RUN CGO_ENABLED=0 go build -a -o agecem-org -ldflags="-X 'git.agecem.com/agecem/agecem-org/version.version=$agecem_org_version'" . # Alpine -FROM alpine:3.18.3 - -WORKDIR /app +FROM alpine:3.18.3 AS run COPY --from=build /go/src/app/agecem-org /usr/bin/agecem-org diff --git a/cmd/version.go b/cmd/version.go new file mode 100644 index 0000000..e2b73c2 --- /dev/null +++ b/cmd/version.go @@ -0,0 +1,21 @@ +package cmd + +import ( + "fmt" + + "git.agecem.com/agecem/agecem-org/version" + "github.com/spf13/cobra" +) + +// versionCmd represents the version command +var versionCmd = &cobra.Command{ + Use: "version", + Short: "Print version registered at build time", + Run: func(cmd *cobra.Command, args []string) { + fmt.Println("agecem-org", version.Version()) + }, +} + +func init() { + rootCmd.AddCommand(versionCmd) +} diff --git a/docker-compose.yaml b/docker-compose.yaml index b463bb1..fb05494 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -1,19 +1,19 @@ services: minio: image: 'quay.io/minio/minio:latest' - restart: unless-stopped + restart: 'unless-stopped' environment: - - "MINIO_ROOT_USER=${MINIO_ROOT_USER}" - - "MINIO_ROOT_PASSWORD=${MINIO_ROOT_PASSWORD}" + MINIO_ROOT_USER: "${MINIO_ROOT_USER}" + MINIO_ROOT_PASSWORD: "${MINIO_ROOT_PASSWORD}" volumes: - 'minio-data:/data' command: 'server /data --console-address ":9001"' server: depends_on: - 'minio' - restart: unless-stopped + restart: 'unless-stopped' build: . - image: git.agecem.com/agecem/agecem-org:latest + image: 'git.agecem.com/agecem/agecem-org:latest' ports: - '8080:8080' volumes: diff --git a/version/version.go b/version/version.go new file mode 100644 index 0000000..bea4c89 --- /dev/null +++ b/version/version.go @@ -0,0 +1,19 @@ +package version + +// Filled by build flag +var version string + +/* +Version returns the application version + +Example command to use the output of `git describe` for version number at build time: + + $ go build -ldflags="-X 'git.agecem.com/agecem/agecem-org/version.version=`git describe`'" . +*/ +func Version() string { + if version == "" { + return "version unknown" + } + + return version +} -- 2.45.2