Skip to content

Commit

Permalink
add support for multi-arch build
Browse files Browse the repository at this point in the history
  • Loading branch information
oilbeater committed Apr 10, 2020
1 parent 6176b00 commit f8d6fd5
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 46 deletions.
23 changes: 12 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ GO_VERSION=1.13
REGISTRY=index.alauda.cn/alaudak8s
DEV_TAG=dev
RELEASE_TAG=$(shell cat VERSION)
OVS_TAG=200403

# ARCH could be amd64,arm64
ARCH=amd64
# RPM_ARCH could be x86_64,aarch64
RPM_ARCH=x86_64

.PHONY: build-dev-images build-go build-bin lint up down halt suspend resume kind-init kind-init-ha kind-reload push-dev push-release e2e ut

Expand All @@ -15,17 +19,14 @@ push-dev:
docker push ${REGISTRY}/kube-ovn:${DEV_TAG}

build-go:
CGO_ENABLED=0 GOOS=linux go build -o $(PWD)/dist/images/kube-ovn -ldflags "-w -s" -v ./cmd/cni
CGO_ENABLED=0 GOOS=linux go build -o $(PWD)/dist/images/kube-ovn-controller -ldflags "-w -s" -v ./cmd/controller
CGO_ENABLED=0 GOOS=linux go build -o $(PWD)/dist/images/kube-ovn-daemon -ldflags "-w -s" -v ./cmd/daemon
CGO_ENABLED=0 GOOS=linux go build -o $(PWD)/dist/images/kube-ovn-webhook -ldflags "-w -s" -v ./cmd/webhook
CGO_ENABLED=0 GOOS=linux go build -o $(PWD)/dist/images/kube-ovn-pinger -ldflags "-w -s" -v ./cmd/pinger

ovs:
docker build -t ovs:${OVS_TAG} -f dist/ovs/Dockerfile dist/ovs/
CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} go build -o $(PWD)/dist/images/kube-ovn -ldflags "-w -s" -v ./cmd/cni
CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} go build -o $(PWD)/dist/images/kube-ovn-controller -ldflags "-w -s" -v ./cmd/controller
CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} go build -o $(PWD)/dist/images/kube-ovn-daemon -ldflags "-w -s" -v ./cmd/daemon
CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} go build -o $(PWD)/dist/images/kube-ovn-pinger -ldflags "-w -s" -v ./cmd/pinger
CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} go build -o $(PWD)/dist/images/kube-ovn-webhook -ldflags "-w -s" -v ./cmd/webhook

release: lint build-go
docker build -t ${REGISTRY}/kube-ovn:${RELEASE_TAG} -f dist/images/Dockerfile dist/images/
docker buildx build --platform linux/${ARCH} --build-arg ARCH=${ARCH} --build-arg RPM_ARCH=${RPM_ARCH} -t ${REGISTRY}/kube-ovn:${RELEASE_TAG} -o type=docker -f dist/images/Dockerfile dist/images/

push-release:
docker push ${REGISTRY}/kube-ovn:${RELEASE_TAG}
Expand All @@ -36,7 +37,7 @@ lint:
@GOOS=linux go vet ./...

build-bin:
docker run --rm -e GOOS=linux -e GOCACHE=/tmp \
docker run --rm -e GOOS=linux -e GOCACHE=/tmp -e GOARCH=${ARCH} -e GOPROXY=https://goproxy.cn \
-u $(shell id -u):$(shell id -g) \
-v $(CURDIR):/go/src/github.com/alauda/kube-ovn:ro \
-v $(CURDIR)/dist:/go/src/github.com/alauda/kube-ovn/dist/ \
Expand Down
38 changes: 35 additions & 3 deletions dist/images/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,49 @@
FROM ovs:200403
# syntax = docker/dockerfile:experimental
FROM centos:8 as ovs-rpm

