Skip to content

Commit

Permalink
Merge pull request #20 from sendgrid/smaller-image
Browse files Browse the repository at this point in the history
Reduce Docker image size #patch
  • Loading branch information
Michael Robinson authored Apr 2, 2019
2 parents 2685828 + 48662f5 commit 6fd0cdd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 23 deletions.
18 changes: 2 additions & 16 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,34 +1,20 @@
ARG GO_VERSION=1.12
ARG GO_VERSION=1.12.1

# The build stage is used for building the aws-env binary and running tests.
FROM golang:${GO_VERSION} AS build

ARG GO_CI_VERSION=v1.15.0

RUN curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh \
| sh -s -- -b /usr/local/bin ${GO_CI_VERSION}

WORKDIR /code

ENV GO111MODULE=on

COPY go.mod go.sum ./

RUN go mod download

COPY . .

ARG GIT_COMMIT=unknown
ARG BUILD_DATE=unknown
ARG VERSION=0.0.1
ARG BUILD_NUMBER=0

RUN make build

# The release (default) stage is a minimal production image suitable for use
# as the base image to applications.
FROM alpine AS release

FROM alpine
COPY --from=build /code/aws-env /usr/local/bin

ENTRYPOINT ["aws-env"]
21 changes: 14 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
GO_VERSION ?= 1.12.1
BINARIES = aws-env
WD ?= $(shell pwd)
NAMESPACE=sendgrid
Expand Down Expand Up @@ -28,7 +29,7 @@ build-docker:
--build-arg BUILD_DATE \
--build-arg VERSION \
--build-arg BUILD_NUMBER \
--target build .
.
@docker tag aws-env docker.sendgrid.net/sendgrid/aws-env

.PHONY: push
Expand All @@ -47,18 +48,19 @@ push-pre-tagged:

.PHONY: artifact
artifact: build-docker
@docker run -v $(WD):/dist --rm aws-env cp /code/aws-env /dist/
@docker run -v $(WD):/dist --rm aws-env cp /usr/local/bin/aws-env /dist/

.PHONY: clean
clean:
@rm -rf $(BINARIES) .image coverage.*

.PHONY: test
test: coverage.txt
coverage.txt: build-docker $(GO_FILES)
coverage.txt: $(GO_FILES)
@docker run --rm \
-v $(WD):/code \
aws-env \
-w /code \
golang:$(GO_VERSION) \
sh -c "\
go test -mod readonly -v -race -coverprofile=coverage.out ./... && \
go tool cover -html=coverage.out -o coverage.html && \
Expand All @@ -79,9 +81,14 @@ else
endif

.PHONY: lint
lint: build-docker
@docker run --rm aws-env \
golangci-lint -v run --enable-all -D gochecknoglobals
lint:
@docker run --rm \
-v $(WD):/code \
-w /code \
golang:$(GO_VERSION) \
sh -c "\
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b /go/bin v1.16.0 && \
golangci-lint -v run --enable-all -D gochecknoglobals"

.PHONY: release
release:
Expand Down

0 comments on commit 6fd0cdd

Please sign in to comment.