From 0f2b7f7d2aaabc65481322bf8e93f401265b58f3 Mon Sep 17 00:00:00 2001 From: Arthur Meyre Date: Fri, 27 Aug 2021 11:50:06 +0200 Subject: [PATCH] build: allow docker base image build triggered by API call - add a polling script to check packages versions regularly and rebuild if the compiler image is more recent --- .github/workflows/docker-env.yaml | 5 ++++ .github/workflows/package-watcher.yaml | 41 ++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 .github/workflows/package-watcher.yaml diff --git a/.github/workflows/docker-env.yaml b/.github/workflows/docker-env.yaml index 696e23f0b..bf6a7b069 100644 --- a/.github/workflows/docker-env.yaml +++ b/.github/workflows/docker-env.yaml @@ -10,6 +10,11 @@ on: # Allows you to run this workflow manually from the Actions tab workflow_dispatch: + # Allows external webhook trigger + repository_dispatch: + types: + - rebuild-docker + jobs: build_publish: concurrency: diff --git a/.github/workflows/package-watcher.yaml b/.github/workflows/package-watcher.yaml new file mode 100644 index 000000000..5e251436c --- /dev/null +++ b/.github/workflows/package-watcher.yaml @@ -0,0 +1,41 @@ +name: Package Version Checker + +on: + schedule: + # * is a special character in YAML so you have to quote this string + # At minute 0 for each hour from 8:00 to 22:00 inclusive from Monday to Friday inclusive + - cron: '0 8-22 * * 1-5' + +jobs: + check_and_notify_build: + name: Check timestamps and notify build + runs-on: ubuntu-20.04 + env: + BASE_IMG_ENDPOINT_URL: "https://api.github.com/orgs/zama-ai/packages/container/zamalang-compiler" + ENV_IMG_ENDPOINT_URL: "https://api.github.com/orgs/zama-ai/packages/container/hdk-env" + steps: + - name: Compare image timestamps and notify + - run: | + BASE_IMG_TIMESTAMP=$(curl \ + -X GET \ + -H "Accept: application/vnd.github.v3+json" \ + -H "Authorization: token ${{ secrets.BOT_TOKEN }}" \ + "${BASE_IMG_ENDPOINT_URL}" | jq -r '.updated_at') + ENV_IMG_TIMESTAMP=$(curl \ + -X GET \ + -H "Accept: application/vnd.github.v3+json" \ + -H "Authorization: token ${{ secrets.BOT_TOKEN }}" \ + "${ENV_IMG_ENDPOINT_URL}" | jq -r '.updated_at') + BASE_IMG_DATE=$(date -d ${BASE_IMG_TIMESTAMP} +%s) + ENV_IMG_DATE=$(date -d ${ENV_IMG_TIMESTAMP} +%s) + if [[ "${BASE_IMG_DATE}" -ge "${ENV_IMG_DATE}" ]]; then + echo "Env image out of date, sending rebuild request." + curl \ + -X POST \ + -H "Accept: application/vnd.github.v3+json" \ + -H "Authorization: token ${{ secrets.BOT_TOKEN }}" \ + https://api.github.com/repos/zama-ai/hdk/dispatches \ + -d '{"event_type":"rebuild-docker"}' + else + echo "Image up to date, nothing to do." + fi