diff --git a/.dockerignore b/.dockerignore index 46a82cbc..1c6f5cf8 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,9 +1,7 @@ -**/.git databunker.db* databunker Dockerfile ./data -.* *.md .env data/* diff --git a/BUILD.md b/BUILD.md index a5e9be07..77cc94cc 100644 --- a/BUILD.md +++ b/BUILD.md @@ -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 diff --git a/Dockerfile b/Dockerfile index 9e7b1ed7..34f2fb7c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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/ @@ -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"] diff --git a/build.sh b/build.sh index 6ce162cd..abf24456 100755 --- a/build.sh +++ b/build.sh @@ -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 .. diff --git a/start-docker.sh b/start-docker.sh index d6c664a6..f7aa1044 100755 --- a/start-docker.sh +++ b/start-docker.sh @@ -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