Skip to content

Commit

Permalink
Build the binary in the deployment container
Browse files Browse the repository at this point in the history
This allows us to the whole build as a single step on DockerHub
  • Loading branch information
tomdee authored and caseydavenport committed Mar 23, 2016
1 parent f11237b commit 7501e90
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 15 deletions.
18 changes: 15 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@
# See the License for the specific language governing permissions and
# limitations under the License.

FROM jeanblanchard/alpine-glibc
COPY ./dist/ /sbin/
CMD ["/sbin/policy_agent"]
FROM alpine:3.3

ADD *.py /code/
ADD handlers /code/handlers

ADD build.sh /build.sh
RUN /build.sh

# Symlinks needed to workaround Alpine/Pyinstaller incompatibilties
# https://github.com/gliderlabs/docker-alpine/issues/48
RUN ln -s /lib/libc.musl-x86_64.so.1 ldd
RUN ln -s /lib /lib64
RUN ln -s /lib/ld-musl-x86_64.so.1 /lib64/ld-linux-x86-64.so.2

CMD ["/dist/policy_agent"]
14 changes: 2 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,13 @@ SRCDIR=.
default: all
all: policy-agent policy-tool

# Build the policy agent binary.
policy-agent: dist/policy_agent

# Build the policy command line tool.
policy-tool: dist/policy

# Build the calico/k8s-policy-agent Docker container.
docker-image: image.created

dist/policy_agent:
# Build the kubernetes policy agent
docker run --rm \
-v `pwd`:/code \
calico/build \
pyinstaller policy_agent.py -ayF

dist/policy: $(shell find policy_tool)
dist/policy: $(shell find policy_tool)
# Build NetworkPolicy install tool.
docker run --rm \
-v `pwd`:/code \
Expand All @@ -34,7 +24,7 @@ ut:
calico/test \
nosetests tests/unit -c nose.cfg

image.created: dist/policy_agent
image.created:
# Build the docker image for the policy agent.
docker build -t calico/k8s-policy-agent .
touch image.created
Expand Down
17 changes: 17 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/sh
set -e
set -x

# Install the system packages needed for building the PyInstaller based binary
apk -U add --virtual temp python-dev py-pip alpine-sdk python py-setuptools

# Install python dependencies
pip install -r https://raw.githubusercontent.com/projectcalico/libcalico/master/build-requirements.txt
pip install git+https://github.com/projectcalico/libcalico.git

# Produce a binary - outputs to /dist/policy_agent
pyinstaller /code/policy_agent.py -ayF

# Cleanup everything that was installed now that we have a self contained binary
apk del temp && rm -rf /var/cache/apk/*
rm -rf /usr/lib/python2.7

0 comments on commit 7501e90

Please sign in to comment.