Skip to content

Commit

Permalink
Merge pull request #7 from hpidcock/release-oci-cron
Browse files Browse the repository at this point in the history
Action to test and publish merged juju-db images
  • Loading branch information
hpidcock authored Nov 22, 2022
2 parents 57702cf + b2ee43b commit 26a8667
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 35 deletions.
22 changes: 16 additions & 6 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Install dependencies
run: |
sudo apt update
sudo apt install -y make jq
wget https://github.com/mikefarah/yq/releases/download/v4.20.1/yq_linux_amd64 -O /usr/bin/yq &&\
chmod +x /usr/bin/yq
wget https://github.com/mikefarah/yq/releases/download/v4.20.1/yq_linux_amd64 -O yq
chmod +x yq
sudo chown root:root yq
sudo mv yq /usr/bin/yq
- id: set-matrix
run: |
echo "::set-output name=matrix::{\"image\": $(make images-json)}"
Expand All @@ -26,10 +30,14 @@ jobs:
matrix: ${{ fromJSON(needs.generate-matrix.outputs.matrix) }}
steps:
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
uses: docker/setup-buildx-action@v2
with:
config-inline: |
[worker.oci]
max-parallelism = 1
- name: Checkout
uses: actions/checkout@v2
Expand All @@ -38,8 +46,10 @@ jobs:
run: |
sudo apt update
sudo apt install -y make
wget https://github.com/mikefarah/yq/releases/download/v4.20.1/yq_linux_amd64 -O /usr/bin/yq &&\
chmod +x /usr/bin/yq
wget https://github.com/mikefarah/yq/releases/download/v4.20.1/yq_linux_amd64 -O yq
chmod +x yq
sudo chown root:root yq
sudo mv yq /usr/bin/yq
- name: Make build image ${{ matrix.image }}
run: |
Expand Down
70 changes: 51 additions & 19 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
name: build
name: release
on:
pull_request: {}
push:
branches:
- 'master'
- "master"
schedule:
- cron: '15 0 * * *'
- cron: "15 0 * * *"
jobs:
generate-matrix:
runs-on: ubuntu-latest
Expand All @@ -14,12 +13,16 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Install dependencies
run: |
sudo apt update
sudo apt install -y make jq
wget https://github.com/mikefarah/yq/releases/download/v4.20.1/yq_linux_amd64 -O /usr/bin/yq &&\
chmod +x /usr/bin/yq
wget https://github.com/mikefarah/yq/releases/download/v4.20.1/yq_linux_amd64 -O yq
chmod +x yq
sudo chown root:root yq
sudo mv yq /usr/bin/yq
- id: set-matrix
run: |
echo "::set-output name=matrix::{\"image\": $(make images-json)}"
Expand All @@ -31,10 +34,14 @@ jobs:
matrix: ${{ fromJSON(needs.generate-matrix.outputs.matrix) }}
steps:
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
uses: docker/setup-buildx-action@v2
with:
config-inline: |
[worker.oci]
max-parallelism = 1
- name: Checkout
uses: actions/checkout@v2
Expand All @@ -43,31 +50,56 @@ jobs:
run: |
sudo apt update
sudo apt install -y make
wget https://github.com/mikefarah/yq/releases/download/v4.20.1/yq_linux_amd64 -O /usr/bin/yq &&\
chmod +x /usr/bin/yq
wget https://github.com/mikefarah/yq/releases/download/v4.20.1/yq_linux_amd64 -O yq
chmod +x yq
sudo chown root:root yq
sudo mv yq /usr/bin/yq
- name: Make build image ${{ matrix.image }}
run: |
IMAGES=${{ matrix.image }} make build
- name: Install microk8s
run: |
sudo snap install microk8s
sudo snap install microk8s --channel 1.25-strict/stable
sudo microk8s.status --wait-ready
sudo microk8s.enable storage dns
sudo microk8s.status --wait-ready
sudo usermod -a -G snap_microk8s $USER
- name: Install juju snap
run: |
juju_test_channel=$(yq -o=t ".images.[\"${{ matrix.image }}\"].juju_test_channel" < images.yaml)
sudo snap install juju --channel=${juju_test_channel} || sudo snap install juju --channel=${juju_test_channel} --classic || sudo snap refresh juju --channel=${juju_test_channel}
juju_test_channel=$(yq ".images.[\"${{ matrix.image }}\"].juju_test_channel" < images.yaml)
sudo snap install juju --channel=${juju_test_channel} || sudo snap refresh juju --channel=${juju_test_channel}
echo "installed juju $(juju version)"
- name: Copy built image to microk8s.ctr
run: |
IMAGES=${{ matrix.image }} make microk8s-import
IMAGES=${{ matrix.image }} make microk8s-image-update
- name: Bootstrap juju into microk8s
run: |
juju bootstrap microk8s
juju status
# TODO: publish the image here.
sg snap_microk8s <<'EOF'
juju bootstrap microk8s
juju status -m controller
image_tag="$(microk8s.kubectl -n controller-microk8s-localhost get pod controller-0 -o json | jq -r '.status.containerStatuses | map(select(.name=="mongodb"))[0].image')"
expected_image_id="$(docker inspect ${image_tag} --format {{.ID}})"
got_image_id="$(microk8s.kubectl -n controller-microk8s-localhost get pod controller-0 -o json | jq -r '.status.containerStatuses | map(select(.name=="mongodb"))[0].imageID')"
echo "image ${image_tag} built as ${expected_image_id}"
echo "image ${image_tag} used as ${got_image_id}"
if [ "${expected_image_id}" != "${got_image_id}" ]; then
echo "${got_image_id} does not match expected ${expected_image_id}"
exit 1
fi
EOF
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Push images
if: ${{ success() && github.ref == 'refs/heads/master' }}
run: |
IMAGES=${{ matrix.image }} make push
14 changes: 7 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
# Licensed under the AGPLv3, see LICENCE file for details.

