ci #2462
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: | |
push: | |
pull_request: | |
schedule: | |
- cron: '0 0 * * *' # every day at midnight | |
#Global vars | |
env: | |
#TODO: avoid duplicity ci/regression_tests | |
DAEMONS: "pmacctd nfacctd sfacctd uacctd pmbgpd pmbmpd pmtelemetryd" | |
jobs: | |
### Step 1: build container images | |
builder-docker: | |
runs-on: ubuntu-22.04 | |
strategy: | |
fail-fast: false | |
matrix: | |
builder-name: [ ubuntu-focal, ubuntu-jammy, rockylinux-8, rockylinux-9 ] | |
steps: | |
- name: Checkout pmacct | |
uses: actions/checkout@v4 | |
with: | |
path: pmacct | |
- name: Build docker image for ${{ matrix.builder-name }} | |
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 ci/Dockerfile-${{ matrix.builder-name }}-for-pmacct -t builder_${{ matrix.builder-name }} . | |
mkdir -p /tmp/docker/ | |
docker save -o /tmp/docker/builder_${{ matrix.builder-name }}.tar builder_${{ matrix.builder-name }} | |
- name: Artifact docker image | |
uses: actions/upload-artifact@v4 | |
with: | |
name: builder_${{ matrix.builder-name }} | |
retention-days: 1 | |
path: | | |
/tmp/docker | |
### Step 2: permutations | |
build-and-test: | |
needs: [builder-docker] | |
runs-on: ubuntu-22.04 | |
strategy: | |
fail-fast: false | |
matrix: | |
builder-name: [ ubuntu-focal, ubuntu-jammy, rockylinux-8, rockylinux-9 ] | |
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-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-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: 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@v4 | |
with: | |
name: builder_${{ matrix.builder-name }} | |
path: /tmp/docker | |
- name: List contents of /tmp/docker | |
run: | | |
ls -la /tmp/docker | |
- name: Checkout pmacct | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
path: pmacct | |
- name: Build in 'builder_${{ 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/builder_${{ matrix.builder-name }}.tar | |
CONTAINER_ID=$(docker run --rm -it -d -v `pwd`:`pwd` -w `pwd` -e CONFIG_FLAGS builder_${{ matrix.builder-name }}: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-22.04 | |
steps: | |
- name: Checkout pmacct | |
uses: actions/checkout@v4 | |
with: | |
path: pmacct | |
fetch-depth: 0 | |
fetch-tags: 1 | |
- name: Check DAEMONS env. variable... | |
run: | | |
#Sanity, avoid regression #816 | |
N_DAEMONS="$(echo $DAEMONS | wc --words)" | |
if [[ "${N_DAEMONS}" != "7" ]]; then | |
echo "ERROR: invalid number of DAEMONS: ${N_DAEMONS}" | |
exit 1 | |
fi | |
- name: Build containers | |
uses: ./pmacct/.github/actions/build_containers/ | |
with: | |
daemons: ${{env.DAEMONS}} | |
- name: Docker save images | |
run: | | |
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: | | |
cd pmacct | |
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/upload-artifact@v4 | |
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-22.04 | |
if: github.event_name != 'pull_request' && vars.SKIP_DOCKERHUB_PUBLISH != 'true' | |
env: | |
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} | |
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} | |
steps: | |
- uses: actions/download-artifact@v4 | |
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 |