tbs ci #521
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 3.1: test that local single-platform builds work fine | |
docker-build-test-local: | |
runs-on: ubuntu-22.04 | |
steps: | |
- name: Checkout pmacct | |
uses: actions/checkout@v1 #Don't use v2 messes everything | |
with: | |
path: pmacct | |
- name: Build single-platform | |
run: | | |
cd docker && V=1 make | |
- 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 | |
sleep 300 | |
echo "success" > $GITHUB_WORKSPACE/.docker-build-test-local.status | |
### Step 3.2: Build test and publish (bleeding-edge, latest and releases) | |
docker-build-test-publish: | |
runs-on: ubuntu-22.04 | |
env: | |
PLATFORMS: linux/amd64 #,linux/arm64 | |
steps: | |
- name: Checkout pmacct | |
uses: actions/checkout@v1 #Don't use v2 messes everything | |
with: | |
path: pmacct | |
- name: Deduce PMACCT version and tags | |
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*") | |
#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'..." | |
TAGS = "$TAGS 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'..." | |
TAGS = "$TAGS $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'..." | |
TAGS = "$TAGS latest" | |
else | |
echo "NOT uploading 'latest'..." | |
fi | |
else | |
echo "NOT uploading '$GIT_RELEASE_TAG' nor 'latest'. Not a release!" | |
fi | |
#Summarize deduced tags | |
echo "Deduced tags: $TAGS" | |
echo "TAGS=$TAGS" >> $GITHUB_ENV | |
- name: Get Runner's IP Address | |
run: | | |
RUNNER_IP=$(hostname -I | awk '{print $1}') | |
echo "RUNNER_IP=$RUNNER_IP" >> $GITHUB_ENV | |
echo "Deduced RUNNER_IP: $RUNNER_IP" | |
- name: Spawn docker registry | |
run: | | |
echo "Instruct dockerd to trust $RUNNER_IP:5000 as an insecure registry..." | |
sudo mkdir -p /etc/docker | |
echo "{ | |
\"insecure-registries\": [\"http://$RUNNER_IP:5000\"] | |
}" | sudo tee /etc/docker/daemon.json > /dev/null | |
sudo systemctl restart docker | |
echo "Starting temporary docker registry..." | |
docker run -d -p 5000:5000 --name registry registry:2 | |
- name: Build for platforms | |
run: | | |
echo "Building platforms: ${{ env.PLATFORMS }}..." | |
echo "Got tags from previous step: $TAGS" | |
cd docker && BUILD_REGISTRY=$RUNNER_IP:5000 PLATFORMS="${{env.PLATFORMS}}" V=1 make | |
- name: Docker (compose) smoke test | |
run: | | |
echo "Running smoke test using docker compose..." | |
export DOCKER_OPTS="--insecure-registry $RUNNER_IP:5000" | |
TAG=_build REPO=$RUNNER_IP:5000/ 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 | |
# Note: we do this to start this job asap, but we don't want to push | |
# unless tests have passed. At this point, given the xbuild time, tests | |
# _should_ have finished. Nevertheless, give some time. | |
- name: Wait and check that tests have completed before pushing... | |
timeout-minutes: 1 | |
run: | | |
while [ ! -f $GITHUB_WORKSPACE/.docker-build-test-local.status ]; do | |
echo "Waiting for .docker-build-test-local.status to complete..." | |
sleep 5 | |
done | |
STATUS=$(cat $GITHUB_WORKSPACE/.docker-build-test-local.status) | |
echo "docker-build-test-local status: ${STATUS}" | |
[ "${STATUS}" == "success" ] | |
- name: Tag and push to dockerhub | |
if: ${{ github.event_name != 'pull_request' && vars.SKIP_DOCKERHUB_PUBLISH != 'true' && env.TAGS != '' }} | |
env: | |
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} | |
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} | |
run: | | |
echo "Logging in..."; | |
echo ${DOCKER_PASSWORD} | docker login -u ${DOCKER_USERNAME} --password-stdin | |
echo "Publishing platforms(archs): ${{ env.PLATFORMS }}..." | |
echo "Got tags from previous step: $TAGS" | |
cd docker && BUILD_REGISTRY=$RUNNER_IP:5000 PUSH=${{secrets.DOCKER_USERNAME}} TAGS="${TAGS}" PLATFORMS="${{env.PLATFORMS}}" V=1 make |