update version generation code

This commit is contained in:
Yuli
2024-04-28 12:16:35 +03:00
parent 65521a3b9f
commit 4a7bb2937d
5 changed files with 19 additions and 40 deletions

View File

@@ -1,9 +1,7 @@
**/.git
databunker.db* databunker.db*
databunker databunker
Dockerfile Dockerfile
./data ./data
.*
*.md *.md
.env .env
data/* data/*

View File

@@ -14,7 +14,7 @@ To generate the ```securitybunker/databunker``` container, use the following com
``` ```
VERSION=$(cat ./version.txt) VERSION=$(cat ./version.txt)
docker build -t securitybunker/databunker:$VERSION --build-arg VERSION=$VERSION . docker build -t securitybunker/databunker:$VERSION .
``` ```
## Pushing Container ## Pushing Container

View File

@@ -1,23 +1,18 @@
############################ ##############################
# STEP 1 build executable binary # STEP 1 build executable file
############################ ##############################
ARG VERSION
FROM golang:alpine AS builder 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 RUN apk update && apk add --no-cache git gcc libc-dev openssl
WORKDIR $GOPATH/src/securitybunker/databunker/src/ WORKDIR /go/src/securitybunker/databunker/src/
COPY src/go.mod ./deps COPY src/go.mod ./deps
RUN cat ./deps | grep -v storage > ./go.mod && go mod download RUN cat ./deps | grep -v storage > ./go.mod && go mod download
COPY . $GOPATH/src/securitybunker/databunker/ COPY . /go/src/securitybunker/databunker/
WORKDIR /go/src/securitybunker/databunker/
#RUN echo "tidy " && go get -u && go mod tidy && cat ./go.mod #RUN echo "tidy " && go get -u && go mod tidy && cat ./go.mod
# Fetch dependencies. RUN ./build.sh
# Using go get. #################################
RUN go get -d -v && \ # STEP 2 create a small container
packr && \ #################################
go build -ldflags="-s -w -X main.version=${VERSION}" -o /go/bin/databunker && \
packr clean
############################
# STEP 2 build a small image
############################
FROM scratch FROM scratch
COPY --from=builder /bin/sh /bin/busybox /usr/bin/openssl /bin/ COPY --from=builder /bin/sh /bin/busybox /usr/bin/openssl /bin/
COPY --from=builder /lib/ld* /lib/libssl.* /lib/libcrypto.* /lib/ COPY --from=builder /lib/ld* /lib/libssl.* /lib/libcrypto.* /lib/
@@ -36,7 +31,7 @@ RUN /bin/busybox mkdir -p /databunker/data && \
addgroup -S appgroup && adduser --no-create-home -S appuser -G appgroup && \ addgroup -S appgroup && adduser --no-create-home -S appuser -G appgroup && \
chown appuser:appgroup /databunker/data chown appuser:appgroup /databunker/data
USER appuser USER appuser
COPY --from=builder /go/bin/databunker /go/src/securitybunker/databunker/run.sh /go/src/securitybunker/databunker/health-check.sh /databunker/bin/ COPY --from=builder /go/src/securitybunker/databunker/databunker /go/src/securitybunker/databunker/run.sh /go/src/securitybunker/databunker/health-check.sh /databunker/bin/
EXPOSE 3000 EXPOSE 3000
HEALTHCHECK --interval=5s --timeout=3s --start-period=33s --retries=3 CMD /databunker/bin/health-check.sh HEALTHCHECK --interval=5s --timeout=3s --start-period=33s --retries=3 CMD /databunker/bin/health-check.sh
ENTRYPOINT ["/bin/sh", "/databunker/bin/run.sh"] ENTRYPOINT ["/bin/sh", "/databunker/bin/run.sh"]

View File

@@ -1,27 +1,13 @@
#!/bin/bash #!/bin/sh
set -x set -x
VERSION=$(cat ./version.txt) VERSION=$(cat ./version.txt)
HASH=$(git rev-parse --short=12 HEAD)
if [[ ! -x "~/go/bin/packr" && ! -x "packr" ]]; then TIMESTAMP=$(date +%Y%m%d%H%M%S) # Current timestamp
go install github.com/gobuffalo/packr/packr@latest FULL_VERSION=$VERSION-$TIMESTAMP-$HASH
fi
cd src cd src
go get -d -v go get -d -v
if [ -x "~/go/bin/packr" ]; then go build -v -ldflags="-s -w -X main.version=$FULL_VERSION" -o ../databunker
~/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 .. cd ..

View File

@@ -1,7 +1,7 @@
#!/bin/sh #!/bin/sh
VERSION=$(cat ./version.txt) VERSION=$(cat ./version.txt)
docker build -t securitybunker/databunker:$VERSION --build-arg VERSION=$VERSION . docker build -t securitybunker/databunker:$VERSION .
docker tag securitybunker/databunker:$VERSION securitybunker/databunker:latest docker tag securitybunker/databunker:$VERSION securitybunker/databunker:latest
docker-compose -f docker-compose-pgsql.yml down || true docker-compose -f docker-compose-pgsql.yml down || true
docker-compose -f docker-compose-pgsql.yml up -d docker-compose -f docker-compose-pgsql.yml up -d