build: Refactor the Minio sync logic and separate the helm chart release
This commit is contained in:

committed by
Nikolai Rodionov

parent
2eef222b49
commit
5e19dbd9d8
290
.drone.yml
290
.drone.yml
@ -1,5 +1,28 @@
|
||||
---
|
||||
# ----------------------------------------------
|
||||
# -- Update the helm chart
|
||||
# ----------------------------------------------
|
||||
kind: pipeline
|
||||
type: kubernetes
|
||||
name: Publish the helm chart
|
||||
|
||||
trigger:
|
||||
event:
|
||||
- push
|
||||
|
||||
steps:
|
||||
- name: Publish the Helm chart
|
||||
image: alpine/helm
|
||||
environment:
|
||||
GITEA_TOKEN:
|
||||
from_secret: GITEA_TOKEN
|
||||
commands:
|
||||
- helm plugin install https://github.com/chartmuseum/helm-push
|
||||
- helm package chart -d chart-package
|
||||
- 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
|
||||
---
|
||||
# ----------------------------------------------
|
||||
# -- Build the site and push it to the registry
|
||||
# ----------------------------------------------
|
||||
kind: pipeline
|
||||
@ -8,137 +31,166 @@ name: Build badhouseplants.net
|
||||
|
||||
trigger:
|
||||
event:
|
||||
- push
|
||||
- push
|
||||
|
||||
steps:
|
||||
- name: Publish the Helm chart
|
||||
image: alpine/helm
|
||||
environment:
|
||||
GITEA_TOKEN:
|
||||
from_secret: GITEA_TOKEN
|
||||
commands:
|
||||
- helm plugin install https://github.com/chartmuseum/helm-push
|
||||
- helm package chart -d chart-package
|
||||
- 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: Download submodules with themes
|
||||
image: alpine/git
|
||||
commands:
|
||||
- git submodule update --init --recursive
|
||||
|
||||
- name: Init git submodules with themes
|
||||
image: alpine/git
|
||||
commands:
|
||||
- git submodule update --init --recursive
|
||||
- name: Test a build
|
||||
image: git.badhouseplants.net/badhouseplants/hugo-builder
|
||||
commands:
|
||||
- hugo
|
||||
|
||||
- name: Test a build
|
||||
image: git.badhouseplants.net/badhouseplants/hugo-builder
|
||||
commands:
|
||||
- hugo
|
||||
- name: Build and push the docker image
|
||||
image: plugins/docker
|
||||
when:
|
||||
branch:
|
||||
exclude:
|
||||
- main
|
||||
settings:
|
||||
registry: git.badhouseplants.net
|
||||
username: allanger
|
||||
password:
|
||||
from_secret: GITEA_TOKEN
|
||||
repo: git.badhouseplants.net/${DRONE_REPO}
|
||||
tags: ${DRONE_COMMIT_SHA}
|
||||
|
||||
- name: Build and push the docker image
|
||||
image: plugins/docker
|
||||
when:
|
||||
branch:
|
||||
exclude:
|
||||
- name: Build and push the docker image with latest
|
||||
image: plugins/docker
|
||||
when:
|
||||
branch:
|
||||
- main
|
||||
settings:
|
||||
registry: git.badhouseplants.net
|
||||
username: allanger
|
||||
password:
|
||||
from_secret: GITEA_TOKEN
|
||||
repo: git.badhouseplants.net/${DRONE_REPO}
|
||||
tags: ${DRONE_COMMIT_SHA}
|
||||
settings:
|
||||
registry: git.badhouseplants.net
|
||||
username: allanger
|
||||
password:
|
||||
from_secret: GITEA_TOKEN
|
||||
repo: git.badhouseplants.net/${DRONE_REPO}
|
||||
tags:
|
||||
- ${DRONE_COMMIT_SHA}
|
||||
- latest
|
||||
|
||||
- name: Build and push the docker image with latest
|
||||
image: plugins/docker
|
||||
when:
|
||||
branch:
|
||||
- main
|
||||
settings:
|
||||
registry: git.badhouseplants.net
|
||||
username: allanger
|
||||
password:
|
||||
from_secret: GITEA_TOKEN
|
||||
repo: git.badhouseplants.net/${DRONE_REPO}
|
||||
tags:
|
||||
- ${DRONE_COMMIT_SHA}
|
||||
- latest
|
||||
- name: Download media files
|
||||
image: alpine/git
|
||||
commands:
|
||||
- git lfs pull
|
||||
|
||||
- name: Deploy a preview ApplicationSet
|
||||
image: alpine/k8s:1.24.10
|
||||
when:
|
||||
branch:
|
||||
exclude:
|
||||
- name: Sync pictures from lfs to Minio
|
||||
image: rclone/rclone:latest
|
||||
when:
|
||||
branch:
|
||||
exclude:
|
||||
- main
|
||||
environment:
|
||||
RCLONE_CONFIG_CONTENT:
|
||||
from_secret: RCLONE_CONFIG_CONTENT_PRIVATE
|
||||
RCLONE_CONFIG: /tmp/rclone.conf
|
||||
commands:
|
||||
- echo "$RCLONE_CONFIG_CONTENT" > $RCLONE_CONFIG
|
||||
- apk update
|
||||
- apk add git make
|
||||
- make upload_static
|
||||
|
||||
- name: Sync pictures to the main Minio bucket
|
||||
image: rclone/rclone:latest
|
||||
when:
|
||||
branch:
|
||||
- main
|
||||
environment:
|
||||
KUBECONFIG_CONTENT:
|
||||
from_secret: KUBECONFIG_CONTENT
|
||||
commands:
|
||||
- mkdir $HOME/.kube
|
||||
- echo $KUBECONFIG_CONTENT | base64 -d > $HOME/.kube/config
|
||||
- apk update --no-cache && apk add yq gettext openssl
|
||||
- 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
|
||||
environment:
|
||||
RCLONE_CONFIG_CONTENT:
|
||||
from_secret: RCLONE_CONFIG_CONTENT_PRIVATE
|
||||
RCLONE_CONFIG: /tmp/rclone.conf
|
||||
commands:
|
||||
- echo "$RCLONE_CONFIG_CONTENT" > $RCLONE_CONFIG
|
||||
- apk update
|
||||
- apk add git make
|
||||
- make sync_static_with_main
|
||||
|
||||
- name: Deploy a main ApplicationSet
|
||||
image: alpine/k8s:1.24.10
|
||||
when:
|
||||
branch:
|
||||
- main
|
||||
environment:
|
||||
KUBECONFIG_CONTENT:
|
||||
from_secret: KUBECONFIG_CONTENT
|
||||
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
|
||||
- apk update --no-cache && apk add yq gettext
|
||||
- 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
|
||||
- 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: Deploy a preview ApplicationSet
|
||||
image: alpine/k8s:1.24.10
|
||||
when:
|
||||
branch:
|
||||
exclude:
|
||||
- main
|
||||
environment:
|
||||
KUBECONFIG_CONTENT:
|
||||
from_secret: KUBECONFIG_CONTENT
|
||||
commands:
|
||||
- mkdir $HOME/.kube
|
||||
- echo $KUBECONFIG_CONTENT | base64 -d > $HOME/.kube/config
|
||||
- apk update --no-cache && apk add yq gettext openssl
|
||||
- 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: Sync application
|
||||
image: argoproj/argocd
|
||||
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: Deploy a main ApplicationSet
|
||||
image: alpine/k8s:1.24.10
|
||||
when:
|
||||
branch:
|
||||
- main
|
||||
environment:
|
||||
KUBECONFIG_CONTENT:
|
||||
from_secret: KUBECONFIG_CONTENT
|
||||
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
|
||||
- apk update --no-cache && apk add yq gettext
|
||||
- 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
|
||||
- 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: Cleanup container registry
|
||||
image: alpine
|
||||
environment:
|
||||
GITEA_TOKEN:
|
||||
from_secret: GITEA_TOKEN
|
||||
commands:
|
||||
- apk update
|
||||
- apk add curl jq perl git
|
||||
- ./scripts/cleanup.pl
|
||||
- name: Sync application
|
||||
image: argoproj/argocd
|
||||
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
|
||||
image: rclone/rclone:latest
|
||||
environment:
|
||||
RCLONE_CONFIG_CONTENT:
|
||||
from_secret: RCLONE_CONFIG_CONTENT_PRIVATE
|
||||
RCLONE_CONFIG: /tmp/rclone.conf
|
||||
GITEA_TOKEN:
|
||||
from_secret: GITEA_TOKEN
|
||||
commands:
|
||||
- echo "$RCLONE_CONFIG_CONTENT" > $RCLONE_CONFIG
|
||||
- apk update
|
||||
- apk add curl jq perl git
|
||||
- ./scripts/cleanup.pl
|
||||
|
||||
---
|
||||
# ----------------------------------------------
|
||||
|
Reference in New Issue
Block a user