UNCLASSIFIED

Commit 50764617 authored by abrichards's avatar abrichards
Browse files

Merge branch 'dev-build-opt' into 'master'

optimize docker build

See merge request !42
parents a4693d1d 0fdd6264
# More info: https://docs.docker.com/engine/reference/builder/#dockerignore-file
# Ignore all files which are not go type
!**/*.go
!**/*.mod
!**/*.sum
# !**/*.go
# !**/*.mod
# !**/*.sum
testbin
\ No newline at end of file
......@@ -26,4 +26,5 @@ coverage.html
*.swo
*~
.vscode
\ No newline at end of file
.vscode
.gomodcache
......@@ -3,25 +3,21 @@
FROM registry.il2.dso.mil/platform-one/devops/pipeline-templates/valkyrie/golang-builder-1.6:1.0 as builder
WORKDIR /workspace
# set go module cache
ENV GOMODCACHE=/workspace/.gomodcache
# Copy the Go Modules manifests
COPY go.mod go.mod
COPY go.sum go.sum
COPY . .
USER root
RUN chmod 755 go.sum
# cache deps before building and copying source so that we don't need to re-download as much
# and so that source changes don't invalidate our downloaded layer
# download with json logging
# RUN go mod download -json
RUN go mod download
# Copy the go source
COPY main.go main.go
COPY driver.go driver.go
COPY apis/ apis/
COPY config/ config/
COPY controllers/ controllers/
COPY clients/ clients/
# RUN ls -al
# Build
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -o manager main.go driver.go
# make hadolint happy. set user to non root user
USER golanguser
......
# NOTE: USING THIS IMAGE UNTIL registry1 credentials are added to IL2 runners
# Build the manager binary
FROM registry.il2.dso.mil/platform-one/devops/pipeline-templates/valkyrie/golang-builder-1.6:1.0 as builder
WORKDIR /workspace
# Copy the Go Modules manifests
COPY go.mod go.mod
COPY go.sum go.sum
USER root
RUN chmod 755 go.sum
# cache deps before building and copying source so that we don't need to re-download as much
# and so that source changes don't invalidate our downloaded layer
RUN go mod download
# Copy the go source
COPY main.go main.go
COPY driver.go driver.go
COPY apis/ apis/
COPY config/ config/
COPY controllers/ controllers/
COPY clients/ clients/
# Build
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -o manager main.go driver.go
# make hadolint happy. set user to non root user
USER golanguser
# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
FROM registry.il2.dso.mil/platform-one/devops/pipeline-templates/base-image/harden-ubi8-8.4:1.0
WORKDIR /app
COPY --from=builder /workspace/manager .
USER appuser
ENTRYPOINT ["/app/manager"]
## <img src="valkyrie.png" width="60"> Valkyrie Automated CICD Provisioning Tool
## Bump
## Env Variables
- for local building and to closer simulate the pipeline set
- from root folder of project
- export GOMODCACHE=$(pwd)/.gomodcache
### Golang Frameworks
- kubebuilder
- https://book.kubebuilder.io/introduction.html
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment