-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move updating to a makefile based experience
- Loading branch information
Showing
5 changed files
with
154 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#!/bin/bash | ||
|
||
# This script is used to create a new release rock image from the included template | ||
set -eu | ||
|
||
SCRIPT_DIR="$( dirname "${BASH_SOURCE[0]}")" | ||
REPO_DIR=$(dirname ${SCRIPT_DIR}) | ||
VERSIONS=${SCRIPT_DIR}/../versions.txt | ||
|
||
function usage() { | ||
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 | ||
echo " Re-run with 'COREDNS_GIT_DIR=/tmp/coredns.git $0'" > /dev/stderr | ||
exit 1 | ||
fi | ||
} | ||
|
||
function create_rockcrafts(){ | ||
# Get the current releases from existing rockcraft yamls | ||
if [[ -v GITHUB_WORKSPACE ]]; then | ||
echo "::group::Create rockcrafts" | ||
fi | ||
|
||
rm -rf ${VERSIONS} | ||
for rockcraft in $(find ${REPO_DIR} -name 'rockcraft.yaml'); do | ||
echo $(yq '.version' $rockcraft) >> ${VERSIONS} | ||
done | ||
current_releases=( $(sort -V ${VERSIONS}) ) | ||
min_tag="v${current_releases[0]}" # this is the oldest release tag we support | ||
rm -rf ${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 ${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 ${REPO_DIR}/${new_tag} | ||
unset ignored_template_var | ||
tag=${new_tag} envsubst < ${SCRIPT_DIR}/template/rockcraft.yaml.in > ${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 | ||
|
||
} | ||
|
||
|
||
function main() { | ||
usage | ||
create_rockcrafts | ||
} | ||
|
||
main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters