Skip to content

Commit

Permalink
Merge branch 'main' into renovate/main-ghcr.io-onedr0p-sonarr-develop…
Browse files Browse the repository at this point in the history
…-4.x
  • Loading branch information
onedr0p authored Dec 22, 2023
2 parents 0f381ea + 64b4f40 commit 7218111
Show file tree
Hide file tree
Showing 114 changed files with 704 additions and 453 deletions.
1 change: 0 additions & 1 deletion .github/renovate.json5
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"extends": [
"config:recommended",
"docker:enableMajor",
"helpers:pinGitHubActionDigests",
"replacements:k8s-registry-move",
":automergeBranch",
":disableRateLimiting",
Expand Down
8 changes: 4 additions & 4 deletions .github/renovate/grafanaDashboards.json5
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"(^|/)kubernetes/.+\\.ya?ml(\\.j2)?$"
],
"matchStrings": [
"depName=\"(?<depName>\\S+)\"\\n.*?gnetId: (?<packageName>\\d+)\\n.*?revision: (?<currentValue>\\d+)"
"depName=\"(?<depName>.*)\"\\n.*?gnetId: (?<packageName>\\d+)\\n.*?revision: (?<currentValue>\\d+)"
],
"datasourceTemplate": "custom.grafana-dashboards",
"versioningTemplate": "regex:^(?<major>\\d+)$"
Expand All @@ -26,12 +26,12 @@
"packageRules": [
{
"addLabels": ["renovate/grafana-dashboard"],
"commitMessageExtra": "to revision {{newVersion}}",
"commitMessageTopic": "dashboard {{depName}}",
"matchDatasources": ["grafana-dashboards", "custom.grafana-dashboards"],
"matchUpdateTypes": ["major"],
"semanticCommitScope": "grafana-dashboards",
"semanticCommitType": "chore"
"semanticCommitType": "",
"commitMessageTopic": "dashboard {{depName}}",
"commitMessageExtra": "( {{currentVersion}} → {{newVersion}} )"
}
]
}
76 changes: 57 additions & 19 deletions .github/renovate/semanticCommits.json5
Original file line number Diff line number Diff line change
Expand Up @@ -4,112 +4,150 @@
{
"matchDatasources": ["docker"],
"matchUpdateTypes": ["major"],
"commitMessagePrefix": "feat(container)!: "
"commitMessagePrefix": "feat(container)!: ",
"commitMessageTopic": "{{depName}}",
"commitMessageExtra": " ( {{currentVersion}} → {{newVersion}} )"
},
{
"matchDatasources": ["docker"],
"matchUpdateTypes": ["minor"],
"semanticCommitType": "feat",
"semanticCommitScope": "container"
"semanticCommitScope": "container",
"commitMessageTopic": "{{depName}}",
"commitMessageExtra": "( {{currentVersion}} → {{newVersion}} )"
},
{
"matchDatasources": ["docker"],
"matchUpdateTypes": ["patch"],
"semanticCommitType": "fix",
"semanticCommitScope": "container"
"semanticCommitScope": "container",
"commitMessageTopic": "{{depName}}",
"commitMessageExtra": "( {{currentVersion}} → {{newVersion}} )"
},
{
"matchDatasources": ["docker"],
"matchUpdateTypes": ["digest"],
"semanticCommitType": "chore",
"semanticCommitScope": "container"
"semanticCommitScope": "container",
"commitMessageTopic": "{{depName}}",
"commitMessageExtra": "( {{currentDigestShort}} → {{newDigestShort}} )"
},
{
"matchDatasources": ["helm"],
"matchUpdateTypes": ["major"],
"commitMessagePrefix": "feat(helm)!: "
"commitMessagePrefix": "feat(helm)!: ",
"commitMessageTopic": "{{depName}}",
"commitMessageExtra": "( {{currentVersion}} → {{newVersion}} )"
},
{
"matchDatasources": ["helm"],
"matchUpdateTypes": ["minor"],
"semanticCommitType": "feat",
"semanticCommitScope": "helm"
"semanticCommitScope": "helm",
"commitMessageTopic": "{{depName}}",
"commitMessageExtra": "( {{currentVersion}} → {{newVersion}} )"
},

