@@ -107,40 +107,21 @@ jobs:
107
107
docker exec -i $CONTAINER_ID ./ci/script.sh
108
108
docker stop $CONTAINER_ID
109
109
110
- # ## Step 3: official docker image generation
111
- pmacct- docker :
110
+ # ## Step 3.1: test that local single-platform builds work fine
111
+ docker-build-test-local :
112
112
runs-on : ubuntu-22.04
113
113
steps :
114
114
- name : Checkout pmacct
115
- uses : actions/checkout@v4
115
+ uses : actions/checkout@v1 # Don't use v2 messes everything
116
116
with :
117
117
path : pmacct
118
- fetch-depth : 0
119
- fetch-tags : 1
120
118
121
- - name : Check DAEMONS env. variable...
119
+ - name : Build single-platform
122
120
run : |
123
- #Sanity, avoid regression #816
124
- N_DAEMONS="$(echo $DAEMONS | wc --words)"
125
- if [[ "${N_DAEMONS}" != "7" ]]; then
126
- echo "ERROR: invalid number of DAEMONS: ${N_DAEMONS}"
127
- exit 1
128
- fi
129
-
130
- - name : Build containers
131
- uses : ./pmacct/.github/actions/build_containers/
132
- with :
133
- daemons : ${{env.DAEMONS}}
134
-
135
- - name : Docker save images
136
- run : |
137
- echo "Saving images as artifacts..."
138
- mkdir -p /tmp/docker/
139
- docker save -o /tmp/docker/pmacct_docker_images.tar base:_build $(for DAEMON in ${DAEMONS};do echo "${DAEMON}:_build "; done)
121
+ cd docker && V=1 make
140
122
141
123
- name : Docker (compose) smoke test
142
124
run : |
143
- cd pmacct
144
125
echo "Running smoke test using docker compose..."
145
126
TAG=_build docker compose -f ci/smoke-test/docker-compose.yml up -d
146
127
sleep 10
@@ -151,51 +132,31 @@ jobs:
151
132
echo "Stopping containers..."
152
133
TAG=_build docker compose -f ci/smoke-test/docker-compose.yml down
153
134
154
- - name : Export pmacct docker images as an artifact
155
- uses : actions/upload-artifact@v4
156
- with :
157
- name : pmacct_docker_images
158
- retention-days : 1
159
- path : /tmp/docker
160
-
161
- # ## Step 4: Upload images to dockerhub (bleeding-edge, latest and releases)
162
- publish-dockerhub :
163
- needs : [pmacct-docker, build-and-test]
135
+ # ## Step 3.2: Build test and publish (bleeding-edge, latest and releases)
136
+ docker-multiplatform-build-test-publish :
164
137
runs-on : ubuntu-22.04
165
- if : github.event_name != 'pull_request' && vars.SKIP_DOCKERHUB_PUBLISH != 'true'
138
+ needs : [build-and-test, docker-build-test-local]
166
139
env :
167
- DOCKER_USERNAME : ${{ secrets.DOCKER_USERNAME }}
168
- DOCKER_PASSWORD : ${{ secrets.DOCKER_PASSWORD }}
140
+ PLATFORMS : linux/amd64,linux/arm64
169
141
steps :
170
- - uses : actions/download-artifact@v4
171
- with :
172
- name : pmacct_docker_images
173
- path : /tmp/docker
174
-
175
- - name : Import pmacct docker images in the local registry
176
- run : |
177
- docker load -i /tmp/docker/pmacct_docker_images.tar
178
-
179
142
- name : Checkout pmacct
180
143
uses : actions/checkout@v1 # Don't use v2 messes everything
181
144
with :
182
145
path : pmacct
183
146
184
- - name : Build and upload containers
147
+ - name : Deduce PMACCT version and tags
185
148
run : |
186
149
echo "Fix mess with tags in actions/checkout..."
187
150
git fetch -f && git fetch -f --tags
188
151
echo "Deducing PMACCT_VERSION..."
189
152
PMACCT_VERSION=$(git describe --abbrev=0 --match="v*")
190
- echo "PMACCT_VERSION=$PMACCT_VERSION"
191
- echo "Uploading to dockerhub ...";
192
- echo ${DOCKER_PASSWORD} | docker login -u ${DOCKER_USERNAME} --password-stdin;
193
153
194
154
#Always push bleeding-edge when pushed to master
195
155
GIT_IS_BLEEDING_EDGE=$( (git branch --all --contains HEAD | grep master ) || echo "")
196
156
echo "GIT_IS_BLEEDING_EDGE=$GIT_IS_BLEEDING_EDGE"
197
157
if [ "$GIT_IS_BLEEDING_EDGE" != "" ]; then
198
158
echo "Tagging and uploading 'bleeding-edge'..."
159
+ TAGS="$TAGS bleeding-edge"
199
160
else
200
161
echo "NOT uploading 'bleeding-edge'... Not HEAD of master"
201
162
fi
@@ -205,32 +166,69 @@ jobs:
205
166
if [ "$GIT_RELEASE_TAG" != "" ]; then
206
167
echo "GIT_RELEASE_TAG=$GIT_RELEASE_TAG"
207
168
echo "Tagging and uploading release '$GIT_RELEASE_TAG'..."
169
+ TAGS="$TAGS $GIT_RELEASE_TAG"
208
170
209
171
#Latest tag
210
172
GIT_LAST_TAG=$(git tag --sort=v:refname | tail -n 1);
211
173
echo "GIT_LAST_TAG=$GIT_LAST_TAG"
212
174
if [ "$GIT_RELEASE_TAG" == "$GIT_LAST_TAG" ]; then
213
175
echo "Tagging and uploading 'latest'..."
176
+ TAGS="$TAGS latest"
214
177
else
215
178
echo "NOT uploading 'latest'..."
216
179
fi
217
180
else
218
181
echo "NOT uploading '$GIT_RELEASE_TAG' nor 'latest'. Not a release!"
219
182
fi
220
183
221
- #Let's do it!
222
- EXT_DAEMONS="base ${DAEMONS}"
223
- for DAEMON in ${EXT_DAEMONS}; do
224
- if [ "$GIT_IS_BLEEDING_EDGE" != "" ]; then
225
- docker tag ${DAEMON}:_build ${DOCKER_USERNAME}/${DAEMON}:bleeding-edge;
226
- docker push ${DOCKER_USERNAME}/${DAEMON}:bleeding-edge;
227
- fi
228
- if [ "$GIT_RELEASE_TAG" != "" ]; then
229
- docker tag ${DAEMON}:_build ${DOCKER_USERNAME}/${DAEMON}:${PMACCT_VERSION};
230
- docker push ${DOCKER_USERNAME}/${DAEMON}:${PMACCT_VERSION};
231
- if [ "$GIT_RELEASE_TAG" == "$GIT_LAST_TAG" ]; then
232
- docker tag ${DAEMON}:_build ${DOCKER_USERNAME}/${DAEMON}:latest;
233
- docker push ${DOCKER_USERNAME}/${DAEMON}:latest;
234
- fi
235
- fi
236
- done
184
+ #Summarize deduced tags
185
+ echo "Deduced tags: $TAGS"
186
+ echo "TAGS=$TAGS" >> $GITHUB_ENV
187
+
188
+ - name : Get Runner's IP Address
189
+ run : |
190
+ RUNNER_IP=$(hostname -I | awk '{print $1}')
191
+ echo "RUNNER_IP=$RUNNER_IP" >> $GITHUB_ENV
192
+ echo "Deduced RUNNER_IP: $RUNNER_IP"
193
+
194
+ - name : Spawn docker registry
195
+ run : |
196
+ echo "Instruct dockerd to trust $RUNNER_IP:5000 as an insecure registry..."
197
+ sudo mkdir -p /etc/docker
198
+ echo "{
199
+ \"insecure-registries\": [\"http://$RUNNER_IP:5000\"]
200
+ }" | sudo tee /etc/docker/daemon.json > /dev/null
201
+ sudo systemctl restart docker
202
+ echo "Starting temporary docker registry..."
203
+ docker run -d -p 5000:5000 --name registry registry:2
204
+
205
+ - name : Build for platforms
206
+ run : |
207
+ echo "Building platforms: ${{ env.PLATFORMS }}..."
208
+ echo "Got tags from previous step: $TAGS"
209
+ cd docker && BUILD_REGISTRY=$RUNNER_IP:5000 PLATFORMS="${{env.PLATFORMS}}" V=1 make
210
+
211
+ - name : Docker (compose) smoke test
212
+ run : |
213
+ echo "Running smoke test using docker compose..."
214
+ export DOCKER_OPTS="--insecure-registry $RUNNER_IP:5000"
215
+ TAG=_build REPO=$RUNNER_IP:5000/ docker compose -f ci/smoke-test/docker-compose.yml up -d
216
+ sleep 10
217
+ echo "Check that all containers are up and running, without restarts ..."
218
+ if [[ "$(docker inspect `docker ps -aq` | grep RestartCount | grep -v '\"RestartCount\": 0')" != "" ]]; then
219
+ echo "Some containers restarted!" && docker inspect `docker ps -aq` && /bin/false
220
+ fi
221
+ echo "Stopping containers..."
222
+ TAG=_build docker compose -f ci/smoke-test/docker-compose.yml down
223
+
224
+ - name : Tag and push to dockerhub
225
+ if : ${{ github.event_name != 'pull_request' && vars.SKIP_DOCKERHUB_PUBLISH != 'true' && env.TAGS != '' }}
226
+ env :
227
+ DOCKER_USERNAME : ${{ secrets.DOCKER_USERNAME }}
228
+ DOCKER_PASSWORD : ${{ secrets.DOCKER_PASSWORD }}
229
+ run : |
230
+ echo "Logging in...";
231
+ echo ${DOCKER_PASSWORD} | docker login -u ${DOCKER_USERNAME} --password-stdin
232
+ echo "Publishing platforms(archs): ${{ env.PLATFORMS }}..."
233
+ echo "Got tags from previous step: $TAGS"
234
+ cd docker && BUILD_REGISTRY=$RUNNER_IP:5000 PUSH=${{secrets.DOCKER_USERNAME}} TAGS="${TAGS}" PLATFORMS="${{env.PLATFORMS}}" V=1 make
0 commit comments