Skip to content

Commit

Permalink
New dockerfile that can build by itself
Browse files Browse the repository at this point in the history
Previously, we'd build a glibc Relay locally and then stuff that into a
minimal Docker image and provide that. Now, we do the build of Relay
inside the image build itself. I have confirmed that an executable built
in this Alpine image runs fine in a Debian (i.e., glibc) system.

However, this results in a larger image size right now. Compare the
previous sizes to what is currently built by this commit:

| Image    | Compressed | Uncompressed |
| -------- | ---------- | ------------ |
| Previous | 6 MB       | 19.9 MB      |
| Current  | 30 MB      | 81.6 MB      |

This allows us to easily automate the build with DockerHub, though,
because it doesn't require anything besides the Dockerfile.

See operable/cog#1384 for more.
  • Loading branch information
christophermaier committed Apr 18, 2017
1 parent 726704b commit 8eb92aa
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 15 deletions.
31 changes: 25 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,29 @@
FROM alpine:3.4

MAINTAINER Kevin Smith <[email protected]>
MAINTAINER Christopher Maier <[email protected]>

# Bake in a directory that we can use for logging, config, etc.
RUN mkdir -p /var/operable/relay
ENV GO_PACKAGE_VERSION 1.6.3-r0
ENV GOPATH /gopath
ENV PATH=${GOPATH}/bin:${PATH}

# Relies on the binary having already been built
COPY _build/relay /usr/local/bin
COPY docker/relay.conf /usr/local/etc/relay.conf
WORKDIR /gopath/src/github.com/operable/go-relay
COPY . /gopath/src/github.com/operable/go-relay

RUN apk -U add --virtual .build_deps \
go=$GO_PACKAGE_VERSION \
go-tools=$GO_PACKAGE_VERSION \
git make && \

go get -u github.com/kardianos/govendor && \
make exe && \

mv _build/relay /usr/local/bin && \
mkdir -p /usr/local/etc && \
cp docker/relay.conf /usr/local/etc/relay.conf && \

# Provide a place to dump log files, etc.
mkdir -p /var/operable/relay && \

apk del .build_deps && \
rm -Rf /var/cache/apk/* && \
rm -Rf $GOPATH
12 changes: 3 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ test:
ci-coveralls: tools deps
goveralls -service=travis-ci

# Builds Relay on the current OS
exe: clean-dev | $(BUILD_DIR)
CGO_ENABLED=0 govendor build -ldflags "$(LINK_VARS)" -o $(BUILD_DIR)/$(EXENAME)

docker: export GOOS=linux
docker: export GOARCH=amd64
docker: clean exe do-docker-build
docker:
docker build -t $(DOCKER_IMAGE) .

clean: clean-dev
rm -rf $(BUILD_DIR) relay-test
Expand Down Expand Up @@ -73,9 +73,3 @@ $(TARBALL_NAME): test exe
cp example_relay.conf $(TARBALL_NAME)
tar czf $(TARBALL_NAME).tar.gz $(TARBALL_NAME)
rm -rf $(TARBALL_NAME)

# Providing this solely for CI-built images. We will have already
# built the executable in a separate step. We split things up because
# we build inside a Docker image in CI (we don't have Go on builders).
do-docker-build:
docker build -t $(DOCKER_IMAGE) .

0 comments on commit 8eb92aa

Please sign in to comment.