From e9ff229630fcc2ec066b1acb51cc4c969c7abcf5 Mon Sep 17 00:00:00 2001 From: Devan Carpenter Date: Wed, 27 Jan 2021 01:31:15 +0100 Subject: [PATCH] ci: create initial gitlab-ci jobs Adds two simple jobs for building the library for Debian 10 and CentOS 8 They will pull down docker images containing the dependencies needed for libpEpAdapter, then proceed with the build. Upon successful compilation, an image containing the ouput (and dependencies) will be pushed to a docker registry on the CI infrastructure. Note about the docker images in use: Currently they pull the latest docker images containing pEpEngine, Sequoia, and other dependencies. We want to specify the exact required version in future updates to the jobs. --- .gitlab-ci-files/common-prepare.yml | 34 +++++++++++++++++++ .gitlab-ci.yml | 25 ++++++++++++++ scripts/centos8/Makefile | 15 ++++++++ scripts/centos8/build_libpEpAdapter.sh | 8 +++++ .../centos8/libpEpAdapter.centos8.Dockerfile | 23 +++++++++++++ scripts/debian10/Makefile | 15 ++++++++ scripts/debian10/build_libpEpAdapter.sh | 8 +++++ .../libpEpAdapter.debian10.Dockerfile | 23 +++++++++++++ 8 files changed, 151 insertions(+) create mode 100644 .gitlab-ci-files/common-prepare.yml create mode 100644 .gitlab-ci.yml create mode 100644 scripts/centos8/Makefile create mode 100755 scripts/centos8/build_libpEpAdapter.sh create mode 100644 scripts/centos8/libpEpAdapter.centos8.Dockerfile create mode 100644 scripts/debian10/Makefile create mode 100755 scripts/debian10/build_libpEpAdapter.sh create mode 100644 scripts/debian10/libpEpAdapter.debian10.Dockerfile diff --git a/.gitlab-ci-files/common-prepare.yml b/.gitlab-ci-files/common-prepare.yml new file mode 100644 index 0000000..14567f1 --- /dev/null +++ b/.gitlab-ci-files/common-prepare.yml @@ -0,0 +1,34 @@ +.ensure_docker: &ensure_docker + # Check for docker and install if missing + - 'which docker || ( sudo apt-get update -y && sudo apt-get install docker.io -y )' + +.ensure_rsync: &ensure_rsync + # Install rsync and deps if missing + - 'which ssh-agent || ( sudo apt-get update -y && sudo apt-get install openssh-client -y )' + - 'which rsync || ( sudo apt-get update -y && sudo apt-get install rsync -y )' + - 'which make || ( sudo apt-get update -y && sudo apt-get install make -y )' + +.enable_insecure_docker_registries: &enable_insecure_docker_registries + # Enable "insecure" docker registries + - | + cat < /tmp/docker-daemon.json + { + "insecure-registries" : ["${DOCKER_REGISTRY_HOST}"] + } + EOD + - sudo cp /tmp/docker-daemon.json /etc/docker/daemon.json + - sudo systemctl restart docker.service + +.standard_job: + tags: [kvm] + before_script: + - *ensure_docker + - *ensure_rsync + - *enable_insecure_docker_registries + +.make_in_docker: + extends: .standard_job + script: + - docker login -u ${DOCKER_REGISTRY_USER} -p ${DOCKER_REGISTRY_PASS} ${DOCKER_REGISTRY_HOST} + - cd scripts/${CI_DISTRO_TARGET} + - make diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..ea90745 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,25 @@ +include: + - '.gitlab-ci-files/common-prepare.yml' + +stages: + - build + + +# CentOS/RHEL + +centos8:build: + extends: .make_in_docker + stage: build + variables: + CI_MAKE_TARGET: libpepadapter + CI_DISTRO_TARGET: centos8 + +# Debian + +debian10:build: + extends: .make_in_docker + stage: build + variables: + CI_MAKE_TARGET: libpepadapter + CI_DISTRO_TARGET: debian10 + DEBIAN_FRONTEND: noninteractive diff --git a/scripts/centos8/Makefile b/scripts/centos8/Makefile new file mode 100644 index 0000000..8e10078 --- /dev/null +++ b/scripts/centos8/Makefile @@ -0,0 +1,15 @@ +CURRENT_DISTRO=$(shell basename $(shell pwd)) +LIBPEPADAPTER_VERSION=$(shell git rev-parse --short=8 HEAD) +IMAGE_NAME=${DOCKER_REGISTRY_HOST}/pep-$(CURRENT_DISTRO)-libpepadapter +DOCKERFILE=libpEpAdapter.$(CURRENT_DISTRO).Dockerfile +all: + -docker pull $(IMAGE_NAME):latest + cd ../../ && docker build --build-arg CURRENT_DISTRO=$(CURRENT_DISTRO) \ + --build-arg DOCKER_REGISTRY_HOST=${DOCKER_REGISTRY_HOST} \ + --build-arg LIBPEPADAPTER_VERSION=$(LIBPEPADAPTER_VERSION) \ + --cache-from $(IMAGE_NAME):latest \ + --tag=$(IMAGE_NAME):$(LIBPEPADAPTER_VERSION) \ + --tag=$(IMAGE_NAME):latest \ + -f scripts/${CURRENT_DISTRO}/$(DOCKERFILE) . + docker push $(IMAGE_NAME):${LIBPEPADAPTER_VERSION} + docker push $(IMAGE_NAME):latest diff --git a/scripts/centos8/build_libpEpAdapter.sh b/scripts/centos8/build_libpEpAdapter.sh new file mode 100755 index 0000000..1f4a6c5 --- /dev/null +++ b/scripts/centos8/build_libpEpAdapter.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env sh +set -exo + +echo "ENGINE_LIB_PATH=${INSTPREFIX}/lib" >> local.conf +echo "ENGINE_INC_PATH=${INSTPREFIX}/include" >> local.conf + +make +make install PREFIX="${INSTPREFIX}" diff --git a/scripts/centos8/libpEpAdapter.centos8.Dockerfile b/scripts/centos8/libpEpAdapter.centos8.Dockerfile new file mode 100644 index 0000000..a2fe8a3 --- /dev/null +++ b/scripts/centos8/libpEpAdapter.centos8.Dockerfile @@ -0,0 +1,23 @@ +ARG DOCKER_REGISTRY_HOST +ARG CURRENT_DISTRO +ARG PEPENGINE_VERSION=latest +FROM ${DOCKER_REGISTRY_HOST}/pep-${CURRENT_DISTRO}-engine:${PEPENGINE_VERSION} + +ENV BUILDROOT /build +ENV INSTPREFIX /install +ENV OUTDIR /out + +### Setup working directory +RUN mkdir ${BUILDROOT}/libpEpAdapter +COPY . ${BUILDROOT}/libpEpAdapter +USER root +RUN chown -R pep-builder:pep-builder ${BUILDROOT}/libpEpAdapter +USER pep-builder +WORKDIR ${BUILDROOT}/libpEpAdapter + +ARG LIBPEPADAPTER_VERSION +ARG CURRENT_DISTRO + +### Build libpEpAdapter +RUN sh ./scripts/${CURRENT_DISTRO}/build_libpEpAdapter.sh && \ + rm -rf ${BUILDROOT}/* diff --git a/scripts/debian10/Makefile b/scripts/debian10/Makefile new file mode 100644 index 0000000..8e10078 --- /dev/null +++ b/scripts/debian10/Makefile @@ -0,0 +1,15 @@ +CURRENT_DISTRO=$(shell basename $(shell pwd)) +LIBPEPADAPTER_VERSION=$(shell git rev-parse --short=8 HEAD) +IMAGE_NAME=${DOCKER_REGISTRY_HOST}/pep-$(CURRENT_DISTRO)-libpepadapter +DOCKERFILE=libpEpAdapter.$(CURRENT_DISTRO).Dockerfile +all: + -docker pull $(IMAGE_NAME):latest + cd ../../ && docker build --build-arg CURRENT_DISTRO=$(CURRENT_DISTRO) \ + --build-arg DOCKER_REGISTRY_HOST=${DOCKER_REGISTRY_HOST} \ + --build-arg LIBPEPADAPTER_VERSION=$(LIBPEPADAPTER_VERSION) \ + --cache-from $(IMAGE_NAME):latest \ + --tag=$(IMAGE_NAME):$(LIBPEPADAPTER_VERSION) \ + --tag=$(IMAGE_NAME):latest \ + -f scripts/${CURRENT_DISTRO}/$(DOCKERFILE) . + docker push $(IMAGE_NAME):${LIBPEPADAPTER_VERSION} + docker push $(IMAGE_NAME):latest diff --git a/scripts/debian10/build_libpEpAdapter.sh b/scripts/debian10/build_libpEpAdapter.sh new file mode 100755 index 0000000..1f4a6c5 --- /dev/null +++ b/scripts/debian10/build_libpEpAdapter.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env sh +set -exo + +echo "ENGINE_LIB_PATH=${INSTPREFIX}/lib" >> local.conf +echo "ENGINE_INC_PATH=${INSTPREFIX}/include" >> local.conf + +make +make install PREFIX="${INSTPREFIX}" diff --git a/scripts/debian10/libpEpAdapter.debian10.Dockerfile b/scripts/debian10/libpEpAdapter.debian10.Dockerfile new file mode 100644 index 0000000..a2fe8a3 --- /dev/null +++ b/scripts/debian10/libpEpAdapter.debian10.Dockerfile @@ -0,0 +1,23 @@ +ARG DOCKER_REGISTRY_HOST +ARG CURRENT_DISTRO +ARG PEPENGINE_VERSION=latest +FROM ${DOCKER_REGISTRY_HOST}/pep-${CURRENT_DISTRO}-engine:${PEPENGINE_VERSION} + +ENV BUILDROOT /build +ENV INSTPREFIX /install +ENV OUTDIR /out + +### Setup working directory +RUN mkdir ${BUILDROOT}/libpEpAdapter +COPY . ${BUILDROOT}/libpEpAdapter +USER root +RUN chown -R pep-builder:pep-builder ${BUILDROOT}/libpEpAdapter +USER pep-builder +WORKDIR ${BUILDROOT}/libpEpAdapter + +ARG LIBPEPADAPTER_VERSION +ARG CURRENT_DISTRO + +### Build libpEpAdapter +RUN sh ./scripts/${CURRENT_DISTRO}/build_libpEpAdapter.sh && \ + rm -rf ${BUILDROOT}/*