From e5a810030009acb2ef4d14df302499e29de7faed Mon Sep 17 00:00:00 2001 From: Paul Hutelmyer Date: Wed, 24 Feb 2021 08:33:21 -0500 Subject: [PATCH] Refactoring dockerfiles --- build/go/fileshot/Dockerfile | 12 +++++++++--- build/go/filestream/Dockerfile | 12 +++++++++--- build/go/frontend/Dockerfile | 13 ++++++++----- build/go/manager/Dockerfile | 13 ++++++++----- build/python/backend/Dockerfile | 2 +- build/python/mmrpc/Dockerfile | 2 +- 6 files changed, 36 insertions(+), 18 deletions(-) diff --git a/build/go/fileshot/Dockerfile b/build/go/fileshot/Dockerfile index 3dfa3167..f7f24683 100644 --- a/build/go/fileshot/Dockerfile +++ b/build/go/fileshot/Dockerfile @@ -1,11 +1,17 @@ FROM golang AS build -LABEL maintainer "Target Brands, Inc. TTS-CFC-OpenSource@target.com" +LABEL maintainer="Target Brands, Inc. TTS-CFC-OpenSource@target.com" +# Copy source files and set the working directory COPY ./src/go/ /go/src/github.com/target/strelka/src/go/ -RUN cd /go/src/github.com/target/strelka/src/go/cmd/strelka-fileshot/ && \ - go get . && \ +WORKDIR /go/src/github.com/target/strelka/src/go/ + +# Initialize, get, and build go modules and main package +RUN go mod init && \ + go mod tidy && \ + cd /go/src/github.com/target/strelka/src/go/cmd/strelka-fileshot/ && \ CGO_ENABLED=0 go build -o /tmp/strelka-fileshot . +# Move build and initialize non-root user FROM alpine COPY --from=build /tmp/strelka-fileshot /usr/local/bin/strelka-fileshot RUN apk add --no-cache jq diff --git a/build/go/filestream/Dockerfile b/build/go/filestream/Dockerfile index e646cb13..d81574ab 100644 --- a/build/go/filestream/Dockerfile +++ b/build/go/filestream/Dockerfile @@ -1,11 +1,17 @@ FROM golang AS build -LABEL maintainer "Target Brands, Inc. TTS-CFC-OpenSource@target.com" +LABEL maintainer="Target Brands, Inc. TTS-CFC-OpenSource@target.com" +# Copy source files and set the working directory COPY ./src/go/ /go/src/github.com/target/strelka/src/go/ -RUN cd /go/src/github.com/target/strelka/src/go/cmd/strelka-filestream/ && \ - go get . && \ +WORKDIR /go/src/github.com/target/strelka/src/go/ + +# Initialize, get, and build go modules and main package +RUN go mod init && \ + go mod tidy && \ + cd /go/src/github.com/target/strelka/src/go/cmd/strelka-filestream/ && \ CGO_ENABLED=0 go build -o /tmp/strelka-filestream . +# Move build, install additional packages, and initialize non-root user FROM alpine COPY --from=build /tmp/strelka-filestream /usr/local/bin/strelka-filestream RUN apk add --no-cache jq diff --git a/build/go/frontend/Dockerfile b/build/go/frontend/Dockerfile index fcb49343..3b376b5b 100644 --- a/build/go/frontend/Dockerfile +++ b/build/go/frontend/Dockerfile @@ -1,14 +1,17 @@ FROM golang AS build -LABEL maintainer "Target Brands, Inc. TTS-CFC-OpenSource@target.com" - -ENV GO111MODULE=on +LABEL maintainer="Target Brands, Inc. TTS-CFC-OpenSource@target.com" +# Copy source files and set the working directory COPY ./src/go/ /go/src/github.com/target/strelka/src/go/ WORKDIR /go/src/github.com/target/strelka/src/go/ -RUN go mod init && cd /go/src/github.com/target/strelka/src/go/cmd/strelka-frontend/ && \ - CGO_ENABLED=0 go build -o /tmp/strelka-frontend . +# Initialize, get, and build go modules and main package +RUN go mod init && \ + go mod tidy && \ + cd /go/src/github.com/target/strelka/src/go/cmd/strelka-frontend/ && \ + CGO_ENABLED=0 go build -o /tmp/strelka-frontend . +# Move build, create default logging directory, and initialize non-root user FROM alpine COPY --from=build /tmp/strelka-frontend /usr/local/bin/strelka-frontend RUN mkdir /var/log/strelka/ && \ diff --git a/build/go/manager/Dockerfile b/build/go/manager/Dockerfile index 6fb12599..93a0c06f 100644 --- a/build/go/manager/Dockerfile +++ b/build/go/manager/Dockerfile @@ -1,14 +1,17 @@ FROM golang AS build -LABEL maintainer "Target Brands, Inc. TTS-CFC-OpenSource@target.com" - -ENV GO111MODULE=on +LABEL maintainer="Target Brands, Inc. TTS-CFC-OpenSource@target.com" +# Copy source files and set the working directory COPY ./src/go/ /go/src/github.com/target/strelka/src/go/ WORKDIR /go/src/github.com/target/strelka/src/go/ -RUN go mod init && cd /go/src/github.com/target/strelka/src/go/cmd/strelka-manager/ && \ - CGO_ENABLED=0 go build -o /tmp/strelka-manager . +# Initialize, get, and build go modules and main package +RUN go mod init && \ + go mod tidy && \ + cd /go/src/github.com/target/strelka/src/go/cmd/strelka-manager/ && \ + CGO_ENABLED=0 go build -o /tmp/strelka-manager . +# Move build and initialize non-root user FROM alpine COPY --from=build /tmp/strelka-manager /usr/local/bin/strelka-manager USER 1001 \ No newline at end of file diff --git a/build/python/backend/Dockerfile b/build/python/backend/Dockerfile index a3140d77..54fec28f 100644 --- a/build/python/backend/Dockerfile +++ b/build/python/backend/Dockerfile @@ -1,6 +1,6 @@ FROM ubuntu:20.04 ARG DEBIAN_FRONTEND=noninteractive -LABEL maintainer "Target Brands, Inc. TTS-CFC-OpenSource@target.com" +LABEL maintainer="Target Brands, Inc. TTS-CFC-OpenSource@target.com" ARG YARA_VERSION=3.11.0 ARG YARA_PYTHON_VERSION=3.11.0 diff --git a/build/python/mmrpc/Dockerfile b/build/python/mmrpc/Dockerfile index 04e1d285..4330cd05 100644 --- a/build/python/mmrpc/Dockerfile +++ b/build/python/mmrpc/Dockerfile @@ -1,6 +1,6 @@ FROM ubuntu:20.04 ARG DEBIAN_FRONTEND=noninteractive -LABEL maintainer "Target Brands, Inc. TTS-CFC-OpenSource@target.com" +LABEL maintainer="Target Brands, Inc. TTS-CFC-OpenSource@target.com" # Copy Strelka files COPY ./src/python/ /strelka/