optimizing dockerfile and updating dependencies

This commit is contained in:
root
2021-10-27 19:13:16 +00:00
parent 716f17d7aa
commit 0fdf52c81f
2 changed files with 39 additions and 46 deletions

View File

@@ -4,31 +4,20 @@
FROM golang:alpine AS builder
# Install git.
# Git is required for fetching the dependencies.
RUN apk update && apk add --no-cache git gcc libc-dev
RUN go get -u github.com/fatih/structs
RUN go get -u github.com/gobuffalo/packr
RUN go get -u github.com/gobuffalo/packr/packr
RUN go get -u github.com/tidwall/gjson
RUN go get -u github.com/ttacon/libphonenumber
RUN go get -u github.com/hashicorp/go-uuid
RUN go get -u go.mongodb.org/mongo-driver/bson
RUN go get -u github.com/mattn/go-sqlite3
RUN go get -u github.com/schollz/sqlite3dump
RUN go get -u github.com/evanphx/json-patch
RUN go get -u github.com/julienschmidt/httprouter
RUN apk update && apk add --no-cache git gcc libc-dev && go get -u github.com/gobuffalo/packr/packr
COPY src/go.mod $GOPATH/src/securitybunker/databunker/src/deps
WORKDIR $GOPATH/src/securitybunker/databunker/src/
RUN cat deps | grep -v storage >> go.mod && go mod download && echo "copy code"
COPY . $GOPATH/src/securitybunker/databunker/
WORKDIR $GOPATH/src/securitybunker/databunker/src/
#RUN echo "update " && go get -u && cat ./go.mod
#RUN echo "tidy " && go mod tidy && cat ./go.mod
# Fetch dependencies.
# Using go get.
RUN go get -d -v
# prepare web to go with packr
RUN packr
# debug
RUN find $GOPATH/src/securitybunker/databunker/
# Build the binary.
RUN go build -o /go/bin/databunker
# clean packr
RUN packr clean
RUN go get -d -v && \
packr && \
go build -o /go/bin/databunker && \
packr clean
############################
# STEP 2 build a small image
############################
@@ -37,24 +26,19 @@ FROM scratch
COPY --from=builder /bin/busybox /bin/busybox
COPY --from=builder /bin/busybox /bin/sh
COPY --from=builder /lib/ld* /lib/
#COPY --from=builder /go/bin/dddatabunker /databunker/bin/databunker
#COPY run.sh /databunker/bin/
#COPY create-test-user.sh /databunker/bin/
COPY databunker.yaml /databunker/conf/
RUN /bin/busybox mkdir -p /databunker/data
RUN /bin/busybox mkdir -p /databunker/certs
#RUN /bin/busybox ln -s /bin/busybox /bin/sh
RUN /bin/busybox ln -s /bin/busybox /bin/addgroup
RUN /bin/busybox ln -s /bin/busybox /bin/adduser
RUN /bin/busybox ln -s /bin/busybox /bin/chown
COPY --from=builder /etc/group /etc/
COPY --from=builder /etc/ssl /etc/ssl
RUN /bin/busybox touch /etc/passwd
RUN /bin/busybox mkdir -p /tmp
RUN /bin/busybox chmod 0777 /tmp
# Create a group and user
RUN addgroup -S appgroup && adduser --no-create-home -S appuser -G appgroup
RUN chown appuser:appgroup /databunker/data
COPY databunker.yaml /databunker/conf/
RUN /bin/busybox mkdir -p /databunker/data && \
/bin/busybox mkdir -p /databunker/certs && \
/bin/busybox ln -s /bin/busybox /bin/addgroup && \
/bin/busybox ln -s /bin/busybox /bin/adduser && \
/bin/busybox ln -s /bin/busybox /bin/chown && \
/bin/busybox touch /etc/passwd && \
/bin/busybox mkdir -p /tmp && \
/bin/busybox chmod 0777 /tmp && \
addgroup -S appgroup && adduser --no-create-home -S appuser -G appgroup && \
chown appuser:appgroup /databunker/data
# Tell docker that all future commands should run as the appuser user
USER appuser
COPY --from=builder /go/bin/databunker /databunker/bin/databunker

View File

@@ -6,25 +6,34 @@ replace github.com/securitybunker/databunker/src/storage => ./storage
require (
github.com/afocus/captcha v0.0.0-20191010092841-4bd1f21c8868
github.com/evanphx/json-patch v4.5.0+incompatible
github.com/fatih/structs v1.1.0
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/evanphx/json-patch v5.6.0+incompatible
github.com/go-sql-driver/mysql v1.6.0 // indirect
github.com/go-stack/stack v1.8.1 // indirect
github.com/gobuffalo/envy v1.9.0 // indirect
github.com/gobuffalo/packd v1.0.0 // indirect
github.com/gobuffalo/packr v1.30.1
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/hashicorp/go-uuid v1.0.2
github.com/joho/godotenv v1.4.0 // indirect
github.com/julienschmidt/httprouter v1.3.0
github.com/kelseyhightower/envconfig v1.4.0
github.com/mattn/go-sqlite3 v2.0.3+incompatible // indirect
github.com/prometheus/client_golang v1.4.1
github.com/prometheus/client_golang v1.11.0
github.com/prometheus/common v0.32.1 // indirect
github.com/prometheus/procfs v0.7.3 // indirect
github.com/qri-io/jsonpointer v0.1.1
github.com/schollz/sqlite3dump v1.2.4 // indirect
github.com/rogpeppe/go-internal v1.8.0 // indirect
github.com/schollz/sqlite3dump v1.3.1 // indirect
github.com/securitybunker/databunker/src/storage v0.0.0
github.com/securitybunker/jsonschema v0.2.1-0.20201128224651-d77c1a3cb787
github.com/tidwall/gjson v1.8.1
github.com/tidwall/gjson v1.10.2
github.com/ttacon/builder v0.0.0-20170518171403-c099f663e1c2 // indirect
github.com/ttacon/libphonenumber v1.2.1
go.mongodb.org/mongo-driver v1.7.1
golang.org/x/image v0.0.0-20210504121937-7319ad40d33e // indirect
golang.org/x/sys v0.0.0-20200219091948-cb0a6d8edb6c
gopkg.in/yaml.v2 v2.2.8
go.mongodb.org/mongo-driver v1.7.3
golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d // indirect
golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359
google.golang.org/protobuf v1.27.1 // indirect
gopkg.in/yaml.v2 v2.4.0
)