forked from pmacct/pmacct
-
Notifications
You must be signed in to change notification settings - Fork 0
156 lines (139 loc) · 6.3 KB
/
ci.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
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
env:
PLATFORMS: linux/amd64,linux/arm64
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