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