-
Notifications
You must be signed in to change notification settings - Fork 25
125 lines (107 loc) · 3.74 KB
/
build-and-test.yml
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
name: Build and test Docker images
on:
pull_request:
branches:
- master
paths-ignore:
- "*.md"
- 'LICENSE'
- 'docs/'
- '.gitignore'
- 'docker-compose.yml'
- 'Makefile'
env:
IMAGE_PREFIX: localhost:5000/brettt89/silverstripe-web
REGISTRY_PATH: ${{ github.workspace }}/registry
CACHE_PATH: /tmp/.buildx-cache
jobs:
build:
name: Build
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
os: [bookworm, bullseye, alpine]
php: ['8.1', '8.2', '8.3']
distro: [apache, fpm, cli]
exclude:
- os: alpine
distro: apache
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
with:
driver-opts: network=host
- name: Start Docker registry
run: |
docker run --rm --detach --publish 5000:5000 \
--volume ${REGISTRY_PATH}:/var/lib/registry \
--name registry registry:2
- name: Build silverstripe docker image
uses: docker/[email protected]
with:
context: src/${{ matrix.php }}/${{ matrix.distro }}/${{ matrix.os }}
platforms: linux/amd64,linux/arm64
cache-from: type=gha,scope=${{ matrix.php }}-${{ matrix.distro }}-${{ matrix.os }}
cache-to: type=gha,scope=${{ matrix.php }}-${{ matrix.distro }}-${{ matrix.os }}
push: true
tags: ${{ env.IMAGE_PREFIX }}:${{ matrix.php }}-${{ matrix.distro }}-${{ matrix.os }}-test
- name: Stop Docker registry
run: docker stop registry
- name: Upload Docker registry data for testing
uses: actions/upload-artifact@v3
with:
name: docker-registry-data-${{ matrix.php }}-${{ matrix.distro }}-${{ matrix.os }}
path: ${{ env.REGISTRY_PATH }}/
test:
name: Test
runs-on: ubuntu-latest
needs: build
strategy:
matrix:
platform: [linux/amd64, linux/arm64]
os: [bookworm, bullseye, alpine]
php: ['8.1', '8.2', '8.3']
distro: [apache, fpm, cli]
exclude:
- os: alpine
distro: apache
env:
PLATFORM: ${{ matrix.platform }}
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Download Docker registry data from build job
uses: actions/download-artifact@v3
with:
name: docker-registry-data-${{ matrix.php }}-${{ matrix.distro }}-${{ matrix.os }}
path: ${{ env.REGISTRY_PATH }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Start Docker registry
run: |
docker run --rm --detach --publish 5000:5000 \
--volume ${REGISTRY_PATH}:/var/lib/registry \
--name registry registry:2
sleep 10
- name: Import Docker images
run: docker pull --platform ${{ matrix.platform }} ${{ env.IMAGE_PREFIX }}:${{ matrix.php }}-${{ matrix.distro }}-${{ matrix.os }}-test
- name: Docker inspect
run: docker buildx imagetools inspect ${{ env.IMAGE_PREFIX }}:${{ matrix.php }}-${{ matrix.distro }}-${{ matrix.os }}-test | grep '${{ matrix.platform }}'
- id: test
uses: ./.github/actions/build-test
with:
image: ${{ env.IMAGE_PREFIX }}:${{ matrix.php }}-${{ matrix.distro }}-${{ matrix.os }}-test
platform: ${{ matrix.platform }}
php: ${{ matrix.php }}
distro: ${{ matrix.distro }}
os: ${{ matrix.os }}
- name: Cleanup
run: |
docker stop registry