Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update coredns image tags automatically #21

Merged
merged 4 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 43 additions & 52 deletions .github/workflows/update_version.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,29 @@ on:
workflow_dispatch:
schedule:
- cron: "0 10 * * *"
pull_request:
branches:
- main

jobs:
generator:
name: Generate Step for new CoreDNS versions
runs-on: ubuntu-latest
outputs:
tags: ${{ steps.fetch-upstream.outputs.tags }}
steps:
- name: Prepare environment
run: |
export DEBIAN_FRONTEND=noninteractive
sudo apt-get -qq update
sudo apt-get -qq install -y jq
addyess marked this conversation as resolved.
Show resolved Hide resolved
sudo snap install yq
- name: Checkout rock repository
uses: actions/checkout@v4
with:
path: coredns-rock
ref: main
ref: ${{ github.head_ref || 'main' }}

- name: Checkout coredns repository
uses: actions/checkout@v4
Expand All @@ -25,70 +36,50 @@ jobs:
fetch-tags: true
fetch-depth: 0

- name: Get current version from rockcraft.yaml
id: currentRockVersion
uses: mikefarah/yq@master
with:
cmd: yq '.version' 'coredns-rock/rockcraft.yaml'

- name: Fetch and filter upstream tags
- name: Itemize all releases
id: releases
run: |
rm -rf versions.txt
for rockcraft in $(find coredns-rock -name 'rockcraft.yaml'); do
echo $(yq '.version' $rockcraft) >> versions.txt
done
- name: Craft from Upstream tags
id: fetch-upstream
run: |
export DEBIAN_FRONTEND=noninteractive
sudo apt-get -qq update
sudo apt-get -qq install -y jq
min_tag="v${{ steps.currentRockVersion.outputs.result }}"
coredns_tags=( $(git -C coredns tag --sort=-v:refname) )
pr_tags=()
current_releases=( $(sort -V versions.txt) )
min_tag="v${current_releases[0]}"
coredns_tags=( $(git -C coredns tag --sort=v:refname | sed -n '/'${min_tag}'/,$p') )
new_tags=()
for coredns_tag in "${coredns_tags[@]}"
do
if [ "$min_tag" = "$coredns_tag" ]; then
break
fi
pr_tags+=( "${coredns_tag:1}" )
if [[ ! -e coredns-rock/${coredns_tag:1}/rockcraft.yaml ]]; then
new_tag=${coredns_tag:1}
new_tags+=($new_tag)
mkdir -p coredns-rock/${new_tag}
tag=${new_tag} envsubst < coredns-rock/template/rockcraft.yaml.in > coredns-rock/${new_tag}/rockcraft.yaml
fi
done
if [ ${#pr_tags[@]} -eq 0 ]; then
if [ ${#new_tags[@]} -eq 0 ]; then
tags='[]'
else
tags=$(printf '%s\n' "${pr_tags[@]}" | jq -R . | jq --compact-output -s .)
tags=$(printf '%s\n' "${new_tags[@]}" | jq -R . | jq --compact-output -s .)
fi
echo $tags
echo "tags=$tags" >> $GITHUB_OUTPUT
update:
runs-on: ubuntu-latest
needs: generator
if: ${{ needs.generator.outputs.tags != '[]' }}
strategy:
matrix:
version: ${{ fromJSON(needs.generator.outputs.tags) }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: main

- name: Update ROCK's source tag
uses: mikefarah/yq@master
with:
cmd: yq -i '.parts.coredns.source-tag = "v${{ matrix.version }}"' 'rockcraft.yaml'

- name: Update ROCK's version
uses: mikefarah/yq@master
- name: Commit and push new rockcraft.yaml
id: commit-rockcraft
if: ${{ steps.fetch-upstream.outputs.tags != '[]' }}
uses: peter-evans/create-pull-request@v7
with:
cmd: yq -i '.version = "${{ matrix.version }}"' 'rockcraft.yaml'

- name: Create pull request
uses: peter-evans/create-pull-request@v6
with:
commit-message: Update CoreDNS version to ${{ matrix.version }}
title: "[${{ matrix.version }}] Update CoreDNS version"
body: Update CoreDNS version to ${{ matrix.version }}
branch: v${{ matrix.version }}
commit-message: Update CoreDNS versions with ${{ join(fromJSON(steps.fetch-upstream.outputs.tags), ', ') }}
title: "Update CoreDNS versions"
body: Update CoreDNS versions with ${{ join(fromJSON(steps.fetch-upstream.outputs.tags), ', ') }}
path: coredns-rock
branch: autoupdate/sync/coredns
delete-branch: true
base: main
37 changes: 37 additions & 0 deletions template/rockcraft.yaml.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: coredns
summary: ROCK for the CoreDNS Project.
description: This ROCK is a drop in replacement for the coredns/coredns image.
version: "${tag}"
license: Apache-2.0

base: bare
build-base: [email protected]
platforms:
amd64:
arm64:

entrypoint-service: coredns
services:
coredns:
override: replace
summary: "coredns service"
startup: enabled
command: "/coredns [ -conf /etc/coredns/Corefile ]"
on-failure: shutdown

parts:
coredns:
plugin: nil
source: https://github.com/coredns/coredns
source-type: git
source-tag: v${tag}
source-depth: 1
build-packages:
- build-essential
build-snaps:
- go/1.21/stable
stage-packages:
- ca-certificates_data
override-build: |
make
cp $CRAFT_PART_BUILD/coredns $CRAFT_PRIME
14 changes: 13 additions & 1 deletion tests/sanity/test_rock.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,23 @@
# Copyright 2024 Canonical, Ltd.
#

from pathlib import Path

import pytest
import yaml
from k8s_test_harness.util import docker_util, env_util

TEST_PATH = Path(__file__)
REPO_PATH = TEST_PATH.parent.parent.parent


def _image_versions():
all_rockcrafts = REPO_PATH.glob("**/rockcraft.yaml")
yamls = [yaml.safe_load(rock.read_bytes()) for rock in all_rockcrafts]
return [rock["version"] for rock in yamls]


@pytest.mark.parametrize("image_version", ["1.11.1", "1.11.3"])
@pytest.mark.parametrize("image_version", _image_versions())
def test_sanity(image_version):
rock = env_util.get_build_meta_info_for_rock_version(
"coredns", image_version, "amd64"
Expand Down
Loading