From 7d97044b7190546c3d8ee50d57d4e2f092ec37fb Mon Sep 17 00:00:00 2001 From: Otavio Tomasevic Date: Sat, 18 Aug 2018 03:59:18 -0300 Subject: [PATCH] N2N Builder adjustments for local repository --- .dockerignore | 1 + Makefile | 48 ++++++++++++--------- README.md | 2 +- image-platforms/Dockerfile.arm32v7 | 22 +++++----- image-platforms/Dockerfile.x86_64 | 22 +++++----- image-platforms/common/dependencies.pkglist | 6 +++ image-platforms/common/prepare-build.sh | 8 ++++ 7 files changed, 66 insertions(+), 43 deletions(-) create mode 100644 .dockerignore create mode 100644 image-platforms/common/dependencies.pkglist create mode 100644 image-platforms/common/prepare-build.sh diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..c795b05 --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +build \ No newline at end of file diff --git a/Makefile b/Makefile index 2e98fd9..7aa7429 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ N2N_VERSION=2.3.0 -N2N_OSNAME=$(shell uname -p) +N2N_OSNAME=$(shell uname) ######## @@ -106,13 +106,15 @@ install: edge supernode edge.8.gz supernode.1.gz n2n.7.gz $(INSTALL_DOC) n2n.7.gz $(MAN7DIR)/ # Docker builder section -DOCKER_IMAGE_NAME=ntop/supernode -DOCKER_IMAGE_VERSION=$N2N_VERSION -N2N_COMMIT_HASH=21055550f3392235a1b41d71257e9dc9ead0dfa0 +DOCKER_IMAGE_NAME=supermock/supernode +DOCKER_IMAGE_VERSION=v$(N2N_VERSION) -default: steps +pre_platforms: + if [ ! "$(N2N_COMMIT_HASH)" = "" ]; then \ + echo -n "Are you sure you want to build the hash commit, with the version 2.3 tag, if it is not right, change the N2N_VERSION environment variable in the Makefile. (y/n) " && read sure && [ $$sure == y ]; \ + fi -steps: +platforms: pre_platforms if [ "$(TARGET_ARCHITECTURE)" = "arm32v7" ] || [ "$(TARGET_ARCHITECTURE)" = "" ]; then DOCKER_IMAGE_FILENAME="Dockerfile.arm32v7" DOCKER_IMAGE_TAGNAME=$(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_VERSION)-arm32v7 make build; fi if [ "$(TARGET_ARCHITECTURE)" = "x86_64" ] || [ "$(TARGET_ARCHITECTURE)" = "" ]; then DOCKER_IMAGE_FILENAME="Dockerfile.x86_64" DOCKER_IMAGE_TAGNAME=$(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_VERSION)-x86_64 make build; fi @@ -122,22 +124,28 @@ build: docker build --target builder --build-arg COMMIT_HASH=$(N2N_COMMIT_HASH) -t $(DOCKER_IMAGE_TAGNAME) -f image-platforms/$(DOCKER_IMAGE_FILENAME) . - docker container create --name builder $(DOCKER_IMAGE_TAGNAME) + docker container create --name n2n-builder $(DOCKER_IMAGE_TAGNAME) if [ ! -d "./build" ]; then mkdir ./build; fi - docker container cp builder:/usr/src/n2n/supernode ./build/supernode-$(OS)$(ARCHITECTURE) - docker container cp builder:/usr/src/n2n/edge ./build/edge-$(OS)$(ARCHITECTURE) - docker container rm -f builder - - docker build --build-arg COMMIT_HASH=$(N2N_COMMIT_HASH) -t $(DOCKER_IMAGE_TAGNAME) -f image-platforms/$(DOCKER_IMAGE_FILENAME) . - docker tag $(DOCKER_IMAGE_TAGNAME) $(DOCKER_IMAGE_NAME):latest$(ARCHITECTURE) - -push: - if [ ! "$(TARGET_ARCHITECTURE)" = "" ]; then \ - docker push $(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_VERSION)-$(TARGET_ARCHITECTURE); \ - docker push $(DOCKER_IMAGE_NAME):latest-$(TARGET_ARCHITECTURE); \ - else \ + docker container cp n2n-builder:/usr/src/n2n/supernode ./build/supernode-$(OS)$(ARCHITECTURE) + docker container cp n2n-builder:/usr/src/n2n/edge ./build/edge-$(OS)$(ARCHITECTURE) + docker container rm -f n2n-builder + + docker build --cache-from $(DOCKER_IMAGE_TAGNAME) \ + --build-arg COMMIT_HASH=$(N2N_COMMIT_HASH) \ + -t $(DOCKER_IMAGE_TAGNAME) \ + -t $(DOCKER_IMAGE_NAME):latest$(ARCHITECTURE) \ + -f image-platforms/$(DOCKER_IMAGE_FILENAME) . + +pre_push: + if [ "$(TARGET_ARCHITECTURE)" = "" ]; then \ echo "Please pass TARGET_ARCHITECTURE, see README.md."; \ + exit 1; \ fi -.PHONY: steps build push +push: pre_push + docker push $(DOCKER_IMAGE_NAME):$(DOCKER_IMAGE_VERSION)-$(TARGET_ARCHITECTURE) + docker push $(DOCKER_IMAGE_NAME):latest-$(TARGET_ARCHITECTURE) + +.PHONY: pre_platforms platforms build pre_push push +.SILENT: pre_platforms pre_push # End Docker builder section \ No newline at end of file diff --git a/README.md b/README.md index f490f39..fd98c0c 100644 --- a/README.md +++ b/README.md @@ -128,7 +128,7 @@ $ docker run --rm -d -p 5645:5645/udp -p 7654:7654/udp supermock/supernode:[TAGN Use `make` command to build the images. Before starting the arm32v7 platform build, you need to run this registry, so you can perform a cross-build. Just follow the documentation: https://github.com/multiarch/qemu-user-static/blob/master/README.md ```sh -$ TARGET_ARCHITECTURE=[arm32v7, x86_64, (nothing to build all architectures)] make +$ N2N_COMMIT_HASH=[(optional)] TARGET_ARCHITECTURE=[arm32v7, x86_64, (nothing to build all architectures)] make platforms ``` ### 2. Push it diff --git a/image-platforms/Dockerfile.arm32v7 b/image-platforms/Dockerfile.arm32v7 index b7be82f..9ebcfb0 100644 --- a/image-platforms/Dockerfile.arm32v7 +++ b/image-platforms/Dockerfile.arm32v7 @@ -1,20 +1,20 @@ FROM multiarch/debian-debootstrap:armhf-stretch AS builder +ARG DEBIAN_FRONTEND=noninteractive + +COPY ./image-platforms/common/dependencies.pkglist /tmp + +RUN apt-get update \ + && cat tmp/dependencies.pkglist | xargs apt-get install -y --no-install-recommends \ + && rm -rf /var/lib/apt/lists/* + ARG COMMIT_HASH -WORKDIR /usr/src +COPY ./ /usr/src/n2n -RUN apt-get update && apt-get install -y \ - gcc \ - libc6-dev \ - libssl-dev \ - ca-certificates \ - git \ - make \ - --no-install-recommends \ - && rm -rf /var/lib/apt/lists/* +WORKDIR /usr/src/n2n -RUN git clone https://github.com/ntop/n2n && cd n2n && git reset --hard $COMMIT_HASH && make +RUN chmod +x image-platforms/common/prepare-build.sh && image-platforms/common/prepare-build.sh FROM arm32v7/debian:stretch COPY --from=builder /usr/src/n2n/supernode /usr/bin diff --git a/image-platforms/Dockerfile.x86_64 b/image-platforms/Dockerfile.x86_64 index 0d95895..bdaefdb 100644 --- a/image-platforms/Dockerfile.x86_64 +++ b/image-platforms/Dockerfile.x86_64 @@ -1,20 +1,20 @@ FROM debian:stretch AS builder +ARG DEBIAN_FRONTEND=noninteractive + +COPY ./image-platforms/common/dependencies.pkglist /tmp + +RUN apt-get update \ + && cat tmp/dependencies.pkglist | xargs apt-get install -y --no-install-recommends \ + && rm -rf /var/lib/apt/lists/* + ARG COMMIT_HASH -WORKDIR /usr/src +COPY ./ /usr/src/n2n -RUN apt-get update && apt-get install -y \ - gcc \ - libc6-dev \ - libssl-dev \ - ca-certificates \ - git \ - make \ - --no-install-recommends \ - && rm -rf /var/lib/apt/lists/* +WORKDIR /usr/src/n2n -RUN git clone https://github.com/ntop/n2n && cd n2n && git reset --hard $COMMIT_HASH && make +RUN chmod +x image-platforms/common/prepare-build.sh && image-platforms/common/prepare-build.sh FROM debian:stretch COPY --from=builder /usr/src/n2n/supernode /usr/bin diff --git a/image-platforms/common/dependencies.pkglist b/image-platforms/common/dependencies.pkglist new file mode 100644 index 0000000..48649b9 --- /dev/null +++ b/image-platforms/common/dependencies.pkglist @@ -0,0 +1,6 @@ +gcc +libc6-dev +libssl-dev +ca-certificates +git +make \ No newline at end of file diff --git a/image-platforms/common/prepare-build.sh b/image-platforms/common/prepare-build.sh new file mode 100644 index 0000000..88bd04c --- /dev/null +++ b/image-platforms/common/prepare-build.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +if [ ! "$COMMIT_HASH" = "" ]; then + echo "Using COMMIT_HASH=$COMMIT_HASH" + git reset --hard $COMMIT_HASH +fi + +make \ No newline at end of file