Skip to content

Commit

Permalink
Optimize docker build
Browse files Browse the repository at this point in the history
* Don't copy in any local build to the Docker context
* Copy go.mod/sum in before the rest of the code as per
base image
* Enable license-check to actually run - which was missing

Signed-off-by: Alex Ellis (OpenFaaS Ltd) <[email protected]>
  • Loading branch information
alexellis committed Jun 10, 2020
1 parent e588fbc commit ca674d2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
./inlets-operator
16 changes: 11 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,28 @@ COPY --from=license-check /license-check /usr/bin/
RUN mkdir -p /go/src/github.com/inlets/inlets-operator
WORKDIR /go/src/github.com/inlets/inlets-operator

RUN addgroup --system app && \
adduser --system --ingroup app app && \
mkdir /scratch-tmp

# Cache the download before continuing
COPY go.mod go.mod
COPY go.sum go.sum
RUN go mod download

COPY . .

ARG OPTS
RUN go mod download

RUN gofmt -l -d $(find . -type f -name '*.go' -not -path "./vendor/*")
RUN go test -v ./...
RUN license-check -path ./ --verbose=false "Alex Ellis" "inlets Authors" "inlets Author(s)" \
RUN VERSION=$(git describe --all --exact-match `git rev-parse HEAD` | grep tags | sed 's/tags\///') && \
GIT_COMMIT=$(git rev-list -1 HEAD) && \
env ${OPTS} CGO_ENABLED=0 GOOS=linux go build -ldflags "-s -w \
-X github.com/inlets/inlets-operator/pkg/version.Release=${VERSION} \
-X github.com/inlets/inlets-operator/pkg/version.SHA=${GIT_COMMIT}" \
-a -installsuffix cgo -o inlets-operator . && \
addgroup --system app && \
adduser --system --ingroup app app && \
mkdir /scratch-tmp
-a -installsuffix cgo -o inlets-operator .

# we can't add user in next stage because it's from scratch
# ca-certificates and tmp folder are also missing in scratch
Expand Down
2 changes: 1 addition & 1 deletion controller.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Inlets Author(s) 2019. All rights reserved.
// Copyright (c) inlets Author(s) 2019. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

package main
Expand Down

0 comments on commit ca674d2

Please sign in to comment.