From f1a8610e27751b81963b09d9cf767e5ccc9691f1 Mon Sep 17 00:00:00 2001 From: Vikram Rangnekar Date: Wed, 27 Mar 2019 00:14:07 -0400 Subject: [PATCH] Optimize docker image --- Dockerfile | 23 ++++++++++++++++++++--- docker-compose.image.yml | 24 ++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 docker-compose.image.yml diff --git a/Dockerfile b/Dockerfile index 1098de6..19081f2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,14 +1,31 @@ -FROM golang:1.12-stretch as builder +FROM golang:1.12-alpine as builder +RUN apk update && \ + apk add --no-cache git && \ + apk add --no-cache upx=3.95-r1 + COPY . /app WORKDIR /app + ENV GO111MODULE=on -RUN CGO_ENABLED=0 GOOS=linux go build -o service +RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" -o service && \ + upx --ultra-brute -qq service && \ + upx -t service + RUN go get github.com/pilu/fresh #second stage FROM alpine:latest WORKDIR /app RUN apk add --no-cache tzdata + COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ -COPY --from=builder /app . +COPY --from=builder /app/service . +COPY web/build /app/web/build/ +COPY dev.yml . + +RUN chmod +x /app/service +USER nobody + +EXPOSE 8080 + CMD ./service diff --git a/docker-compose.image.yml b/docker-compose.image.yml new file mode 100644 index 0000000..cbc420f --- /dev/null +++ b/docker-compose.image.yml @@ -0,0 +1,24 @@ +version: '3.4' +services: + db: + image: postgres + + super_graph: + image: dosco/super-graph:latest + environment: + GO_ENV: "development" + depends_on: + - db + ports: + - "8080:8080" + + web: + build: example/. + command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'" + volumes: + - ./example:/app + ports: + - "3000:3000" + depends_on: + - db + - super_graph \ No newline at end of file