666c9e39d6fab4dcafe6d4d11f3928485c210299
[buildbot.git] / .github / workflows / build-push.yml
1 name: Build and push containers
2 on:
3 push:
4 branches:
5 - master
6 tags:
7 - 'v*'
8 pull_request:
9
10 env:
11 BUILDBOT_VERSION: 3.8.0
12
13 concurrency:
14 group: ${{ github.workflow }}-${{ github.ref }}
15 cancel-in-progress: ${{ github.event_name == 'pull_request' }}
16
17 jobs:
18 build-test-push:
19 name: Build, test and push containers
20 runs-on: ubuntu-latest
21
22 permissions:
23 packages: write
24
25 strategy:
26 fail-fast: ${{ github.event_name == 'pull_request' }}
27 matrix:
28 container_flavor:
29 - master
30 - worker
31
32 steps:
33 - name: Checkout
34 uses: actions/checkout@v3
35
36 - name: Environment variables
37 run: |
38 echo "GIT_SHA_SHORT=${GITHUB_SHA::8}" >> $GITHUB_ENV
39
40 - name: Build container and export it to local Docker
41 uses: docker/build-push-action@v4
42 with:
43 load: true
44 tags: local/${{ matrix.container_flavor }}
45 file: docker/build${{ matrix.container_flavor }}/Dockerfile
46 build-args: |
47 BUILDBOT_VERSION=${{ env.BUILDBOT_VERSION }}
48 OPENWRT_VERSION=${{ env.GIT_SHA_SHORT }}
49
50 - name: Test master Docker container
51 if: matrix.container_flavor == 'master'
52 run: |
53 docker run --detach --name test-master local/master
54 sleep 5
55 docker logs test-master | tee master.log
56 grep "buildmaster configured in /master" master.log
57
58 - name: Test worker Docker container
59 if: matrix.container_flavor == 'worker'
60 run: |
61 docker run --detach --env BUILDWORKER_NAME=X --env BUILDWORKER_PASSWORD=Y --name test-worker local/worker
62 sleep 5
63 docker logs test-worker | tee worker.log
64 grep "worker configured in /builder" worker.log
65
66 - name: Docker meta
67 id: meta
68 if: github.event_name != 'pull_request' || github.repository_owner != 'openwrt'
69 uses: docker/metadata-action@v4
70 with:
71 images: name=ghcr.io/${{ github.repository }}/build${{ matrix.container_flavor }}-v${{ env.BUILDBOT_VERSION }}
72
73 - name: Login to GitHub Container Registry
74 uses: docker/login-action@v2
75 if: github.event_name != 'pull_request' || github.repository_owner != 'openwrt'
76 with:
77 registry: ghcr.io
78 username: ${{ github.actor }}
79 password: ${{ secrets.GITHUB_TOKEN }}
80
81 - name: Build container again and push it
82 uses: docker/build-push-action@v4
83 if: github.event_name != 'pull_request' || github.repository_owner != 'openwrt'
84 with:
85 push: true
86 tags: ${{ steps.meta.outputs.tags }}
87 labels: ${{ steps.meta.outputs.labels }}
88 file: docker/build${{ matrix.container_flavor }}/Dockerfile
89 build-args: |
90 BUILDBOT_VERSION=${{ env.BUILDBOT_VERSION }}
91 OPENWRT_VERSION=${{ env.GIT_SHA_SHORT }}