build: Get rid of ApplicationSets
This commit is contained in:
parent
f16c18f0e8
commit
b2e9cb0d7d
70
.drone.yml
70
.drone.yml
@ -75,7 +75,7 @@ steps:
|
|||||||
- echo "$RCLONE_CONFIG_CONTENT" > $RCLONE_CONFIG
|
- echo "$RCLONE_CONFIG_CONTENT" > $RCLONE_CONFIG
|
||||||
- ./scripts/upload-media.pl
|
- ./scripts/upload-media.pl
|
||||||
|
|
||||||
- name: Deploy a preview ApplicationSet
|
- name: Deploy the application
|
||||||
image: git.badhouseplants.net/badhouseplants/badhouseplants-builder:80ffd53372652576fa3c36a56b351b448a025c6a
|
image: git.badhouseplants.net/badhouseplants/badhouseplants-builder:80ffd53372652576fa3c36a56b351b448a025c6a
|
||||||
when:
|
when:
|
||||||
branch:
|
branch:
|
||||||
@ -85,77 +85,21 @@ steps:
|
|||||||
- Build and push the docker image
|
- Build and push the docker image
|
||||||
- Sync pictures from lfs to Minio
|
- Sync pictures from lfs to Minio
|
||||||
environment:
|
environment:
|
||||||
KUBECONFIG_CONTENT:
|
ARGOCD_SERVER:
|
||||||
from_secret: KUBECONFIG_CONTENT
|
from_secret: ARGOCD_SERVER
|
||||||
commands:
|
ARGOCD_AUTH_TOKEN:
|
||||||
- mkdir $HOME/.kube
|
from_secret: ARGOCD_AUTH_TOKEN
|
||||||
- echo $KUBECONFIG_CONTENT | base64 -d > $HOME/.kube/config
|
|
||||||
- export ARGO_APP_CHART_VERSION=`cat chart/Chart.yaml | yq '.version'`
|
|
||||||
- export ARGO_APP_BRANCH=$DRONE_BRANCH
|
|
||||||
- export ARGO_APP_HOSTNAME="${DRONE_BRANCH}-dev.badhouseplants.net"
|
|
||||||
- export ARGO_APP_IMAGE_TAG=$DRONE_COMMIT_SHA
|
|
||||||
- export ARGO_REMARK42_SECRET=$(openssl rand -hex 12)
|
|
||||||
- kubectl get -f ./kube/applicationset.yaml -o yaml > /tmp/appset.yaml
|
|
||||||
- yq -i "del(.metadata.resourceVersion)" /tmp/appset.yaml
|
|
||||||
- yq -i "del(.metadata.generation)" /tmp/appset.yaml
|
|
||||||
- yq -i "del(.metadata.uid)" /tmp/appset.yaml
|
|
||||||
- yq -i "del(.status)" /tmp/appset.yaml
|
|
||||||
- yq -i "del(.spec.generators[].list.elements[] | select(.branch == \"$ARGO_APP_BRANCH\"))" /tmp/appset.yaml
|
|
||||||
- envsubst < ./kube/template.yaml > /tmp/elements.yaml
|
|
||||||
- yq -i '.spec.generators[].list.elements += load("/tmp/elements.yaml")' /tmp/appset.yaml
|
|
||||||
- kubectl apply -f /tmp/appset.yaml
|
|
||||||
|
|
||||||
- name: Deploy a main ApplicationSet
|
|
||||||
image: git.badhouseplants.net/badhouseplants/badhouseplants-builder:80ffd53372652576fa3c36a56b351b448a025c6a
|
|
||||||
when:
|
|
||||||
branch:
|
|
||||||
- main
|
|
||||||
depends_on:
|
|
||||||
- Build and push the docker image
|
|
||||||
- Sync pictures from lfs to Minio
|
|
||||||
environment:
|
|
||||||
KUBECONFIG_CONTENT:
|
|
||||||
from_secret: KUBECONFIG_CONTENT
|
|
||||||
ARGO_GITHUB_OAUTH_KEY:
|
ARGO_GITHUB_OAUTH_KEY:
|
||||||
from_secret: GITHUB_OAUTH_KEY
|
from_secret: GITHUB_OAUTH_KEY
|
||||||
ARGO_GOOGLE_OAUTH_KEY:
|
ARGO_GOOGLE_OAUTH_KEY:
|
||||||
from_secret: GOOGLE_OAUTH_KEY
|
from_secret: GOOGLE_OAUTH_KEY
|
||||||
commands:
|
commands:
|
||||||
- mkdir $HOME/.kube
|
- ./scripts/deploy-app.pl
|
||||||
- echo $KUBECONFIG_CONTENT | base64 -d > $HOME/.kube/config
|
|
||||||
- export ARGO_APP_CHART_VERSION=`cat chart/Chart.yaml | yq '.version'`
|
|
||||||
- export ARGO_APP_BRANCH=$DRONE_BRANCH
|
|
||||||
- export ARGO_APP_IMAGE_TAG=$DRONE_COMMIT_SHA
|
|
||||||
- kubectl get -f ./kube/applicationset.yaml -o yaml > /tmp/appset.yaml
|
|
||||||
- yq -i "del(.metadata.resourceVersion)" /tmp/appset.yaml
|
|
||||||
- yq -i "del(.metadata.generation)" /tmp/appset.yaml
|
|
||||||
- yq -i "del(.metadata.uid)" /tmp/appset.yaml
|
|
||||||
- yq -i "del(.status)" /tmp/appset.yaml
|
|
||||||
- yq -i "del(.spec.generators[].list.elements[] | select(.branch == \"$ARGO_APP_BRANCH\"))" /tmp/appset.yaml
|
|
||||||
- yq -i "del(.spec.generators[].list.elements[] | select(.commit_sha == \"$ARGO_APP_IMAGE_TAG\"))" /tmp/appset.yaml
|
|
||||||
- yq -i '. *= load("./kube/applicationset.yaml")' /tmp/appset.yaml
|
|
||||||
- envsubst < ./kube/main.yaml > /tmp/elements.yaml
|
|
||||||
- yq -i '.spec.generators[].list.elements += load("/tmp/elements.yaml")' /tmp/appset.yaml
|
|
||||||
- kubectl apply -f /tmp/appset.yaml
|
|
||||||
|
|
||||||
- name: Sync application
|
|
||||||
image: git.badhouseplants.net/badhouseplants/badhouseplants-builder:80ffd53372652576fa3c36a56b351b448a025c6a
|
|
||||||
depends_on:
|
|
||||||
- Deploy a main ApplicationSet
|
|
||||||
- Deploy a preview ApplicationSet
|
|
||||||
environment:
|
|
||||||
ARGOCD_SERVER:
|
|
||||||
from_secret: ARGOCD_SERVER
|
|
||||||
ARGOCD_AUTH_TOKEN:
|
|
||||||
from_secret: ARGOCD_AUTH_TOKEN
|
|
||||||
commands:
|
|
||||||
- argocd app sync -l app=badhouseplants -l branch=$DRONE_BRANCH
|
|
||||||
- argocd app wait -l app=badhouseplants -l branch=$DRONE_BRANCH
|
|
||||||
|
|
||||||
- name: Cleanup everything
|
- name: Cleanup everything
|
||||||
image: git.badhouseplants.net/badhouseplants/badhouseplants-builder:80ffd53372652576fa3c36a56b351b448a025c6a
|
image: git.badhouseplants.net/badhouseplants/badhouseplants-builder:80ffd53372652576fa3c36a56b351b448a025c6a
|
||||||
depends_on:
|
depends_on:
|
||||||
- Sync application
|
- Deploy the application
|
||||||
environment:
|
environment:
|
||||||
RCLONE_CONFIG_CONTENT:
|
RCLONE_CONFIG_CONTENT:
|
||||||
from_secret: RCLONE_CONFIG_CONTENT_PRIVATE
|
from_secret: RCLONE_CONFIG_CONTENT_PRIVATE
|
||||||
|
@ -1,4 +1,8 @@
|
|||||||
# Badhouseplants NET
|
# Badhouseplants NET
|
||||||
|
## About
|
||||||
|
- To be done
|
||||||
|
|
||||||
## Static content
|
## Static content
|
||||||
Storing static content in the repo is painful, because there are massive. That's why for storing them I'm using a S3 bucket that is publicly available for downstream operations
|
Storing static content in the repo is painful, because there are massive. That's why for storing them I'm using a S3 bucket that is publicly available for downstream operations
|
||||||
|
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ namespace:
|
|||||||
labels:
|
labels:
|
||||||
istio-injection: enabled
|
istio-injection: enabled
|
||||||
enabled: true
|
enabled: true
|
||||||
name: badhouseplants-application
|
name: badhouseplants-main
|
||||||
|
|
||||||
nginx:
|
nginx:
|
||||||
container:
|
container:
|
||||||
|
@ -2,51 +2,21 @@ apiVersion: argoproj.io/v1alpha1
|
|||||||
kind: Application
|
kind: Application
|
||||||
metadata:
|
metadata:
|
||||||
labels:
|
labels:
|
||||||
application: $APPLICATON
|
application: badhouseplants
|
||||||
branch: $GIT_BRANCH
|
branch: $ARGO_APP_BRANCH
|
||||||
commit_sha: $GIT_COMMIT_SHA
|
commit_sha: $ARGO_APP_IMAGE_TAG
|
||||||
name: $APPLICATON-$GIT_BRANCH
|
name: badhouseplants-$ARGO_APP_BRANCH
|
||||||
namespace: argo-system
|
namespace: argo-system
|
||||||
spec:
|
spec:
|
||||||
destination:
|
destination:
|
||||||
namespace: $APPLICATON-$GIT_BRANCH
|
namespace: badhouseplants-$ARGO_APP_BRANCH
|
||||||
server: https://kubernetes.default.svc
|
server: https://kubernetes.default.svc
|
||||||
project: default
|
project: default
|
||||||
source:
|
source:
|
||||||
chart: badhouseplants-net
|
chart: badhouseplants-net
|
||||||
targetRevision: $HELM_CHART_VERSION
|
targetRevision: $ARGO_APP_CHART_VERSION
|
||||||
helm:
|
helm:
|
||||||
valueFiles:
|
valueFiles:
|
||||||
- values.yaml
|
- values.yaml
|
||||||
values: |
|
values: __DUMMY__
|
||||||
namespace:
|
|
||||||
name: badhouseplants-create-wubs-in-vital
|
|
||||||
labels:
|
|
||||||
istio-injection: disabled
|
|
||||||
istio:
|
|
||||||
hosts:
|
|
||||||
- create-wubs-in-vital-dev.badhouseplants.net
|
|
||||||
annotations:
|
|
||||||
link.argocd.argoproj.io/env: https://create-wubs-in-vital-dev.badhouseplants.net/
|
|
||||||
link.argocd.argoproj.io/remark42: https://remark42-create-wubs-in-vital-dev.badhouseplants.net/web
|
|
||||||
link.argocd.argoproj.io/build: DRONE_BUILD_LINK
|
|
||||||
hugo:
|
|
||||||
image:
|
|
||||||
tag: ee4efc6107541657f405a3dd9b7ee238d0e69e7b
|
|
||||||
baseURL: https://create-wubs-in-vital-dev.badhouseplants.net/
|
|
||||||
buildDrafts: true
|
|
||||||
env:
|
|
||||||
HUGO_PARAMS_GITBRANCH: create-wubs-in-vital
|
|
||||||
HUGO_PARAMS_REMARK42URL: https://remark42-create-wubs-in-vital-dev.badhouseplants.net
|
|
||||||
remark42:
|
|
||||||
istio:
|
|
||||||
hosts:
|
|
||||||
- remark42-create-wubs-in-vital-dev.badhouseplants.net
|
|
||||||
settings:
|
|
||||||
url: https://remark42-create-wubs-in-vital-dev.badhouseplants.net/
|
|
||||||
auth:
|
|
||||||
anonymous: true
|
|
||||||
secretKey: b8a41781b2c1ba2ecf49e4e7
|
|
||||||
rclone:
|
|
||||||
command: "rclone copy -P badhouseplants-public:/badhouseplants-net/ee4efc6107541657f405a3dd9b7ee238d0e69e7b /static"
|
|
||||||
repoURL: https://git.badhouseplants.net/api/packages/badhouseplants/helm
|
repoURL: https://git.badhouseplants.net/api/packages/badhouseplants/helm
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
- value: |
|
---
|
||||||
|
values: |
|
||||||
hugo:
|
hugo:
|
||||||
image:
|
image:
|
||||||
tag: $ARGO_APP_IMAGE_TAG
|
tag: $ARGO_APP_IMAGE_TAG
|
||||||
@ -25,4 +26,3 @@
|
|||||||
secret: $ARGO_GOOGLE_OAUTH_KEY
|
secret: $ARGO_GOOGLE_OAUTH_KEY
|
||||||
storage:
|
storage:
|
||||||
requestedSize: 300Mi
|
requestedSize: 300Mi
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
---
|
---
|
||||||
- value: |
|
values: |
|
||||||
namespace:
|
namespace:
|
||||||
name: badhouseplants-$ARGO_APP_BRANCH
|
name: badhouseplants-$ARGO_APP_BRANCH
|
||||||
labels:
|
labels:
|
||||||
@ -28,6 +28,6 @@
|
|||||||
url: https://remark42-$ARGO_APP_HOSTNAME/
|
url: https://remark42-$ARGO_APP_HOSTNAME/
|
||||||
auth:
|
auth:
|
||||||
anonymous: true
|
anonymous: true
|
||||||
secretKey: $ARGO_REMARK42_SECRET
|
secretKey: $ARGO_REMARK_SECRET
|
||||||
rclone:
|
rclone:
|
||||||
command: "rclone copy -P badhouseplants-public:/badhouseplants-net/$ARGO_APP_IMAGE_TAG /static"
|
command: 'rclone copy -P badhouseplants-public:/badhouseplants-net/$ARGO_APP_IMAGE_TAG /static'
|
||||||
|
@ -2,26 +2,69 @@
|
|||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
|
|
||||||
my $chart_version = `cat chart/Chart.yaml | yq '.version'` or die;
|
my $chart_version = `cat chart/Chart.yaml | yq '.version'` or die $1;
|
||||||
chomp($chart_version);
|
chomp($chart_version);
|
||||||
|
|
||||||
my $git_branch = `git rev-parse --abbrev-ref HEAD`;
|
my $git_branch = `git rev-parse --abbrev-ref HEAD`;
|
||||||
chomp($git_branch);
|
chomp($git_branch);
|
||||||
my $git_commit_sha = `git rev-parse HEAD`;
|
my $git_commit_sha = `git rev-parse HEAD`;
|
||||||
chomp($git_commit_sha);
|
chomp($git_commit_sha);
|
||||||
my $main_branch = "main";
|
|
||||||
|
|
||||||
print
|
my $main_branch = "main";
|
||||||
print $chart_version;
|
my $values = "";
|
||||||
# - kubectl get -f ./kube/applicationset.yaml -o yaml > /tmp/appset.yaml
|
my $remark_secret = `openssl rand -hex 12`;
|
||||||
# - yq -i "del(.metadata.resourceVersion)" /tmp/appset.yaml
|
chomp($remark_secret);
|
||||||
# - yq -i "del(.metadata.generation)" /tmp/appset.yaml
|
|
||||||
# - yq -i "del(.metadata.uid)" /tmp/appset.yaml
|
$ENV{'ARGO_APP_CHART_VERSION'} = $chart_version;
|
||||||
# - yq -i "del(.status)" /tmp/appset.yaml
|
$ENV{'ARGO_APP_BRANCH'} = $git_branch;
|
||||||
# - yq -i "del(.spec.generators[].list.elements[] | select(.branch == \"$ARGO_APP_BRANCH\"))" /tmp/appset.yaml
|
$ENV{'ARGO_APP_HOSTNAME'} = "$git_branch-dev.badhouseplants.net";
|
||||||
# - yq -i "del(.spec.generators[].list.elements[] | select(.commit_sha == \"$ARGO_APP_IMAGE_TAG\"))" /tmp/appset.yaml
|
$ENV{'ARGO_APP_IMAGE_TAG'} = $git_commit_sha;
|
||||||
# - yq -i '. *= load("./kube/applicationset.yaml")' /tmp/appset.yaml
|
$ENV{'ARGO_REMARK_SECRET'} = $remark_secret;
|
||||||
# - envsubst < ./kube/main.yaml > /tmp/elements.yaml
|
|
||||||
# - yq -i '.spec.generators[].list.elements += load("/tmp/elements.yaml")' /tmp/appset.yaml
|
# ----------------------------------
|
||||||
# - kubectl apply -f /tmp/appset.yaml
|
# -- Fill the Application manifest
|
||||||
#
|
# -- with correct values
|
||||||
|
# ----------------------------------
|
||||||
|
if ($git_branch eq $main_branch) {
|
||||||
|
print "Using the main values file\n";
|
||||||
|
print `envsubst < ./kube/values-main.yaml > /tmp/values.yaml` or die $!;
|
||||||
|
} else {
|
||||||
|
print "Using the preview values file\n";
|
||||||
|
print `envsubst < ./kube/values-preview.yaml > /tmp/values.yaml` or die $!;
|
||||||
|
}
|
||||||
|
print `yq -i '.values' /tmp/values.yaml` or die $!;
|
||||||
|
print `envsubst < ./kube/application.yaml > /tmp/application.yaml` or die $!;
|
||||||
|
print `yq -i '.spec.source.helm.values = load_str("/tmp/values.yaml")' /tmp/application.yaml` or die $!;
|
||||||
|
|
||||||
|
if(!defined $ENV{DEPLOY_SCRIPT_DEBUG}){
|
||||||
|
print `kubectl apply -f /tmp/application.yaml` or die $!;
|
||||||
|
print `argocd app sync -l application=badhouseplants -l branch=$git_branch` or die $!;
|
||||||
|
print `argocd app wait -l application=badhouseplants -l branch=$git_branch` or die $!;
|
||||||
|
}
|
||||||
|
# ----------------------------------
|
||||||
|
# -- Remove all `Applications` for
|
||||||
|
# -- branches that do not exists
|
||||||
|
# ----------------------------------
|
||||||
|
my @all_applications = `argocd app list -l application=badhouseplants -o yaml | yq '.[].metadata.name'` or die $!;
|
||||||
|
chomp(@all_applications);
|
||||||
|
foreach my $app (@all_applications) {
|
||||||
|
$app =~ s/badhouseplants-//;
|
||||||
|
}
|
||||||
|
|
||||||
|
my @all_branches = `git branch --format='%(refname:short)' -r` or die $!;
|
||||||
|
chomp(@all_branches);
|
||||||
|
foreach my $branch (@all_branches) {
|
||||||
|
$branch =~ s/origin\///;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach my $app (@all_applications) {
|
||||||
|
if ( !grep( /^$app$/, @all_branches ) ) {
|
||||||
|
if ($app ne "application") {
|
||||||
|
print "$app should be removed\n";
|
||||||
|
if(!defined $ENV{DEPLOY_SCRIPT_DEBUG}){
|
||||||
|
print `argocd app delete --yes badhouseplants-$app` or die $!;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user