diff --git a/Dockerfile b/Dockerfile index 44e2461f..a524b01c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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"] diff --git a/Makefile b/Makefile index e03e49e9..0e5596e2 100644 --- a/Makefile +++ b/Makefile @@ -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 \ @@ -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 diff --git a/build.sh b/build.sh new file mode 100755 index 00000000..a59969b6 --- /dev/null +++ b/build.sh @@ -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 \ No newline at end of file