{
"matchDatasources": ["helm"],
"matchUpdateTypes": ["patch"],
"semanticCommitType": "fix",
"semanticCommitScope": "helm"
"semanticCommitScope": "helm",
"commitMessageTopic": "{{depName}}",
"commitMessageExtra": "( {{currentVersion}} → {{newVersion}} )"
},
{
"matchDatasources": ["galaxy", "galaxy-collection"],
"matchUpdateTypes": ["major"],
"commitMessagePrefix": "feat(ansible)!: "
"commitMessagePrefix": "feat(ansible)!: ",
"commitMessageTopic": "{{depName}}",
"commitMessageExtra": "( {{currentVersion}} → {{newVersion}} )"
},
{
"matchDatasources": ["galaxy", "galaxy-collection"],
"matchUpdateTypes": ["minor"],
"semanticCommitType": "feat",
"semanticCommitScope": "ansible"
"semanticCommitScope": "ansible",
"commitMessageTopic": "{{depName}}",
"commitMessageExtra": "( {{currentVersion}} → {{newVersion}} )"
},

{
"matchDatasources": ["galaxy", "galaxy-collection"],
"matchUpdateTypes": ["patch"],
"semanticCommitType": "fix",
"semanticCommitScope": "ansible"
"semanticCommitScope": "ansible",
"commitMessageTopic": "{{depName}}",
"commitMessageExtra": "( {{currentVersion}} → {{newVersion}} )"
},
{
"matchDatasources": ["terraform-provider"],
"matchUpdateTypes": ["major"],
"commitMessagePrefix": "feat(terraform)!: "
"commitMessagePrefix": "feat(terraform)!: ",
"commitMessageTopic": "{{depName}}",
"commitMessageExtra": "( {{currentVersion}} → {{newVersion}} )"
},
{
"matchDatasources": ["terraform-provider"],
"matchUpdateTypes": ["minor"],
"semanticCommitType": "feat",
"semanticCommitScope": "terraform"
"semanticCommitScope": "terraform",
"commitMessageTopic": "{{depName}}",
"commitMessageExtra": "( {{currentVersion}} → {{newVersion}} )"
},
{
"matchDatasources": ["terraform-provider"],
"matchUpdateTypes": ["patch"],
"semanticCommitType": "fix",
"semanticCommitScope": "terraform"
"semanticCommitScope": "terraform",
"commitMessageTopic": "{{depName}}",
"commitMessageExtra": "( {{currentVersion}} → {{newVersion}} )"
},
{
"matchDatasources": ["github-releases", "github-tags"],
"matchUpdateTypes": ["major"],
"commitMessagePrefix": "feat(github-release)!: "
"commitMessagePrefix": "feat(github-release)!: ",
"commitMessageTopic": "{{depName}}",
"commitMessageExtra": "( {{currentVersion}} → {{newVersion}} )"
},
{
"matchDatasources": ["github-releases", "github-tags"],
"matchUpdateTypes": ["minor"],
"semanticCommitType": "feat",
"semanticCommitScope": "github-release"
"semanticCommitScope": "github-release",
"commitMessageTopic": "{{depName}}",
"commitMessageExtra": "( {{currentVersion}} → {{newVersion}} )"
},
{
"matchDatasources": ["github-releases", "github-tags"],
"matchUpdateTypes": ["patch"],
"semanticCommitType": "fix",
"semanticCommitScope": "github-release"
"semanticCommitScope": "github-release",
"commitMessageTopic": "{{depName}}",
"commitMessageExtra": "( {{currentVersion}} → {{newVersion}} )"
},
{
"matchManagers": ["github-actions"],
"matchUpdateTypes": ["major"],
"commitMessagePrefix": "feat(github-action)!: "
"commitMessagePrefix": "feat(github-action)!: ",
"commitMessageTopic": "{{depName}}",
"commitMessageExtra": "( {{currentVersion}} → {{newVersion}} )"
},
{
"matchManagers": ["github-actions"],
"matchUpdateTypes": ["minor"],
"semanticCommitType": "feat",
"semanticCommitScope": "github-action"
"semanticCommitScope": "github-action",
"commitMessageTopic": "{{depName}}",
"commitMessageExtra": "( {{currentVersion}} → {{newVersion}} )"
},
{
"matchManagers": ["github-actions"],
"matchUpdateTypes": ["patch"],
"semanticCommitType": "fix",
"semanticCommitScope": "github-action"
"semanticCommitScope": "github-action",
"commitMessageTopic": "{{depName}}",
"commitMessageExtra": "( {{currentVersion}} → {{newVersion}} )"
}
]
}
96 changes: 96 additions & 0 deletions .github/scripts/extract-images.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#!/usr/bin/env zx
$.verbose = false

