Skip to content

Commit 6cdaff6

Browse files
tomdeecaseydavenport
authored andcommitted
Build the binary in the deployment container
This allows us to the whole build as a single step on DockerHub
1 parent 00c2f0c commit 6cdaff6

File tree

3 files changed

+34
-15
lines changed

3 files changed

+34
-15
lines changed

Dockerfile

+15-3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,18 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
FROM jeanblanchard/alpine-glibc
16-
COPY ./dist/ /sbin/
17-
CMD ["/sbin/policy_agent"]
15+
FROM alpine:3.3
16+
17+
ADD *.py /code/
18+
ADD handlers /code/handlers
19+
20+
ADD build.sh /build.sh
21+
RUN /build.sh
22+
23+
# Symlinks needed to workaround Alpine/Pyinstaller incompatibilties
24+
# https://github.com/gliderlabs/docker-alpine/issues/48
25+
RUN ln -s /lib/libc.musl-x86_64.so.1 ldd
26+
RUN ln -s /lib /lib64
27+
RUN ln -s /lib/ld-musl-x86_64.so.1 /lib64/ld-linux-x86-64.so.2
28+
29+
CMD ["/dist/policy_agent"]

Makefile

+2-12
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,13 @@ SRCDIR=.
55
default: all
66
all: policy-agent policy-tool
77

8-
# Build the policy agent binary.
9-
policy-agent: dist/policy_agent
10-
118
# Build the policy command line tool.
129
policy-tool: dist/policy
1310

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

17-
dist/policy_agent:
18-
# Build the kubernetes policy agent
19-
docker run --rm \
20-
-v `pwd`:/code \
21-
calico/build \
22-
pyinstaller policy_agent.py -ayF
23-
24-
dist/policy: $(shell find policy_tool)
14+
dist/policy: $(shell find policy_tool)
2515
# Build NetworkPolicy install tool.
2616
docker run --rm \
2717
-v `pwd`:/code \
@@ -34,7 +24,7 @@ ut:
3424
calico/test \
3525
nosetests tests/unit -c nose.cfg
3626

37-
image.created: dist/policy_agent
27+
image.created:
3828
# Build the docker image for the policy agent.
3929
docker build -t calico/k8s-policy-agent .
4030
touch image.created

build.sh

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/sh
2+
set -e
3+
set -x
4+
5+
# Install the system packages needed for building the PyInstaller based binary
6+
apk -U add --virtual temp python-dev py-pip alpine-sdk python py-setuptools
7+
8+
# Install python dependencies
9+
pip install -r https://raw.githubusercontent.com/projectcalico/libcalico/master/build-requirements.txt
10+
pip install git+https://github.com/projectcalico/libcalico.git
11+
12+
# Produce a binary - outputs to /dist/policy_agent
13+
pyinstaller /code/policy_agent.py -ayF
14+
15+
# Cleanup everything that was installed now that we have a self contained binary
16+
apk del temp && rm -rf /var/cache/apk/*
17+
rm -rf /usr/lib/python2.7

0 commit comments

Comments
 (0)