Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add multi-arch Dockerfiles and scripts #1712

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 103 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -311,3 +311,106 @@ wrappers: | build deps librln libwaku.so
go build -ldflags "-linkmode external -extldflags '$(EXTRA_LIBS_DYNAMIC)'" -o build/go_wrapper_example wrappers/wrapper_example.go #wrappers/cfuncs.go

endif # "variables.mk" was not included

##############################################
# Static Binaries for Multiple Architectures #
##############################################

MAKE_PID := $(shell echo $$PPID)
JOB_FLAG := $(filter -j%, $(subst --jobs ,-j,$(subst --jobs=,-j,$(subst -j ,-j,$(shell ps T | grep "^\s*$(MAKE_PID).*$(MAKE)")))))
JOBS := $(subst -j,,$(JOB_FLAG))
ifneq ($(JOBS), )
JOBS := -j $(JOBS)
endif

ARCH :=amd64
#FIXME!
NWAKU_BUILDER_IMAGE := quay.io/vpavlin0/nwaku-builder
NWAKU_BASE_TAG := 20230512110759
NWAKU_DIST_TAG := $(GIT_VERSION)_
#nwaku-base-20230502082624_arm64

SHELL := /bin/bash

BINARIES := wakunode2 wakunode1 chat2

static-base:
set -x &&\
mkdir -p $${PWD}/vendor-$(ARCH) $${PWD}/build/$(ARCH) $${PWD}/nimcache-$(ARCH) &&\
docker run -it --rm\
-v $${PWD}:/home/user/nwaku:z\
-v $${PWD}/vendor-$(ARCH):/home/user/nwaku/vendor:z\
-v $${PWD}/nimcache-$(ARCH):/home/user/nwaku/nimcache:z\
-v $${PWD}/build/$(ARCH):/home/user/nwaku/build:z\
--workdir /home/user/nwaku\
--user $$(id -u):$$(id -g)\
$(NWAKU_BUILDER_IMAGE):$(NWAKU_BASE_TAG)_$(ARCH)\
$(JOBS)\
V=1\
LOG_LEVEL="TRACE"\
QUICK_AND_DIRTY_COMPILER=1\
NIMFLAGS="$(NIMFLAGS)"\
$(BINARIES)

static-arm64: ARCH :=arm64
static-arm64: NIMFLAGS := $(NIMFLAGS) --cpu:arm64 --os:linux --gcc.exe:aarch64-alpine-linux-musl-gcc --gcc.linkerexe:aarch64-alpine-linux-musl-gcc --passL:-static
static-arm64:
$(MAKE) $(JOBS) static-base NIMFLAGS="$(NIMFLAGS)" ARCH=$(ARCH)



static-amd64: ARCH :=amd64
static-amd64: NIMFLAGS := $(NIMFLAGS) --cpu:amd64 --os:linux --gcc.exe:x86_64-alpine-linux-musl-gcc --gcc.linkerexe:x86_64-alpine-linux-musl-gcc --passL:-static
static-amd64:
$(MAKE) $(JOBS) static-base NIMFLAGS="$(NIMFLAGS)" ARCH=$(ARCH)

static-clean:
rm -rf build/arm64 build/amd64 vendor-arm64 vendor-amd64


################################################
# Distributable Artifacts (tars and containers) #
################################################

dist-base:
mkdir -p dist &&\
pushd build/$(ARCH) &&\
tar czf ../../dist/wakunode-$(GIT_VERSION)-$(ARCH).tgz $(BINARIES)

dist-amd64: static-amd64
$(MAKE) $(JOBS) dist-base ARCH=amd64

dist-arm64: static-arm64
$(MAKE) $(JOBS) dist-base ARCH=arm64

dist-container-base:
echo $(ARCH) &&\
ls &&\
cd build/$(ARCH) &&\
docker build -t nwaku:$(NWAKU_DIST_TAG)$(ARCH) -f ../../docker/dist/Dockerfile.$(ARCH) .

dist-container-amd64: | dist-amd64
$(MAKE) $(JOBS) dist-container-base ARCH=amd64

dist-container-arm64: | dist-arm64
$(MAKE) $(JOBS) dist-container-base ARCH=arm64

dist-container:
$(MAKE) $(JOBS) dist-container-amd64
$(MAKE) $(JOBS) dist-container-arm64
docker manifest create quay.io/vpavlin0/nwaku:multiarch \
--amend nwaku:$(NWAKU_DIST_TAG)amd64 \
--amend nwaku:$(NWAKU_DIST_TAG)arm64

###################
# Release Targets #
###################

release-notes:
docker run \
-it \
--rm \
-v $${PWD}:/opt/sv4git/repo:z \
-u $(shell id -u) \
quay.io/vpavlin0/sv4git:latest \
release-notes
34 changes: 34 additions & 0 deletions ci/Jenkinsfile.builders
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
pipeline {
agent { label 'linux' }

options {
timestamps()
timeout(time: 20, unit: 'MINUTES')
buildDiscarder(logRotator(
numToKeepStr: '10',
daysToKeepStr: '30',
))
}

parameters {
string(
name: 'REPOSITORY',
description: 'Name of container registry repository',
defaultValue: params.REPOSITORY ?: 'wakuorg',
)
}

stages {
stage('Build & Push') {
steps {
withDockerRegistry([credentialsId: "dockerhub-vacorgbot-api-token", url: ""]) {
dir("docker/base") {
sh "./build.sh --registry docker.io --repository ${params.REPOSITORY} --latest --push all"
}
}
}
}
} // stages

} // pipeline

15 changes: 15 additions & 0 deletions docker/base/Dockerfile.amd64
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM --platform=amd64 alpine:edge

ARG USER_ID
ARG GROUP_ID

RUN addgroup -g ${GROUP_ID} user; \
adduser --disabled-password --gecos '' -u ${USER_ID} -G user user;

WORKDIR /home/user/nwaku
ENTRYPOINT [ "entrypoint.sh" ]

# Get build tools and required header files
RUN apk add --no-cache bash git cargo build-base pcre-dev linux-headers

ADD entrypoint.sh /bin/entrypoint.sh
19 changes: 19 additions & 0 deletions docker/base/Dockerfile.arm64
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM --platform=arm64 alpine:edge

ARG USER_ID
ARG GROUP_ID

RUN addgroup -g ${GROUP_ID} user; \
adduser --disabled-password --gecos '' -u ${USER_ID} -G user user;

WORKDIR /home/user/nwaku
ENTRYPOINT [ "entrypoint.sh" ]

# Get build tools and required header files
RUN apk add --no-cache bash git cargo build-base pcre-dev linux-headers

ADD entrypoint.sh /bin/entrypoint.sh

#RUN git clone https://github.com/waku-org/nwaku.git --depth 1 &&\
# cd nwaku &&\
# make deps
86 changes: 86 additions & 0 deletions docker/base/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#!/usr/bin/env bash

set -ex

cd "$(dirname "${BASH_SOURCE[0]}")"

BUILDER=
PUSH=
LOAD=
LATEST=
NO_CACHE="--no-cache"
IMAGE_NAME="nwaku-builder"

for i in `seq 1 $#`;do
case $1 in
"--builder")
shift
BUILDER="--builder ${1}"
shift
;;
"--push")
shift
PUSH="--push"
;;
"--load")
shift
LOAD="--load"
;;
"--registry")
shift
REGISTRY="${1}/"
shift
;;
"--repository")
shift
REPOSITORY="${1}/"
shift
;;
"--latest")
shift
LATEST="1"
;;
"--use-cache")
shift
NO_CACHE=""
;;
*)
break
;;
esac
done

IMAGE_NAME=${REGISTRY}${REPOSITORY}${IMAGE_NAME}

ARCHS=$(ls Dockerfile.* | sed 's/.*\.//')

ARCH="${@:-amd64}"



if [[ "${ARCH}" == "all" ]]; then
echo "Building all images: $( echo ${ARCHS} | tr '\n' ' ')"
ARCH=${ARCHS}
fi

TAG="$(date --utc +"%Y%m%d%H%M%S")"

for arch in $(echo ${ARCH}); do
DOCKER_BUILDKIT=1 \
docker build\
${BUILDER}\
${PUSH}\
${LOAD}\
${NO_CACHE}\
-t ${IMAGE_NAME}:${TAG}_${arch}\
--build-arg USER_ID=$(id -u)\
--build-arg GROUP_ID=$(id -g)\
-f Dockerfile.${arch}\
.

if [[ -n "${LATEST}" ]]; then
docker tag\
${IMAGE_NAME}:${TAG}_${arch}\
${IMAGE_NAME}:latest_${arch}
fi
done
11 changes: 11 additions & 0 deletions docker/base/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

echo $@

die() {
exit 143; # 128 + 15 -- SIGTERM
}

trap 'die' SIGINT

make "$@"
Empty file added docker/builder/Dockerfile.arm64
Empty file.
5 changes: 5 additions & 0 deletions docker/dist/Dockerfile.amd64
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM --platform=amd64 alpine:edge

ADD . /usr/local/bin

ENTRYPOINT [ "wakunode2" ]
5 changes: 5 additions & 0 deletions docker/dist/Dockerfile.arm64
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM --platform=arm64 alpine:edge

ADD . /usr/local/bin

ENTRYPOINT [ "wakunode2" ]