Implement dynamic envs (#19)
Reviewed-on: https://git.badhouseplants.net/allanger/badhouseplants-net/pulls/19
This commit is contained in:
74
.drone.yml
74
.drone.yml
@ -7,8 +7,6 @@ type: kubernetes
|
||||
name: Build badhouseplants.net
|
||||
|
||||
trigger:
|
||||
branch:
|
||||
- main
|
||||
event:
|
||||
- push
|
||||
|
||||
@ -29,15 +27,10 @@ steps:
|
||||
commands:
|
||||
- git submodule update --init --recursive
|
||||
|
||||
- name: Get static content
|
||||
image: rclone/rclone:latest
|
||||
environment:
|
||||
RCLONE_CONFIG_CONTENT:
|
||||
from_secret: RCLONE_CONFIG_CONTENT
|
||||
RCLONE_CONFIG: /tmp/rclone.conf
|
||||
- name: Test a build
|
||||
image: git.badhouseplants.net/badhouseplants/hugo-builder
|
||||
commands:
|
||||
- echo "$RCLONE_CONFIG_CONTENT" > $RCLONE_CONFIG
|
||||
- rclone copy -P badhouseplants-public:/badhouseplants-static static
|
||||
- hugo
|
||||
|
||||
- name: Build and push the docker image
|
||||
image: plugins/docker
|
||||
@ -47,10 +40,63 @@ steps:
|
||||
password:
|
||||
from_secret: GITEA_TOKEN
|
||||
repo: git.badhouseplants.net/allanger/badhouseplants-net
|
||||
tags: latest
|
||||
depends_on:
|
||||
- Init git submodules with themes
|
||||
- Get static content
|
||||
tags: ${DRONE_COMMIT_SHA}
|
||||
|
||||
- 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
|
||||
- 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
|
||||
- kubectl get -f ./kube/applicationset.yaml -o yaml > /tmp/old_appset.yaml
|
||||
- yq "del(.spec.generators[].list.elements[] | select(.name == \"$ARGO_APP_BRANCH\"))" /tmp/old_appset.yaml > /tmp/clean_appset.yaml
|
||||
- envsubst < ./kube/template.yaml > /tmp/elements.yaml
|
||||
- yq '.spec.generators[].list.elements += load("/tmp/elements.yaml")' /tmp/clean_appset.yaml > /tmp/new_appset.yaml
|
||||
- kubectl apply -f /tmp/new_appset.yaml
|
||||
|
||||
- name: Deploy a main ApplicationSet
|
||||
image: alpine/k8s:1.24.10
|
||||
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
|
||||
- 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/old_appset.yaml
|
||||
- yq "del(.spec.generators[].list.elements[] | select(.name == \"$ARGO_APP_BRANCH\"))" /tmp/old_appset.yaml > /tmp/clean_appset1.yaml
|
||||
- yq "del(.spec.generators[].list.elements[] | select(.commit_sha == \"$ARGO_APP_IMAGE_TAG\"))" /tmp/clean_appset1.yaml > /tmp/clean_appset.yaml
|
||||
- envsubst < ./kube/template.yaml > /tmp/elements.yaml
|
||||
- yq '.spec.generators[].list.elements += load("/tmp/elements.yaml")' /tmp/clean_appset.yaml > /tmp/new_appset.yaml
|
||||
- kubectl apply -f /tmp/new_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
|
||||
|
||||
---
|
||||
# ----------------------------------------------
|
||||
|
Reference in New Issue
Block a user