-
Notifications
You must be signed in to change notification settings - Fork 2
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Contributing | ||
|
||
To make contributions to this rock, the only significant changes to be made are in the `Makefile` and the `build/` directory | ||
|
||
## Upgrading the components | ||
|
||
To Upgrade the rocks for new releases of coredns run the following make target: | ||
|
||
```shell | ||
make update-component | ||
``` | ||
|
||
* if `jq` or `yq` are not installed on the system, they will be when the target for those items runs | ||
* this will clone the upstream coredns/coredns repo only for listing tags | ||
* it will create a new rockcraft yaml based on the tags missing from this repo | ||
* Raise a PR from a branch with the new rockcraft.yaml files | ||
|
||
|
||
## Testing | ||
|
||
To test the rocks, run the pytest sanity check test | ||
|
||
```shell | ||
cd tests | ||
tox -e sanity | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# Makefile for CoreDNS Rock | ||
# Description: This Makefile installs necessary tools and updates components. | ||
|
||
which_jq = $(shell which jq) | ||
which_yq = $(shell which yq) | ||
COREDNS_GIT_DIR = /tmp/coredns.git | ||
|
||
.PHONY: JQ | ||
JQ: | ||
@if [ -z "${which_jq}" ]; then \ | ||
echo "Installing jq..."; \ | ||
sudo apt-get update && sudo apt-get install -y jq; \ | ||
else \ | ||
echo "jq is installed @ ${which_jq}"; \ | ||
fi | ||
|
||
.PHONY: YQ | ||
YQ: | ||
@if [ -z "$(which_yq)" ]; then \ | ||
echo "Installing yq..."; \ | ||
sudo snap install yq; \ | ||
else \ | ||
echo "yq is installed @ ${which_yq}"; \ | ||
fi | ||
|
||
.PHONY: install-tools | ||
install-tools: JQ YQ | ||
@echo "Tools installed." | ||
|
||
.PHONY: clone-CoreDNS | ||
clone-CoreDNS: | ||
@echo "Cloning CoreDNS..." | ||
@if [ -d $(COREDNS_GIT_DIR) ]; then \ | ||
echo "CoreDNS already cloned."; \ | ||
else \ | ||
mkdir -p $(COREDNS_GIT_DIR); \ | ||
git clone --bare --filter=blob:none --no-checkout https://github.com/coredns/coredns.git $(COREDNS_GIT_DIR); \ | ||
fi | ||
|
||
.PHONY: update-component | ||
update-component: install-tools clone-CoreDNS | ||
@echo "Updating component..." | ||
@COREDNS_GIT_DIR=$(COREDNS_GIT_DIR) build/craft_release.sh | ||
|
||
# Target to remove the temporary directory | ||
clean: | ||
@rm -rf $(COREDNS_GIT_DIR) | ||
@echo "Temporary directory removed: $(COREDNS_GIT_DIR)" | ||
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,82 @@ | ||||||
#!/bin/bash | ||||||
|
||||||
# This script is used to create a new release rock image from the included template | ||||||
set -eu | ||||||
|
||||||
RO_SCRIPT_DIR="$( dirname "${BASH_SOURCE[0]}")" | ||||||
RO_REPO_DIR=$(dirname ${RO_SCRIPT_DIR}) | ||||||
RO_VERSIONS=${RO_SCRIPT_DIR}/../versions.txt | ||||||
|
||||||
function usage() { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not really "usage", more of a environment check |
||||||
if [[ -z ${COREDNS_GIT_DIR+x} ]]; then | ||||||
echo "COREDNS_GIT_DIR is not set" > /dev/stderr | ||||||
echo " Clone with 'git clone --bare --filter=blob:none --no-checkout https://github.com/coredns/coredns.git /tmp/coredns.git'" > /dev/stderr | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
echo " Re-run with 'COREDNS_GIT_DIR=/tmp/coredns.git $0'" > /dev/stderr | ||||||
exit 1 | ||||||
fi | ||||||
} | ||||||
|
||||||
|
||||||
function check_dependencies(){ | ||||||
for cmd in yq jq git envsubst; do | ||||||
if ! command -v $cmd &> /dev/null; then | ||||||
echo "$cmd could not be found" > /dev/stderr | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
exit 1 | ||||||
fi | ||||||
done | ||||||
} | ||||||
|
||||||
|
||||||
function create_rockcrafts(){ | ||||||
# Get the current releases from existing rockcraft yamls | ||||||
if [[ -v GITHUB_WORKSPACE ]]; then | ||||||
echo "::group::Create rockcrafts" | ||||||
fi | ||||||
|
||||||
rm -rf ${RO_VERSIONS} | ||||||
for rockcraft in $(find ${RO_REPO_DIR} -name 'rockcraft.yaml'); do | ||||||
echo $(yq '.version' $rockcraft) >> ${RO_VERSIONS} | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. echo not needed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so? it seems this is required. Without it yq '.version' $rockcraft >> ${RO_VERSIONS} i get an error:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think it's due to snap confinement when yq is installed via snap |
||||||
done | ||||||
current_releases=( $(sort -V ${RO_VERSIONS}) ) | ||||||
min_tag="v${current_releases[0]}" # this is the oldest release tag we support | ||||||
rm -rf ${RO_VERSIONS} | ||||||
|
||||||
# Get the tags from the coredns repo, ignoring all before the min_tag | ||||||
coredns_tags=( $(git -C ${COREDNS_GIT_DIR} tag --sort=v:refname | sed -n '/'${min_tag}'/,$p') ) | ||||||
new_tags=() | ||||||
|
||||||
for coredns_tag in "${coredns_tags[@]}"; do | ||||||
if [[ ! -e ${RO_REPO_DIR}/${coredns_tag:1}/rockcraft.yaml ]]; then | ||||||
new_tag=${coredns_tag:1} | ||||||
new_tags+=($new_tag) | ||||||
echo "Creating rockcraft.yaml for ${new_tag}" | ||||||
mkdir -p ${RO_REPO_DIR}/${new_tag} | ||||||
unset ignored_template_var | ||||||
tag=${new_tag} envsubst < ${RO_SCRIPT_DIR}/template/rockcraft.yaml.in > ${RO_REPO_DIR}/${new_tag}/rockcraft.yaml | ||||||
else | ||||||
echo "Skipping ${coredns_tag} as it already exists" | ||||||
fi | ||||||
done | ||||||
|
||||||
if [ ${#new_tags[@]} -eq 0 ]; then | ||||||
tags='[]' | ||||||
else | ||||||
tags=$(printf '%s\n' "${new_tags[@]}" | jq -R . | jq --compact-output -s .) | ||||||
fi | ||||||
if [[ -v GITHUB_OUTPUT ]]; then | ||||||
echo "tags=$tags" >> $GITHUB_OUTPUT | ||||||
fi | ||||||
if [[ -v GITHUB_WORKSPACE ]]; then | ||||||
echo "::endgroup::" | ||||||
fi | ||||||
|
||||||
} | ||||||
|
||||||
addyess marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
function main() { | ||||||
usage | ||||||
check_dependencies | ||||||
create_rockcrafts | ||||||
addyess marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
} | ||||||
|
||||||
main | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. EOF |
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 $${ignored_template_var}CRAFT_PART_BUILD/coredns $${ignored_template_var}CRAFT_PRIME |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
newline at eof