Skip to content

Commit

Permalink
fixes dockerfile build issues
Browse files Browse the repository at this point in the history
- disables CGO to prevent any dependencies from failing the build
- the GOARCH variable was named incorrectly and not being picked up during the docker build
- locked both the alpine and golang versions for the docker build
  • Loading branch information
Willie Sana committed Nov 14, 2020
1 parent 6b484b1 commit 545692f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
GIT_COMMIT := $(shell git rev-parse --short HEAD 2>/dev/null)
BUILD_FLAGS := -v -ldflags "-w -s"
ENV_SETTINGS := CGO_ENABLED=0

BUILD_DIR = ./bin
BINARY_NAME = terrascan
Expand Down Expand Up @@ -30,7 +31,7 @@ help:
build: clean
@mkdir -p $(BUILD_DIR) > /dev/null
@export GO111MODULE=on
go build ${BUILD_FLAGS} -o ${BUILD_DIR}/${BINARY_NAME} cmd/terrascan/main.go
${ENV_SETTINGS} go build ${BUILD_FLAGS} -o ${BUILD_DIR}/${BINARY_NAME} cmd/terrascan/main.go
@echo "binary created at ${BUILD_DIR}/${BINARY_NAME}"


Expand Down
7 changes: 4 additions & 3 deletions build/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# -------- builder stage -------- #
FROM golang:alpine AS builder
FROM golang:1.15.5-alpine3.12 AS builder

ARG GOOS_VAL=linux
ARG GOARCH=amd64
ARG GOARCH_VAL=amd64
ARG CGO_ENABLED_VAL=0

WORKDIR $GOPATH/src/terrascan

Expand All @@ -14,7 +15,7 @@ RUN go mod download
COPY . .

# build binary
RUN GOOS=${GOOS_VAL} GOARCH=${GOARCH_VAL} go build -v -ldflags "-w -s" -o /go/bin/terrascan ./cmd/terrascan
RUN CGO_ENABLED=${CGO_ENABLED_VAL} GOOS=${GOOS_VAL} GOARCH=${GOARCH_VAL} go build -v -ldflags "-w -s" -o /go/bin/terrascan ./cmd/terrascan


# -------- prod stage -------- #
Expand Down

0 comments on commit 545692f

Please sign in to comment.