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
|
||||
- ./scripts/upload-media.pl
|
||||
|
||||
- name: Deploy a preview ApplicationSet
|
||||
- name: Deploy the application
|
||||
image: git.badhouseplants.net/badhouseplants/badhouseplants-builder:80ffd53372652576fa3c36a56b351b448a025c6a
|
||||
when:
|
||||
branch:
|
||||
@ -85,77 +85,21 @@ steps:
|
||||
- Build and push the docker image
|
||||
- Sync pictures from lfs to Minio
|
||||
environment:
|
||||
KUBECONFIG_CONTENT:
|
||||
from_secret: KUBECONFIG_CONTENT
|
||||
commands:
|
||||
- mkdir $HOME/.kube
|
||||
- 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
|
||||
ARGOCD_SERVER:
|
||||
from_secret: ARGOCD_SERVER
|
||||
ARGOCD_AUTH_TOKEN:
|
||||
from_secret: ARGOCD_AUTH_TOKEN
|
||||
ARGO_GITHUB_OAUTH_KEY:
|
||||
from_secret: GITHUB_OAUTH_KEY
|
||||
ARGO_GOOGLE_OAUTH_KEY:
|
||||
from_secret: GOOGLE_OAUTH_KEY
|
||||
commands:
|
||||
- mkdir $HOME/.kube
|
||||
- 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
|
||||
- ./scripts/deploy-app.pl
|
||||
|
||||
- name: Cleanup everything
|
||||
image: git.badhouseplants.net/badhouseplants/badhouseplants-builder:80ffd53372652576fa3c36a56b351b448a025c6a
|
||||
depends_on:
|
||||
- Sync application
|
||||
- Deploy the application
|
||||
environment:
|
||||
RCLONE_CONFIG_CONTENT:
|
||||
from_secret: RCLONE_CONFIG_CONTENT_PRIVATE
|
||||
|
@ -1,4 +1,8 @@
|
||||
# Badhouseplants NET
|
||||
## About
|
||||
- To be done
|
||||
|
||||
## 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
|
||||
|
||||
|
||||
|
@ -5,7 +5,7 @@ namespace:
|
||||
labels:
|
||||
istio-injection: enabled
|
||||
enabled: true
|
||||
name: badhouseplants-application
|
||||
name: badhouseplants-main
|
||||
|
||||
nginx:
|
||||
container:
|
||||
|
@ -2,51 +2,21 @@ apiVersion: argoproj.io/v1alpha1
|
||||
kind: Application
|
||||
metadata:
|
||||
labels:
|
||||
application: $APPLICATON
|
||||
branch: $GIT_BRANCH
|
||||
commit_sha: $GIT_COMMIT_SHA
|
||||
name: $APPLICATON-$GIT_BRANCH
|
||||
application: badhouseplants
|
||||
branch: $ARGO_APP_BRANCH
|
||||
commit_sha: $ARGO_APP_IMAGE_TAG
|
||||
name: badhouseplants-$ARGO_APP_BRANCH
|
||||
namespace: argo-system
|
||||
spec:
|
||||
destination:
|
||||
namespace: $APPLICATON-$GIT_BRANCH
|
||||
namespace: badhouseplants-$ARGO_APP_BRANCH
|
||||
server: https://kubernetes.default.svc
|
||||
project: default
|
||||
source:
|
||||
chart: badhouseplants-net
|
||||
targetRevision: $HELM_CHART_VERSION
|
||||
targetRevision: $ARGO_APP_CHART_VERSION
|
||||
helm:
|
||||
valueFiles:
|
||||
- values.yaml
|
||||
values: |
|
||||
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"
|
||||
values: __DUMMY__
|
||||
repoURL: https://git.badhouseplants.net/api/packages/badhouseplants/helm
|
||||
|
@ -1,28 +1,28 @@
|
||||
- value: |
|
||||
hugo:
|
||||
image:
|
||||
tag: $ARGO_APP_IMAGE_TAG
|
||||
env:
|
||||
HUGO_PARAMS_GITCOMMIT: $ARGO_APP_IMAGE_TAG
|
||||
istio:
|
||||
annotations:
|
||||
link.argocd.argoproj.io/env: https://badhouseplants.net/
|
||||
link.argocd.argoproj.io/build: $DRONE_BUILD_LINK
|
||||
link.argocd.argoproj.io/remark42: https://remark42.badhouseplants.net/web
|
||||
remark42:
|
||||
settings:
|
||||
secret: $ARGO_REMARK_SECRET
|
||||
admin:
|
||||
sharedEmail: allanger@zohomail.com
|
||||
oauth:
|
||||
github:
|
||||
enabled: true
|
||||
key: 1fb3d33a62b074bc0ea0
|
||||
secret: $ARGO_GITHUB_OAUTH_KEY
|
||||
google:
|
||||
enabled: true
|
||||
key: 966815964055-m9t7leuj1arqimqu2pvbs1k10cg54gcg.apps.googleusercontent.com
|
||||
secret: $ARGO_GOOGLE_OAUTH_KEY
|
||||
storage:
|
||||
requestedSize: 300Mi
|
||||
|
||||
---
|
||||
values: |
|
||||
hugo:
|
||||
image:
|
||||
tag: $ARGO_APP_IMAGE_TAG
|
||||
env:
|
||||
HUGO_PARAMS_GITCOMMIT: $ARGO_APP_IMAGE_TAG
|
||||
istio:
|
||||
annotations:
|
||||
link.argocd.argoproj.io/env: https://badhouseplants.net/
|
||||
link.argocd.argoproj.io/build: $DRONE_BUILD_LINK
|
||||
link.argocd.argoproj.io/remark42: https://remark42.badhouseplants.net/web
|
||||
remark42:
|
||||
settings:
|
||||
secret: $ARGO_REMARK_SECRET
|
||||
admin:
|
||||
sharedEmail: allanger@zohomail.com
|
||||
oauth:
|
||||
github:
|
||||
enabled: true
|
||||
key: 1fb3d33a62b074bc0ea0
|
||||
secret: $ARGO_GITHUB_OAUTH_KEY
|
||||
google:
|
||||
enabled: true
|
||||
key: 966815964055-m9t7leuj1arqimqu2pvbs1k10cg54gcg.apps.googleusercontent.com
|
||||
secret: $ARGO_GOOGLE_OAUTH_KEY
|
||||
storage:
|
||||
requestedSize: 300Mi
|
||||
|
@ -1,33 +1,33 @@
|
||||
---
|
||||
- value: |
|
||||
namespace:
|
||||
name: badhouseplants-$ARGO_APP_BRANCH
|
||||
labels:
|
||||
istio-injection: disabled
|
||||
values: |
|
||||
namespace:
|
||||
name: badhouseplants-$ARGO_APP_BRANCH
|
||||
labels:
|
||||
istio-injection: disabled
|
||||
istio:
|
||||
hosts:
|
||||
- $ARGO_APP_HOSTNAME
|
||||
annotations:
|
||||
link.argocd.argoproj.io/env: https://$ARGO_APP_HOSTNAME/
|
||||
link.argocd.argoproj.io/remark42: https://remark42-$ARGO_APP_HOSTNAME/web
|
||||
link.argocd.argoproj.io/build: $DRONE_BUILD_LINK
|
||||
hugo:
|
||||
image:
|
||||
tag: $ARGO_APP_IMAGE_TAG
|
||||
baseURL: https://$ARGO_APP_HOSTNAME/
|
||||
buildDrafts: true
|
||||
env:
|
||||
HUGO_PARAMS_GITBRANCH: $ARGO_APP_BRANCH
|
||||
HUGO_PARAMS_REMARK42URL: https://remark42-$ARGO_APP_HOSTNAME
|
||||
HUGO_PARAMS_GITCOMMIT: $ARGO_APP_IMAGE_TAG
|
||||
remark42:
|
||||
istio:
|
||||
hosts:
|
||||
- $ARGO_APP_HOSTNAME
|
||||
annotations:
|
||||
link.argocd.argoproj.io/env: https://$ARGO_APP_HOSTNAME/
|
||||
link.argocd.argoproj.io/remark42: https://remark42-$ARGO_APP_HOSTNAME/web
|
||||
link.argocd.argoproj.io/build: $DRONE_BUILD_LINK
|
||||
hugo:
|
||||
image:
|
||||
tag: $ARGO_APP_IMAGE_TAG
|
||||
baseURL: https://$ARGO_APP_HOSTNAME/
|
||||
buildDrafts: true
|
||||
env:
|
||||
HUGO_PARAMS_GITBRANCH: $ARGO_APP_BRANCH
|
||||
HUGO_PARAMS_REMARK42URL: https://remark42-$ARGO_APP_HOSTNAME
|
||||
HUGO_PARAMS_GITCOMMIT: $ARGO_APP_IMAGE_TAG
|
||||
remark42:
|
||||
istio:
|
||||
hosts:
|
||||
- remark42-$ARGO_APP_HOSTNAME
|
||||
settings:
|
||||
url: https://remark42-$ARGO_APP_HOSTNAME/
|
||||
auth:
|
||||
anonymous: true
|
||||
secretKey: $ARGO_REMARK42_SECRET
|
||||
rclone:
|
||||
command: "rclone copy -P badhouseplants-public:/badhouseplants-net/$ARGO_APP_IMAGE_TAG /static"
|
||||
- remark42-$ARGO_APP_HOSTNAME
|
||||
settings:
|
||||
url: https://remark42-$ARGO_APP_HOSTNAME/
|
||||
auth:
|
||||
anonymous: true
|
||||
secretKey: $ARGO_REMARK_SECRET
|
||||
rclone:
|
||||
command: 'rclone copy -P badhouseplants-public:/badhouseplants-net/$ARGO_APP_IMAGE_TAG /static'
|
||||
|
@ -2,26 +2,69 @@
|
||||
use strict;
|
||||
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);
|
||||
|
||||
my $git_branch = `git rev-parse --abbrev-ref HEAD`;
|
||||
chomp($git_branch);
|
||||
my $git_commit_sha = `git rev-parse HEAD`;
|
||||
chomp($git_commit_sha);
|
||||
my $main_branch = "main";
|
||||
|
||||
print
|
||||
print $chart_version;
|
||||
# - 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
|
||||
#
|
||||
my $main_branch = "main";
|
||||
my $values = "";
|
||||
my $remark_secret = `openssl rand -hex 12`;
|
||||
chomp($remark_secret);
|
||||
|
||||
$ENV{'ARGO_APP_CHART_VERSION'} = $chart_version;
|
||||
$ENV{'ARGO_APP_BRANCH'} = $git_branch;
|
||||
$ENV{'ARGO_APP_HOSTNAME'} = "$git_branch-dev.badhouseplants.net";
|
||||
$ENV{'ARGO_APP_IMAGE_TAG'} = $git_commit_sha;
|
||||
$ENV{'ARGO_REMARK_SECRET'} = $remark_secret;
|
||||
|
||||
# ----------------------------------
|
||||
# -- 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