From 33c97deac40521f6da574d0e88bbf24ec47e4917 Mon Sep 17 00:00:00 2001 From: yuli Date: Sat, 27 Apr 2024 23:38:18 +0300 Subject: [PATCH] add version information --- .gitignore | 2 ++ BUILD.md | 19 ++++++------------- Dockerfile | 3 ++- build.sh | 29 ++++++++++++++++++++++++++--- release.sh | 11 ----------- src/bunker.go | 10 +++++++++- version.txt | 1 + 7 files changed, 46 insertions(+), 29 deletions(-) delete mode 100755 release.sh create mode 100644 version.txt diff --git a/.gitignore b/.gitignore index 53e3f50..236017c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,9 @@ +src/a_main-packr.go charts/databunker/charts/ terraform.tfstate terraform.tfstate.backup .DS_Store +databunker databunker.db* databunker.yaml bql.db diff --git a/BUILD.md b/BUILD.md index 922f249..9d8a392 100644 --- a/BUILD.md +++ b/BUILD.md @@ -1,28 +1,20 @@ # Building Databunker -## Build for release - -``` -./release.sh -``` - -It will generate **databunker** executable. HTML files are built inside executable. - -## Debug version +Use the folllowing command ``` ./build.sh ``` -It will generate **databunker** executable that can be run on the same box. -Web UI files will be fetched from ui/ directory. +It will generate **databunker** executable. HTML files are built inside executable. ## Build container It will generate "securitybunker/databunker" container and save it locally. ``` -docker build -t securitybunker/databunker:latest . +VERSION=$(cat ./version.txt) +docker build -t securitybunker/databunker:$VERSION --build-arg VERSION=$VERSION . ``` ## Push container @@ -31,7 +23,8 @@ docker build -t securitybunker/databunker:latest . ``` docker login -docker push securitybunker/databunker:latest +VERSION=$(cat ./version.txt) +docker push securitybunker/databunker:$VERSION ``` diff --git a/Dockerfile b/Dockerfile index e908e24..9e7b1ed 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,7 @@ ############################ # STEP 1 build executable binary ############################ +ARG VERSION FROM golang:alpine AS builder RUN apk update && apk add --no-cache git gcc libc-dev openssl && go install github.com/gobuffalo/packr/packr@latest WORKDIR $GOPATH/src/securitybunker/databunker/src/ @@ -12,7 +13,7 @@ COPY . $GOPATH/src/securitybunker/databunker/ # Using go get. RUN go get -d -v && \ packr && \ - go build -o /go/bin/databunker && \ + go build -ldflags="-s -w -X main.version=${VERSION}" -o /go/bin/databunker && \ packr clean ############################ # STEP 2 build a small image diff --git a/build.sh b/build.sh index f923417..6ce162c 100755 --- a/build.sh +++ b/build.sh @@ -1,4 +1,27 @@ -# build without debug +#!/bin/bash + +set -x + +VERSION=$(cat ./version.txt) + +if [[ ! -x "~/go/bin/packr" && ! -x "packr" ]]; then + go install github.com/gobuffalo/packr/packr@latest +fi + cd src -go build -v -o ../databunker -cd .. \ No newline at end of file +go get -d -v +if [ -x "~/go/bin/packr" ]; then + ~/go/bin/packr +elif [ -x "packr" ]; then + packr +fi + +go build -v -ldflags="-s -w -X main.version=${VERSION}" -o ../databunker + +if [ -x "~/go/bin/packr" ]; then + ~/go/bin/packr clean +elif [ -x "packr" ]; then + packr clean +fi + +cd .. diff --git a/release.sh b/release.sh deleted file mode 100755 index 17e1dcc..0000000 --- a/release.sh +++ /dev/null @@ -1,11 +0,0 @@ -# build without debug -packr -go build -ldflags "-w" -o databunker ./src/bunker.go ./src/qldb.go ./src/audit_db.go ./src/audit_api.go \ - ./src/utils.go ./src/cryptor.go \ - ./src/sms.go ./src/email.go \ - ./src/users_db.go ./src/users_api.go \ - ./src/userapps_db.go ./src/userapps_api.go \ - ./src/sessions_db.go ./src/sessions_api.go \ - ./src/consent_db.go ./src/consent_api.go \ - ./src/xtokens_db.go ./src/xtokens_api.go ./src/a_main-packr.go -packr clean \ No newline at end of file diff --git a/src/bunker.go b/src/bunker.go index 30c8dec..a5989ba 100644 --- a/src/bunker.go +++ b/src/bunker.go @@ -33,6 +33,8 @@ import ( yaml "gopkg.in/yaml.v2" ) +var version string + type dbcon struct { store storage.BackendDB masterKey []byte @@ -338,7 +340,7 @@ func readConfFile(cfg *Config, filepath *string) error { confFile = *filepath } } - fmt.Printf("Databunker configuration file is: %s\n", confFile) + fmt.Printf("Databunker configuration file: %s\n", confFile) f, err := os.Open(confFile) if err != nil { return err @@ -580,8 +582,14 @@ func main() { dbPtr := flag.String("db", "databunker", "Specify database name/file") confPtr := flag.String("conf", "", "Configuration file name to use") rootTokenKeyPtr := flag.String("roottoken", "", "Specify custom root token to use during database init. It must be in UUID format.") + versionPtr := flag.Bool("version", false, "Print version information") flag.Parse() + if *versionPtr { + fmt.Printf("Databunker version: %s\n", version) + os.Exit(0) + } + var cfg Config readEnv(&cfg) readConfFile(&cfg, confPtr) diff --git a/version.txt b/version.txt new file mode 100644 index 0000000..100435b --- /dev/null +++ b/version.txt @@ -0,0 +1 @@ +0.8.2