BUILD_IMAGE=bash -c '. "./make_functions.sh"; build_image "$$@"' build_image
IMPORT_MICROK8S=bash -c '. "./make_functions.sh"; import_microk8s "$$@"' import_microk8s
MICROK8S_IMAGE_UPDATE=bash -c '. "./make_functions.sh"; microk8s_image_update "$$@"' microk8s_image_update
IMAGES?=$(shell yq -o=t '.images | keys' < images.yaml)

default: build

microk8s-import: .build-test $(patsubst %,.microk8s-import/%,$(IMAGES))
.microk8s-import/%:
$(IMPORT_MICROK8S) "$(@:.microk8s-import/%=%)"
microk8s-image-update: .build-test $(patsubst %,.microk8s-image-update/%,$(IMAGES))
.microk8s-image-update/%:
$(MICROK8S_IMAGE_UPDATE) "$(@:.microk8s-image-update/%=%)"
.build-test: OUTPUT_TYPE=type=docker
IS_LOCAL=1
.build-test: IS_LOCAL=1
.build-test: $(IMAGES)

build: OUTPUT_TYPE=type=image,push=false
Expand All @@ -31,9 +31,9 @@ push: $(IMAGES)

.PHONY: default
.PHONY: build
.PHONY: microk8s-import
.PHONY: microk8s-image-update
.PHONY: .build-test
.PHONY: .microk8s-import/%
.PHONY: .microk8s-image-update/%
.PHONY: check
.PHONY: push
.PHONY: %
Expand Down
6 changes: 3 additions & 3 deletions make_functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ build_image() {
if [[ "${is_local}" -eq 1 ]]; then
cmd_platforms=""
else
cmd_platforms="--platform \"${platforms}\""
cmd_platforms="--platform ${platforms}"
fi

echo "Building ${image} for build args \"$build_args\" and platforms \"$platforms\""
Expand All @@ -60,7 +60,7 @@ build_image() {
-f "$dockerfile" . ${cmd_tags} -o "$output" --progress=auto
}

import_microk8s() {
microk8s_image_update() {
image=${1-""}
if [ -z "$image" ]; then
echo "You must supply the image to build in images.yaml"
Expand All @@ -70,7 +70,7 @@ import_microk8s() {
tags=$(yq -o=c ".images.[\"${image}\"].tags" < images.yaml)
for reg_path in ${reg_paths//,/ }; do
for tag in ${tags//,/ }; do
docker save "${reg_path}:${tag}" | microk8s.ctr --namespace k8s.io image import -
docker save "${reg_path}:${tag}" | sudo microk8s.ctr --namespace k8s.io image import -
done
done
}

0 comments on commit 26a8667

Please sign in to comment.