Skip to content

Commit

Permalink
Merge pull request #35 from johejo/optimize_docker_image_size
Browse files Browse the repository at this point in the history
Optimize docker image size
  • Loading branch information
mattn authored Sep 2, 2020
2 parents 520473e + abd8102 commit b223401
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
34 changes: 21 additions & 13 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,36 @@
name: Go
on: [push]
on: [push, pull_request]
jobs:

build:
name: Build
runs-on: ubuntu-latest
steps:

- name: Set up Go 1.12
uses: actions/setup-go@v1
- name: Set up Go 1.15
uses: actions/setup-go@v2
with:
go-version: 1.12
go-version: 1.15
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v1

- name: Get dependencies
run: |
go get -v -t -d ./...
if [ -f Gopkg.toml ]; then
curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
dep ensure
fi
uses: actions/checkout@v2

- name: Build
run: go build -v .

docker:
name: Docker
runs-on: ubuntu-latest
steps:

- uses: actions/checkout@v2

- name: docker build
run: docker build -t mattn/longcat .

- name: check image size
run: docker images | grep longcat

- name: check run
run: docker run --rm mattn/longcat
7 changes: 5 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ FROM golang:alpine AS build-env
WORKDIR /app
COPY go.mod .
COPY go.sum .
RUN go mod download
RUN apk add --no-cache upx && \
go version && \
go mod download
COPY . .
RUN CGO_ENABLED=0 go build -o /go/bin/longcat
RUN CGO_ENABLED=0 go build -trimpath -ldflags '-w -s' -o /go/bin/longcat && \
upx /go/bin/longcat
FROM scratch
COPY --from=build-env /go/bin/longcat /go/bin/longcat
ENTRYPOINT ["/go/bin/longcat"]

0 comments on commit b223401

Please sign in to comment.