RUN yum install dnf-plugins-core -y && \
yum config-manager --set-enabled PowerTools && \
yum install python36 git wget openssl-devel gcc \
make python3-devel openssl-devel kernel-devel kernel-debug-devel \
autoconf automake rpm-build redhat-rpm-config libtool libcap-ng-devel \
checkpolicy selinux-policy-devel unbound unbound-devel gcc-c++ \
desktop-file-utils graphviz groff python3-sphinx -y
COPY build.sh /root/build.sh
RUN bash /root/build.sh
ARG RPM_ARCH
RUN mkdir /rpms/ && \
cp /ovs/rpm/rpmbuild/RPMS/${RPM_ARCH}/* /ovn/rpm/rpmbuild/RPMS/${RPM_ARCH}/* /rpms && \
cd /rpms && rm -f *debug* *docker* *vtep* *ipsec*


FROM centos:8

RUN yum install -y \
bind-utils \
firewalld-filesystem \
libpcap \
hostname ethtool \
iproute nc \
unbound unbound-devel \
tcpdump ipset && yum clean all
ARG RPM_ARCH
RUN rpm -ivh --nodeps https://download-ib01.fedoraproject.org/pub/fedora/linux/releases/30/Everything/${RPM_ARCH}/os/Packages/i/iptables-1.8.0-5.fc30.${RPM_ARCH}.rpm

RUN mkdir -p /var/run/openvswitch && \
mkdir -p /var/run/ovn && \
mkdir -p /etc/cni/net.d && \
mkdir -p /opt/cni/bin

ARG ARCH
ENV CNI_VERSION=v0.7.5
RUN curl -sSf -L --retry 5 https://github.com/containernetworking/plugins/releases/download/${CNI_VERSION}/cni-plugins-amd64-${CNI_VERSION}.tgz | tar -xz -C . ./loopback ./portmap
RUN curl -sSf -L --retry 5 https://github.com/containernetworking/plugins/releases/download/${CNI_VERSION}/cni-plugins-${ARCH}-${CNI_VERSION}.tgz | tar -xz -C . ./loopback ./portmap

ENV KUBE_VERSION="v1.13.2"
RUN curl -L https://storage.googleapis.com/kubernetes-release/release/${KUBE_VERSION}/bin/linux/amd64/kubectl -o /usr/bin/kubectl \
RUN curl -L https://storage.googleapis.com/kubernetes-release/release/${KUBE_VERSION}/bin/linux/${ARCH}/kubectl -o /usr/bin/kubectl \
&& chmod +x /usr/bin/kubectl

RUN --mount=type=bind,target=/rpms,from=ovs-rpm,source=/rpms rpm -ivh --nodeps /rpms/*.rpm

COPY *.sh /kube-ovn/
COPY 01-kube-ovn.conflist /kube-ovn/01-kube-ovn.conflist

Expand Down
4 changes: 2 additions & 2 deletions dist/ovs/build.sh → dist/images/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ curl https://github.com/alauda/ovs/commit/238003290766808ba310e1875157b3d4142456
sed -i 's/2.13.1/2.13.0/g' configure.ac
sed -i 's/sphinx-build-3/sphinx-build/g' rhel/openvswitch-fedora.spec.in
./boot.sh
./configure LIBS=-ljemalloc CFLAGS="-O2 -g -msse4.2 -mpopcnt"
./configure LIBS=-ljemalloc
make rpm-fedora
cd ..

Expand All @@ -26,5 +26,5 @@ cd ovn
curl https://github.com/alauda/ovn/commit/19e802b80c866089af8f7a21512f68decc75a874.patch | git apply
sed -i 's/20.03.1/20.03.0/g' configure.ac
./boot.sh
./configure LIBS=-ljemalloc CFLAGS="-O2 -g -msse4.2 -mpopcnt" --with-ovs-source=/ovs
./configure LIBS=-ljemalloc --with-ovs-source=/ovs
make rpm-fedora
30 changes: 0 additions & 30 deletions dist/ovs/Dockerfile

This file was deleted.

0 comments on commit f8d6fd5

Please sign in to comment.