/**
* * extract-images.mjs
* * Extracts all container images from a HelmRelease and renders them as a JSON object
* @param --helmrelease : The source Flux HelmRelease to compare against the target
* @param --kubernetes-dir : The directory containing your Flux manifests including the HelmRepository manifests
*/
const HelmRelease = argv['helmrelease']
const KubernetesDir = argv['kubernetes-dir']

const helm = await which('helm')
const kustomize = await which('kustomize')

function extractImageValues(data) {
const imageValues = [];
function extractValues(obj) {
for (const key in obj) {
if (typeof obj[key] === 'object') {
extractValues(obj[key]);
} else if (key === 'image') {
imageValues.push(obj[key]);
}
}
}
extractValues(data);
return imageValues;
}

async function parseHelmRelease(releaseFile) {
const helmRelease = await fs.readFile(releaseFile, 'utf8')
const doc = YAML.parseAllDocuments(helmRelease).map((item) => item.toJS())
const release = doc.filter((item) =>
item.apiVersion === 'helm.toolkit.fluxcd.io/v2beta2'
&& item.kind === 'HelmRelease'
)
return release[0]
}

async function parseHelmRepository(kubernetesDir, releaseName) {
const files = await globby([`${kubernetesDir}/**/*.yaml`])
for await (const file of files) {
const contents = await fs.readFile(file, 'utf8')
const repository = YAML.parseAllDocuments(contents).map((item) => item.toJS())
if (repository[0] && 'apiVersion' in repository[0] && repository[0].apiVersion === 'source.toolkit.fluxcd.io/v1beta2'
&& 'kind' in repository[0] && repository[0].kind === 'HelmRepository'
&& 'metadata' in repository[0] && 'name' in repository[0].metadata && repository[0].metadata.name === releaseName)
{
return repository[0]
}
}
}

async function renderKustomize(releaseBaseDir, releaseName) {
const build = await $`${kustomize} build --load-restrictor=LoadRestrictionsNone ${releaseBaseDir}`
const docs = YAML.parseAllDocuments(build.stdout).map((item) => item.toJS())
const release = docs.filter((item) =>
item.apiVersion === 'helm.toolkit.fluxcd.io/v2beta2'
&& item.kind === 'HelmRelease'
&& item.metadata.name === releaseName
)
return release[0]
}

async function helmTemplate(release, repository) {
const values = new YAML.Document()
values.contents = release.spec.values
const valuesFile = await $`mktemp`
await fs.writeFile(valuesFile.stdout.trim(), values.toString())

// Template out helm values into Kubernetes manifests
let manifests
if ('type' in repository.spec && repository.spec.type == 'oci') {
manifests = await $`${helm} template --kube-version 1.28.0 --release-name ${release.metadata.name} --include-crds=false --skip-tests ${repository.spec.url}/${release.spec.chart.spec.chart} --version ${release.spec.chart.spec.version} --values ${valuesFile.stdout.trim()}`
} else {
await $`${helm} repo add ${release.spec.chart.spec.sourceRef.name} ${repository.spec.url}`
manifests = await $`${helm} template --kube-version 1.28.0 --release-name ${release.metadata.name} --include-crds=false --skip-tests ${release.spec.chart.spec.sourceRef.name}/${release.spec.chart.spec.chart} --version ${release.spec.chart.spec.version} --values ${valuesFile.stdout.trim()}`
}

let documents = YAML.parseAllDocuments(manifests.stdout.trim()).map((item) => item.toJS())

const images = [];
documents.forEach((doc) => {
const docImageValues = extractImageValues(doc);
images.push(...docImageValues);
});
return images;
}

const helmRelease = await parseHelmRelease(HelmRelease)
const kustomizeBuild = await renderKustomize(path.dirname(HelmRelease), helmRelease.metadata.name)
const helmRepository = await parseHelmRepository(KubernetesDir, kustomizeBuild.spec.chart.spec.sourceRef.name)
const images = await helmTemplate(kustomizeBuild, helmRepository)

echo(JSON.stringify(images))
Loading

0 comments on commit 7218111

Please sign in to comment.