Skip to content

Commit

Permalink
Update coredns images automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
addyess committed Dec 2, 2024
1 parent cb0b3c2 commit a2cc206
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 52 deletions.
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
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

0 comments on commit a2cc206

Please sign in to comment.