Ajouter version subcommand

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
This commit is contained in:
Victor Lacasse-Beaudoin 2023-11-13 16:49:20 -05:00
parent 1c558687b4
commit 6c97a670c6
4 changed files with 52 additions and 10 deletions

View file

@ -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 <vlbeaudoin@agecem.org>" LABEL author="Victor Lacasse-Beaudoin <vlbeaudoin@agecem.org>"
@ -24,17 +26,17 @@ ADD models/ models/
ADD templates/ templates/ ADD templates/ templates/
ADD version/ version/
ADD web_handlers/ web_handlers/ ADD web_handlers/ web_handlers/
Add webresponse/ webresponse/ 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 # Alpine
FROM alpine:3.18.3 FROM alpine:3.18.3 AS run
WORKDIR /app
COPY --from=build /go/src/app/agecem-org /usr/bin/agecem-org COPY --from=build /go/src/app/agecem-org /usr/bin/agecem-org

21
cmd/version.go Normal file
View file

@ -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)
}

View file

@ -1,19 +1,19 @@
services: services:
minio: minio:
image: 'quay.io/minio/minio:latest' image: 'quay.io/minio/minio:latest'
restart: unless-stopped restart: 'unless-stopped'
environment: environment:
- "MINIO_ROOT_USER=${MINIO_ROOT_USER}" MINIO_ROOT_USER: "${MINIO_ROOT_USER}"
- "MINIO_ROOT_PASSWORD=${MINIO_ROOT_PASSWORD}" MINIO_ROOT_PASSWORD: "${MINIO_ROOT_PASSWORD}"
volumes: volumes:
- 'minio-data:/data' - 'minio-data:/data'
command: 'server /data --console-address ":9001"' command: 'server /data --console-address ":9001"'
server: server:
depends_on: depends_on:
- 'minio' - 'minio'
restart: unless-stopped restart: 'unless-stopped'
build: . build: .
image: git.agecem.com/agecem/agecem-org:latest image: 'git.agecem.com/agecem/agecem-org:latest'
ports: ports:
- '8080:8080' - '8080:8080'
volumes: volumes:

19
version/version.go Normal file
View file

@ -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
}