From c1b7262a14fd3fa894d723bed5db6b945e0eaba1 Mon Sep 17 00:00:00 2001 From: Nikolai Rodionov Date: Sun, 26 Feb 2023 07:27:44 +0100 Subject: [PATCH] migration: transfer the repo ownership --- .dockerignore | 1 + .drone.yml | 18 ++++++++++++++---- chart/Chart.yaml | 2 +- chart/values.yaml | 2 +- config.yaml | 2 +- kube/applicationset.yaml | 6 ++++-- kube/main.yaml | 1 + kube/template.yaml | 1 + scripts/cleanup.pl | 27 +++++++++++++++++++++------ 9 files changed, 45 insertions(+), 15 deletions(-) diff --git a/.dockerignore b/.dockerignore index e3e8e9e..fbc5c0c 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,3 +1,4 @@ node_modules static +scripts diff --git a/.drone.yml b/.drone.yml index c996c4d..de58de1 100644 --- a/.drone.yml +++ b/.drone.yml @@ -19,8 +19,8 @@ steps: commands: - helm plugin install https://github.com/chartmuseum/helm-push - helm package chart -d chart-package - - helm repo add --username allanger --password $GITEA_TOKEN allanger-charts https://git.badhouseplants.net/api/packages/allanger/helm - - helm cm-push "./chart-package/$(ls chart-package)" allanger-charts + - helm repo add --username allanger --password $GITEA_TOKEN badhouseplants-net https://git.badhouseplants.net/api/packages/badhouseplants/helm + - helm cm-push "./chart-package/$(ls chart-package)" badhouseplants-net - name: Init git submodules with themes image: alpine/git @@ -43,7 +43,7 @@ steps: username: allanger password: from_secret: GITEA_TOKEN - repo: git.badhouseplants.net/allanger/badhouseplants-net + repo: git.badhouseplants.net/${DRONE_REPO} tags: ${DRONE_COMMIT_SHA} - name: Build and push the docker image with latest @@ -56,7 +56,7 @@ steps: username: allanger password: from_secret: GITEA_TOKEN - repo: git.badhouseplants.net/allanger/badhouseplants-net + repo: git.badhouseplants.net/${DRONE_REPO} tags: - ${DRONE_COMMIT_SHA} - latest @@ -125,6 +125,16 @@ steps: - argocd app sync -l app=badhouseplants -l branch=$DRONE_BRANCH - argocd app wait -l app=badhouseplants -l branch=$DRONE_BRANCH +- name: Cleanup container registry + image: alpine + environment: + GITEA_TOKEN: + from_secret: GITEA_TOKEN + commands: + - apk update + - apk add curl jq perl git + - ./scripts/cleanup.pl + --- # ---------------------------------------------- # -- Upload a newer version of my CV diff --git a/chart/Chart.yaml b/chart/Chart.yaml index b5bbc9a..a73b83b 100644 --- a/chart/Chart.yaml +++ b/chart/Chart.yaml @@ -2,5 +2,5 @@ apiVersion: v2 name: badhouseplants-net description: A Helm chart for Kubernetes type: application -version: 0.3.9 +version: 0.4.0 appVersion: "1.16.0" diff --git a/chart/values.yaml b/chart/values.yaml index 440acd8..0030bae 100644 --- a/chart/values.yaml +++ b/chart/values.yaml @@ -37,7 +37,7 @@ hugo: name: badhouseplants-net resources: {} image: - repository: git.badhouseplants.net/allanger/badhouseplants-net + repository: git.badhouseplants.net/badhouseplants/badhouseplants-net pullPolicy: Always tag: latest baseURL: https://badhouseplants.net/ diff --git a/config.yaml b/config.yaml index dfbaec1..b04b5ae 100644 --- a/config.yaml +++ b/config.yaml @@ -35,7 +35,7 @@ params: imageHeight: 150 buttons: - name: Source - url: "https://git.badhouseplants.net/allanger/badhouseplants-net" + url: "https://git.badhouseplants.net/badhouseplants/badhouseplants-net" - name: My Music url: "https://funkwhale.badhouseplants.net/library/artists" socialIcons: diff --git a/kube/applicationset.yaml b/kube/applicationset.yaml index 7388408..e775dff 100644 --- a/kube/applicationset.yaml +++ b/kube/applicationset.yaml @@ -10,7 +10,9 @@ spec: - name: application app: badhouseplants branch: main - chart_version: 0.3.8 + chart_version: 0.3.9 + repo_url: https://git.badhouseplants.net/api/packages/badhouseplants/helm + value: | template: metadata: name: "{{ app }}-{{ name }}" @@ -25,7 +27,7 @@ spec: valueFiles: - values.yaml values: "{{ value }}" - repoURL: https://git.badhouseplants.net/api/packages/allanger/helm + repoURL: "{{ repo_url }}" targetRevision: "{{ chart_version }}" chart: badhouseplants-net destination: diff --git a/kube/main.yaml b/kube/main.yaml index 8a5c1c6..bbf1286 100644 --- a/kube/main.yaml +++ b/kube/main.yaml @@ -2,6 +2,7 @@ app: badhouseplants branch: $ARGO_APP_BRANCH chart_version: $ARGO_APP_CHART_VERSION + repo_url: https://git.badhouseplants.net/api/packages/badhouseplants/helm value: | hugo: image: diff --git a/kube/template.yaml b/kube/template.yaml index b2e7bcd..e2c6318 100644 --- a/kube/template.yaml +++ b/kube/template.yaml @@ -3,6 +3,7 @@ branch: $ARGO_APP_BRANCH commit_sha: $ARGO_APP_IMAGE_TAG chart_version: $ARGO_APP_CHART_VERSION + repo_url: https://git.badhouseplants.net/api/packages/badhouseplants/helm value: | namespace: name: badhouseplants-$ARGO_APP_BRANCH diff --git a/scripts/cleanup.pl b/scripts/cleanup.pl index c7c7a4b..67d317e 100755 --- a/scripts/cleanup.pl +++ b/scripts/cleanup.pl @@ -3,15 +3,30 @@ # Modules used use strict; use warnings; - +use Carp; -my $cmd = "git log --format=format:%H --all"; -my @output = `$cmd`; -chomp @output; +my $drone_url="$ENV{'DRONE_SYSTEM_PROTO'}://$ENV{'DRONE_SYSTEM_HOST'}"; +my $drone_project=$ENV{'DRONE_REPO'}; +my $drone_api="$drone_url/api/repos/$drone_project/builds"; +my $gitea_token=$ENV{'GITEA_TOKEN'}; +my $commits = "git log --format=format:%H --all"; +my @commits_out = `$commits`; +chomp @commits_out; +push @commits_out, 'latest'; -foreach my $line (@output) +my $builds = "curl -X 'GET' $drone_api -H 'accept: application/json' | jq -r '.[].after'"; +my @builds_out = `$builds`; +chomp @builds_out; + + +foreach my $line (@builds_out) { - print "$line"; + print $line; + if ( ! grep( /^$line$/, @commits_out ) ) { + my $cmd = "curl -X 'DELETE' \"https://git.badhouseplants.net/api/v1/packages/badhouseplants/container/badhouseplants-net/${line}\" -H 'accept: application/json' -u allanger:$gitea_token || true"; + print "Removing ${line}\n"; + my $output = `$cmd`; + } }