|
1 | 1 | name: build |
2 | 2 | on: |
3 | 3 | pull_request: {} |
| 4 | + workflow_dispatch: |
4 | 5 | jobs: |
5 | 6 | generate-matrix: |
6 | 7 | runs-on: ubuntu-latest |
|
43 | 44 | sudo apt install -y make jq |
44 | 45 | sudo snap install yq |
45 | 46 |
|
| 47 | + - name: Install microk8s |
| 48 | + run: | |
| 49 | + microk8s_test_channel=$(yq ".images.[\"${{ matrix.image }}\"].microk8s_test_channel" < images.yaml) |
| 50 | + sudo snap install microk8s --channel=${microk8s_test_channel} || sudo snap install microk8s --channel=${microk8s_test_channel} --classic |
| 51 | + sudo microk8s.status --wait-ready |
| 52 | + sudo microk8s.enable storage dns |
| 53 | + sudo microk8s.status --wait-ready |
| 54 | + microk8s_group=microk8s |
| 55 | + if getent group snap_microk8s; then |
| 56 | + microk8s_group=snap_microk8s |
| 57 | + fi |
| 58 | + sudo usermod -a -G "${microk8s_group}" "${USER}" |
| 59 | +
|
46 | 60 | - name: Make build image ${{ matrix.image }} |
47 | 61 | run: | |
48 | 62 | IMAGES=${{ matrix.image }} make build |
| 63 | +
|
| 64 | + - name: Install juju snap |
| 65 | + run: | |
| 66 | + juju_test_channel=$(yq ".images.[\"${{ matrix.image }}\"].juju_test_channel" < images.yaml) |
| 67 | + sudo snap install juju --channel=${juju_test_channel} || sudo snap install juju --channel=${juju_test_channel} --classic |
| 68 | + echo "installed juju $(juju version)" |
| 69 | +
|
| 70 | + - name: Copy built image to microk8s.ctr |
| 71 | + run: | |
| 72 | + IMAGES=${{ matrix.image }} make microk8s-image-update |
| 73 | +
|
| 74 | + - name: Bootstrap juju into microk8s |
| 75 | + run: | |
| 76 | + microk8s_group=microk8s |
| 77 | + if getent group snap_microk8s; then |
| 78 | + microk8s_group=snap_microk8s |
| 79 | + fi |
| 80 | + $(echo sudo su $USER -G ${microk8s_group} -g $(groups | sed "s/\s/ -G /g")) <<'EOF' |
| 81 | + series=$(yq ".images.[\"${{ matrix.image }}\"].series" < images.yaml) |
| 82 | + juju bootstrap microk8s |
| 83 | + juju status -m controller |
| 84 | + juju add-model test |
| 85 | + juju deploy ./test-charm --series "${series}" |
| 86 | +
|
| 87 | + until juju status | grep -q "Image is all good."; do |
| 88 | + sleep 1 |
| 89 | + juju status |
| 90 | + done |
| 91 | +
|
| 92 | + image_tag="$(microk8s.kubectl -n test get pod ubuntu-test-0 -o json | jq -r '.status.containerStatuses | map(select(.name=="charm"))[0].image')" |
| 93 | + expected_image_id="$(docker inspect ${image_tag} --format {{.ID}})" |
| 94 | + got_image_id="$(microk8s.kubectl -n test get pod ubuntu-test-0 -o json | jq -r '.status.containerStatuses | map(select(.name=="charm"))[0].imageID')" |
| 95 | + echo "image ${image_tag} built as ${expected_image_id}" |
| 96 | + echo "image ${image_tag} used as ${got_image_id}" |
| 97 | + if [ "${expected_image_id}" != "${got_image_id}" ]; then |
| 98 | + echo "${got_image_id} does not match expected ${expected_image_id}" |
| 99 | + exit 1 |
| 100 | + fi |
| 101 | + EOF |
0 commit comments