ci #67
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: ci | |
on: | |
workflow_dispatch: | |
push: | |
pull_request: | |
schedule: | |
- cron: '0 0 * * *' # every day at midnight | |
#Global vars | |
env: | |
BUILD_DOCKER_FILE_UBUNTU_BIONIC: ci/Dockerfile-ubuntu-bionic-for-pmacct | |
BUILD_DOCKER_TAG_UBUNTU_BIONIC: ci/ubuntu-bionic-for-pmacct | |
BUILD_DOCKER_FILE_CENTOS_8: ci/Dockerfile-centos-8-for-pmacct | |
BUILD_DOCKER_TAG_CENTOS_8: ci/centos8-for-pmacct | |
jobs: | |
### Step 1: build container images | |
builder-ubuntu-docker: | |
runs-on: ubuntu-18.04 | |
steps: | |
- name: Checkout pmacct | |
uses: actions/checkout@v2 | |
with: | |
path: pmacct | |
- name: Build docker image for Ubuntu Bionic | |
run: | | |
cd pmacct | |
git config --global --add safe.directory $GITHUB_WORKSPACE | |
git config --global --add safe.directory $GITHUB_WORKSPACE/src/external_libs/libcdada | |
git rev-parse HEAD | |
docker build -f $BUILD_DOCKER_FILE_UBUNTU_BIONIC -t $BUILD_DOCKER_TAG_UBUNTU_BIONIC . | |
mkdir -p /tmp/docker/ | |
docker save -o /tmp/docker/builder_ubuntu.tar $BUILD_DOCKER_TAG_UBUNTU_BIONIC | |
- name: Artifact docker image | |
uses: actions/[email protected] | |
with: | |
name: builder_ubuntu | |
retention-days: 1 | |
path: | | |
/tmp/docker | |
builder-centos-docker: | |
runs-on: ubuntu-18.04 | |
steps: | |
- name: Checkout pmacct | |
uses: actions/checkout@v2 | |
with: | |
path: pmacct | |
- name: Build docker image for Centos 8 | |
run: | | |
cd pmacct | |
git config --global --add safe.directory $GITHUB_WORKSPACE | |
git config --global --add safe.directory $GITHUB_WORKSPACE/src/external_libs/libcdada | |
git rev-parse HEAD | |
docker build -f $BUILD_DOCKER_FILE_UBUNTU_BIONIC -t $BUILD_DOCKER_TAG_UBUNTU_BIONIC . | |
mkdir -p /tmp/docker/ | |
docker save -o /tmp/docker/builder_centos.tar $BUILD_DOCKER_TAG_UBUNTU_BIONIC | |
- name: Artifact docker image | |
uses: actions/[email protected] | |
with: | |
name: builder_centos | |
retention-days: 1 | |
path: | | |
/tmp/docker | |
### Step 2: permutations | |
build-and-test: | |
needs: [builder-ubuntu-docker, builder-centos-docker] | |
runs-on: ubuntu-18.04 | |
strategy: | |
fail-fast: false | |
matrix: | |
builder-name: [builder_ubuntu, builder_centos] | |
CONFIG_FLAGS: [ | |
"", | |
"--enable-debug", | |
"--enable-debug --enable-jansson", | |
"--enable-debug --enable-jansson --enable-kafka", | |
"--enable-debug --enable-jansson --enable-kafka --enable-avro --enable-serdes", | |
"--enable-debug --enable-jansson --enable-zmq", | |
"--enable-debug --enable-jansson --enable-zmq --enable-kafka", | |
"--enable-debug --enable-mysql --enable-pgsql --enable-sqlite3 --enable-kafka --enable-geoipv2 --enable-jansson --enable-rabbitmq --enable-nflog --enable-ndpi --enable-zmq --enable-avro --enable-serdes --enable-redis --enable-unyte-udp-notif", | |
"--enable-debug --enable-zmq", | |
"--enable-jansson", | |
"--enable-jansson --enable-kafka", | |
"--enable-jansson --enable-kafka --enable-avro --enable-serdes", | |
"--enable-jansson --enable-zmq", | |
"--enable-jansson --enable-zmq --enable-kafka", | |
"--enable-mysql --enable-pgsql --enable-sqlite3 --enable-kafka --enable-geoipv2 --enable-jansson --enable-rabbitmq --enable-nflog --enable-ndpi --enable-zmq --enable-avro --enable-serdes --enable-redis --enable-unyte-udp-notif", | |
"--enable-zmq"] | |
env: | |
CONFIG_FLAGS: ${{ matrix.CONFIG_FLAGS }} | |
steps: | |
- name: Info | |
run: | | |
echo "Builder: ${{ matrix.builder-name }}" | |
echo "CONFIG_FLAGS: ${{ matrix.CONFIG_FLAGS }}" | |
- name: Create /tmp/docker folder to copy the docker registry (artifact) | |
run: | | |
mkdir -p /tmp/docker | |
- uses: actions/download-artifact@v2 | |
with: | |
name: ${{ matrix.builder-name }} | |
path: /tmp/docker | |
- name: List contents of /tmp/docker | |
run: | | |
ls -la /tmp/docker | |
- name: Checkout pmacct | |
uses: actions/[email protected] | |
with: | |
fetch-depth: 0 | |
path: pmacct | |
- name: Build in '${{ matrix.builder-name }}' with '${{ matrix.CONFIG_FLAGS }}' | |
run: | | |
cd pmacct | |
git config --global --add safe.directory $GITHUB_WORKSPACE | |
git config --global --add safe.directory $GITHUB_WORKSPACE/src/external_libs/libcdada | |
git rev-parse HEAD | |
docker load -i /tmp/docker/${{ matrix.builder-name }}.tar | |
CONTAINER_ID=$(docker run --rm -it -d -v `pwd`:`pwd` -w `pwd` -e CONFIG_FLAGS $BUILD_DOCKER_TAG_UBUNTU_BIONIC:latest) | |
echo "Launched container id:" $CONTAINER_ID | |
docker exec -i $CONTAINER_ID ./ci/script.sh | |
docker stop $CONTAINER_ID | |
### Step 3: official docker image generation | |
pmacct-docker: | |
runs-on: ubuntu-18.04 | |
steps: | |
- name: Checkout pmacct | |
uses: actions/checkout@v1 #Don't use v2 messes everything | |
with: | |
path: pmacct | |
- name: Build containers | |
run: | | |
git config --global --add safe.directory $GITHUB_WORKSPACE | |
git config --global --add safe.directory $GITHUB_WORKSPACE/src/external_libs/libcdada | |
git rev-parse HEAD | |
echo "Fix mess with tags in actions/checkout..." | |
git fetch -f && git fetch -f --tags | |
echo "Deducing PMACCT_VERSION..." | |
PMACCT_VERSION=$(git describe --abbrev=0 --match="v*") | |
echo "PMACCT_VERSION=$PMACCT_VERSION" | |
echo "Building the base container..." | |
docker build --build-arg NUM_WORKERS=$CI_NUM_WORKERS --build-arg DEPS_DONT_CHECK_CERTIFICATE=$CI_DEPS_DONT_CHECK_CERTIFICATE -f docker/base/Dockerfile -t base:_build . | |
echo "Building daemon containers..." | |
docker build -f docker/pmacctd/Dockerfile -t pmacctd:_build . | |
docker build -f docker/nfacctd/Dockerfile -t nfacctd:_build . | |
docker build -f docker/sfacctd/Dockerfile -t sfacctd:_build . | |
docker build -f docker/uacctd/Dockerfile -t uacctd:_build . | |
docker build -f docker/pmbgpd/Dockerfile -t pmbgpd:_build . | |
docker build -f docker/pmbmpd/Dockerfile -t pmbmpd:_build . | |
docker build -f docker/pmtelemetryd/Dockerfile -t pmtelemetryd:_build . | |
echo "Saving images as artifacts..." | |
mkdir -p /tmp/docker/ | |
docker save -o /tmp/docker/pmacct_docker_images.tar base:_build pmacctd:_build nfacctd:_build sfacctd:_build uacctd:_build pmbgpd:_build pmbmpd:_build pmtelemetryd:_build | |
- name: Docker (compose) smoke test | |
run: | | |
echo "Running smoke test using docker-compose..." | |
TAG=_build docker-compose -f ci/smoke-test/docker-compose.yml up -d | |
sleep 10 | |
echo "Check that all containers are up and running, without restarts ..." | |
if [[ "$(docker inspect `docker ps -aq` | grep RestartCount | grep -v '\"RestartCount\": 0')" != "" ]]; then | |
echo "Some containers restarted!" && docker inspect `docker ps -aq` && /bin/false | |
fi | |
echo "Stopping containers..." | |
TAG=_build docker-compose -f ci/smoke-test/docker-compose.yml down | |
- name: Export pmacct docker images as an artifact | |
uses: actions/[email protected] | |
with: | |
name: pmacct_docker_images | |
retention-days: 1 | |
path: | | |
/tmp/docker | |
### Step 4: Upload images to dockerhub (bleeding-edge, latest and releases) | |
publish-dockerhub: | |
needs: [pmacct-docker, build-and-test] | |
runs-on: ubuntu-18.04 | |
if: github.event_name != 'pull_request' | |
env: | |
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} | |
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} | |
steps: | |
- uses: actions/download-artifact@v2 | |
with: | |
name: pmacct_docker_images | |
path: /tmp/docker | |
- name: Import pmacct docker images in the local registry | |
run: | | |
docker load -i /tmp/docker/pmacct_docker_images.tar | |
- name: Checkout pmacct | |
uses: actions/checkout@v1 #Don't use v2 messes everything | |
with: | |
path: pmacct | |
- name: Build and upload containers | |
run: | | |
echo "Fix mess with tags in actions/checkout..." | |
git fetch -f && git fetch -f --tags | |
echo "Deducing PMACCT_VERSION..." | |
PMACCT_VERSION=$(git describe --abbrev=0 --match="v*") | |
echo "PMACCT_VERSION=$PMACCT_VERSION" | |
echo "Uploading to dockerhub ..."; | |
echo ${DOCKER_PASSWORD} | docker login -u ${DOCKER_USERNAME} --password-stdin; | |
#Always push bleeding-edge when pushed to master | |
GIT_IS_BLEEDING_EDGE=$( (git branch --all --contains HEAD | grep master ) || echo "") | |
echo "GIT_IS_BLEEDING_EDGE=$GIT_IS_BLEEDING_EDGE" | |
if [ "$GIT_IS_BLEEDING_EDGE" != "" ]; then | |
echo "Uploading 'bleeding-edge' tag for `git describe`..."; | |
docker tag base:_build ${DOCKER_USERNAME}/base:bleeding-edge; | |
docker push ${DOCKER_USERNAME}/base:bleeding-edge; | |
docker tag pmacctd:_build ${DOCKER_USERNAME}/pmacctd:bleeding-edge; | |
docker push ${DOCKER_USERNAME}/pmacctd:bleeding-edge; | |
docker tag nfacctd:_build ${DOCKER_USERNAME}/nfacctd:bleeding-edge; | |
docker push ${DOCKER_USERNAME}/nfacctd:bleeding-edge; | |
docker tag sfacctd:_build ${DOCKER_USERNAME}/sfacctd:bleeding-edge; | |
docker push ${DOCKER_USERNAME}/sfacctd:bleeding-edge; | |
docker tag uacctd:_build ${DOCKER_USERNAME}/uacctd:bleeding-edge; | |
docker push ${DOCKER_USERNAME}/uacctd:bleeding-edge; | |
docker tag pmbgpd:_build ${DOCKER_USERNAME}/pmbgpd:bleeding-edge; | |
docker push ${DOCKER_USERNAME}/pmbgpd:bleeding-edge; | |
docker tag pmbmpd:_build ${DOCKER_USERNAME}/pmbmpd:bleeding-edge; | |
docker push ${DOCKER_USERNAME}/pmbmpd:bleeding-edge; | |
docker tag pmtelemetryd:_build ${DOCKER_USERNAME}/pmtelemetryd:bleeding-edge; | |
docker push ${DOCKER_USERNAME}/pmtelemetryd:bleeding-edge; | |
fi | |
#Upload vX.Y.Z only of it's a release commit | |
GIT_RELEASE_TAG=$(git describe --exact-match --match "v*" || echo "") | |
echo "GIT_RELEASE_TAG=$GIT_RELEASE_TAG" | |
if [ "$GIT_RELEASE_TAG" != "" ]; then | |
echo "Uploading '$PMACCT_VERSION' tag for `git describe`..."; | |
docker tag base:_build ${DOCKER_USERNAME}/base:${PMACCT_VERSION}; | |
docker push ${DOCKER_USERNAME}/base:${PMACCT_VERSION}; | |
docker tag pmacctd:_build ${DOCKER_USERNAME}/pmacctd:${PMACCT_VERSION}; | |
docker push ${DOCKER_USERNAME}/pmacctd:${PMACCT_VERSION}; | |
docker tag nfacctd:_build ${DOCKER_USERNAME}/nfacctd:${PMACCT_VERSION}; | |
docker push ${DOCKER_USERNAME}/nfacctd:${PMACCT_VERSION}; | |
docker tag sfacctd:_build ${DOCKER_USERNAME}/sfacctd:${PMACCT_VERSION}; | |
docker push ${DOCKER_USERNAME}/sfacctd:${PMACCT_VERSION}; | |
docker tag uacctd:_build ${DOCKER_USERNAME}/uacctd:${PMACCT_VERSION}; | |
docker push ${DOCKER_USERNAME}/uacctd:${PMACCT_VERSION}; | |
docker tag pmbgpd:_build ${DOCKER_USERNAME}/pmbgpd:${PMACCT_VERSION}; | |
docker push ${DOCKER_USERNAME}/pmbgpd:${PMACCT_VERSION}; | |
docker tag pmbmpd:_build ${DOCKER_USERNAME}/pmbmpd:${PMACCT_VERSION}; | |
docker push ${DOCKER_USERNAME}/pmbmpd:${PMACCT_VERSION}; | |
docker tag pmtelemetryd:_build ${DOCKER_USERNAME}/pmtelemetryd:${PMACCT_VERSION}; | |
docker push ${DOCKER_USERNAME}/pmtelemetryd:${PMACCT_VERSION}; | |
fi | |
#Upload "latest" if the release version is the highest | |
if [ "$GIT_RELEASE_TAG" != "" ]; then | |
GIT_LAST_TAG=$(git tag --sort=v:refname | tail -n 1); | |
echo "GIT_LAST_TAG=$GIT_LAST_TAG" | |
if [ "$GIT_RELEASE_TAG" == "$GIT_LAST_TAG" ]; then | |
echo "Uploading 'latest' tag for `git describe`..."; | |
docker tag base:_build ${DOCKER_USERNAME}/base:latest; | |
docker push ${DOCKER_USERNAME}/base:latest; | |
docker tag pmacctd:_build ${DOCKER_USERNAME}/pmacctd:latest; | |
docker push ${DOCKER_USERNAME}/pmacctd:latest; | |
docker tag nfacctd:_build ${DOCKER_USERNAME}/nfacctd:latest; | |
docker push ${DOCKER_USERNAME}/nfacctd:latest; | |
docker tag sfacctd:_build ${DOCKER_USERNAME}/sfacctd:latest; | |
docker push ${DOCKER_USERNAME}/sfacctd:latest; | |
docker tag uacctd:_build ${DOCKER_USERNAME}/uacctd:latest; | |
docker push ${DOCKER_USERNAME}/uacctd:latest; | |
docker tag pmbgpd:_build ${DOCKER_USERNAME}/pmbgpd:latest; | |
docker push ${DOCKER_USERNAME}/pmbgpd:latest; | |
docker tag pmbmpd:_build ${DOCKER_USERNAME}/pmbmpd:latest; | |
docker push ${DOCKER_USERNAME}/pmbmpd:latest; | |
docker tag pmtelemetryd:_build ${DOCKER_USERNAME}/pmtelemetryd:latest; | |
docker push ${DOCKER_USERNAME}/pmtelemetryd:latest; | |
fi | |
fi |