Tc #506
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: Build and publish to dockerhub (bleeding-edge, latest and releases) | |
docker-buildx-publish: | |
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 }} | |
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 | |
TAGS="$TAGS pushme" | |
echo "Deduced tags: $TAGS" | |
echo "TAGS=$TAGS" >> $GITHUB_ENV | |
- name: Build for platforms | |
run: | | |
echo "Building platforms: ${{ env.PLATFORMS }}..." | |
echo "Got tags from previous step: $TAGS" | |
cd docker && PLATFORMS="${{env.PLATFORMS}}" V=1 make | |
- name: Docker (compose) smoke test | |
if: ${{ env.PLATFORMS == 'linux/amd64' }} #TODO remove when ARM64 is supported | |
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: Tag and push to dockerhub | |
if: ${{ env.TAGS != '' }} | |
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 && PUSH=${{secrets.DOCKER_USERNAME}} TAGS="${TAGS}" PLATFORMS="${{env.PLATFORMS}}" V=1 make |