Skip to content

to be removed, shorten test pipelines #251

to be removed, shorten test pipelines

to be removed, shorten test pipelines #251

Workflow file for this run

name: ci
on:
workflow_dispatch:
push:
pull_request:
schedule:
- cron: '0 0 * * *' # every day at midnight
#Global vars
env:
BUILD_DOCKER_FILE_UBUNTU_FOCAL: ci/Dockerfile-ubuntu-focal-for-pmacct
BUILD_DOCKER_TAG_UBUNTU_FOCAL: builder_ubuntu_focal
BUILD_DOCKER_FILE_UBUNTU_JAMMY: ci/Dockerfile-ubuntu-jammy-for-pmacct
BUILD_DOCKER_TAG_UBUNTU_JAMMY: builder_ubuntu_jammy
BUILD_DOCKER_FILE_ROCKYLINUX_8: ci/Dockerfile-rockylinux-8-for-pmacct
BUILD_DOCKER_TAG_ROCKYLINUX_8: builder_rockylinux8
BUILD_DOCKER_FILE_ROCKYLINUX_9: ci/Dockerfile-rockylinux-9-for-pmacct
BUILD_DOCKER_TAG_ROCKYLINUX_9: builder_rockylinux9
DAEMONS: "pmacctd nfacctd sfacctd uacctd pmbgpd pmbmpd pmtelemetryd"
jobs:
### Step 3: official docker image generation
pmacct-docker:
runs-on: ubuntu-22.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..."
for DAEMON in ${DAEMONS}; do
docker build -f docker/${DAEMON}/Dockerfile -t ${DAEMON}:_build .
done
echo "Saving images as artifacts..."
mkdir -p /tmp/docker/
docker save -o /tmp/docker/pmacct_docker_images.tar base:_build $(for DAEMON in ${DAEMONS};do echo "${DAEMON}:_build "; done)
- 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]
runs-on: ubuntu-22.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 "Tagging and uploading 'bleeding-edge'..."
else
echo "NOT uploading 'bleeding-edge'... Not HEAD of master"
fi
#Upload vX.Y.Z only of it's a release commit
GIT_RELEASE_TAG=$(git describe --exact-match --match "v*" || echo "")
if [ "$GIT_RELEASE_TAG" != "" ]; then
echo "GIT_RELEASE_TAG=$GIT_RELEASE_TAG"
echo "Tagging and uploading release '$GIT_RELEASE_TAG'..."
#Latest tag
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 "Tagging and uploading 'latest'..."
else
echo "NOT uploading 'latest'..."
fi
else
echo "NOT uploading '$GIT_RELEASE_TAG' nor 'latest'. Not a release!"
fi
#Let's do it!
EXT_DAEMONS="base ${DAEMONS}"
for DAEMON in ${EXT_DAEMONS}; do
if [ "$GIT_IS_BLEEDING_EDGE" != "" ]; then
docker tag ${DAEMON}:_build ${DOCKER_USERNAME}/${DAEMON}:bleeding-edge;
docker push ${DOCKER_USERNAME}/${DAEMON}:bleeding-edge;
fi
if [ "$GIT_RELEASE_TAG" != "" ]; then
docker tag ${DAEMON}:_build ${DOCKER_USERNAME}/${DAEMON}:${PMACCT_VERSION};
docker push ${DOCKER_USERNAME}/${DAEMON}:${PMACCT_VERSION};
if [ "$GIT_RELEASE_TAG" == "$GIT_LAST_TAG" ]; then
docker tag ${DAEMON}:_build ${DOCKER_USERNAME}/${DAEMON}:latest;
docker push ${DOCKER_USERNAME}/${DAEMON}:latest;
fi
fi
done