Skip to content

Commit

Permalink
Simplify how the docker image is built by using one docker file, so t…
Browse files Browse the repository at this point in the history
…hat the image can be built on Heroku as well #122
  • Loading branch information
danpersa committed Dec 4, 2018
1 parent 49acb14 commit 538a841
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 41 deletions.
21 changes: 20 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,27 @@
# build stage
FROM golang:1.11.1-alpine AS build-env

ENV GOPATH /go
ENV GOOS linux

RUN apk add --update git bash

ADD packaging/install-vips.sh install-vips.sh
RUN ./install-vips.sh

ADD . /go/src/github.com/zalando-stups/skrop
WORKDIR /go/src/github.com/zalando-stups/skrop

RUN go get github.com/Masterminds/glide

RUN go build ./cmd/skrop

# final stage
FROM danpersa/alpine-mozjpeg-vips:3.3.1-8.7.0

ARG ROUTES_FILE

ADD skrop /usr/local/bin/
COPY --from=0 /go/src/github.com/zalando-stups/skrop/skrop /usr/local/bin/
ADD $ROUTES_FILE skrop.eskip

ENTRYPOINT skrop -routes-file skrop.eskip ${SKROP_ARGS}
8 changes: 0 additions & 8 deletions packaging/Dockerfile

This file was deleted.

32 changes: 0 additions & 32 deletions packaging/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,45 +6,13 @@ readonly DOCKER_IMAGE_NAME=${3-"zalando-stups/skrop"}

readonly GO_PROJECT_NAME="github.com/zalando-stups/skrop"

function make_build_image() {
docker build -t "$DOCKER_IMAGE_NAME-build" packaging/ \
&& return 0
}

function make_binary() {
docker run --rm \
-v ${PWD}:/go/src/${GO_PROJECT_NAME} \
-e "GOPATH=/go" \
-e "GOOS=linux" \
-w /go/src/${GO_PROJECT_NAME} \
"$DOCKER_IMAGE_NAME-build" sh \
-c 'go build ./cmd/skrop' \
&& return 0
}

function make_production_image() {
docker build \
--build-arg ROUTES_FILE=${ROUTES_FILE} \
-t ${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_VERSION} . \
&& return 0
}

echo >&2 "Building build Docker image…"

make_build_image
if [ "$?" -ne 0 ]; then
echo >&2 "Aborting!"
exit 1
fi

echo >&2 "Building binary…"

make_binary
if [ "$?" -ne 0 ]; then
echo >&2 "Aborting!"
exit 1
fi

echo >&2 "Building Docker image…"

make_production_image
Expand Down

0 comments on commit 538a841

Please sign in to comment.