Skip to content

Commit

Permalink
update version generation code
Browse files Browse the repository at this point in the history
  • Loading branch information
stremovsky committed Apr 28, 2024
1 parent 65521a3 commit 4a7bb29
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 40 deletions.
2 changes: 0 additions & 2 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
**/.git
databunker.db*
databunker
Dockerfile
./data
.*
*.md
.env
data/*
Expand Down
2 changes: 1 addition & 1 deletion BUILD.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ To generate the ```securitybunker/databunker``` container, use the following com

```
VERSION=$(cat ./version.txt)
docker build -t securitybunker/databunker:$VERSION --build-arg VERSION=$VERSION .
docker build -t securitybunker/databunker:$VERSION .
```

## Pushing Container
Expand Down
29 changes: 12 additions & 17 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
############################
# STEP 1 build executable binary
############################
ARG VERSION
##############################
# STEP 1 build executable file
##############################
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/
RUN apk update && apk add --no-cache git gcc libc-dev openssl
WORKDIR /go/src/securitybunker/databunker/src/
COPY src/go.mod ./deps
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
# Fetch dependencies.
# Using go get.
RUN go get -d -v && \
packr && \
go build -ldflags="-s -w -X main.version=${VERSION}" -o /go/bin/databunker && \
packr clean
############################
# STEP 2 build a small image
############################
RUN ./build.sh
#################################
# STEP 2 create a small container
#################################
FROM scratch
COPY --from=builder /bin/sh /bin/busybox /usr/bin/openssl /bin/
COPY --from=builder /lib/ld* /lib/libssl.* /lib/libcrypto.* /lib/
Expand All @@ -36,7 +31,7 @@ RUN /bin/busybox mkdir -p /databunker/data && \
addgroup -S appgroup && adduser --no-create-home -S appuser -G appgroup && \
chown appuser:appgroup /databunker/data
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
HEALTHCHECK --interval=5s --timeout=3s --start-period=33s --retries=3 CMD /databunker/bin/health-check.sh
ENTRYPOINT ["/bin/sh", "/databunker/bin/run.sh"]
Expand Down
24 changes: 5 additions & 19 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,27 +1,13 @@
#!/bin/bash
#!/bin/sh

set -x

VERSION=$(cat ./version.txt)

if [[ ! -x "~/go/bin/packr" && ! -x "packr" ]]; then
go install github.com/gobuffalo/packr/packr@latest
fi
HASH=$(git rev-parse --short=12 HEAD)
TIMESTAMP=$(date +%Y%m%d%H%M%S) # Current timestamp
FULL_VERSION=$VERSION-$TIMESTAMP-$HASH

cd src
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

go build -v -ldflags="-s -w -X main.version=$FULL_VERSION" -o ../databunker
cd ..
2 changes: 1 addition & 1 deletion start-docker.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/sh

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-compose -f docker-compose-pgsql.yml down || true
docker-compose -f docker-compose-pgsql.yml up -d

0 comments on commit 4a7bb29

Please sign in to comment.