From 654bf09ed157577c9d2d36546ac07d74c634a031 Mon Sep 17 00:00:00 2001 From: Christian Jakob <47860090+thesephirot@users.noreply.github.com> Date: Wed, 10 Jun 2020 12:38:13 +0200 Subject: [PATCH] Autodeploydev (#200) * fix: autodeploy * added version condition --- .github/scripts/githelper.sh | 54 +++++++++++++++++++++++++++++++++++ .github/scripts/variables.env | 21 ++++++++++++++ .github/workflows/release.yml | 11 +++++++ 3 files changed, 86 insertions(+) create mode 100755 .github/scripts/githelper.sh create mode 100644 .github/scripts/variables.env diff --git a/.github/scripts/githelper.sh b/.github/scripts/githelper.sh new file mode 100755 index 000000000..26524949d --- /dev/null +++ b/.github/scripts/githelper.sh @@ -0,0 +1,54 @@ +#!/bin/bash +#debugger +set -x + +source ./.github/scripts/variables.env + +############################ +function setup_git { +############################ + echo "###############" + echo "set git config" + echo "###############" + + git config --global user.email "$GIT_USER_MAIL" + git config --global user.name "$GIT_USER_NAME" +} + +############################ +function checkout_project { +############################ + echo "###############" + echo "clone repository $GIT_URL" + echo "###############" + + # clone opsrepo + git clone $GIT_URL $LOCAL_TMP_DIR/$GIT_OPSREPO +} + +############################ +function change_image_version { +############################ + echo "###############" + echo "checkout master" + echo "###############" + + cd $LOCAL_TMP_DIR/$GIT_OPSREPO/$GIT_OPSREPO_APPFOLDER/$GIT_OPSREPO_APPLICATION_NAME/overlay/$TARGET_ENVIRONMENT + git checkout master + git pull + echo "###############" + echo "change image version and commit" + echo "###############" + sed -i "s#image: $REGISTRY_IMAGE:.*#image: $REGISTRY_IMAGE:$CAOS_NEXT_VERSION#g" $GIT_OPSREPO_IMAGEFILE + git add $GIT_OPSREPO_IMAGEFILE + git commit --message "Github Workflow: $GITHUB_WORKFLOW" +} + +############################ +function upload_files { +############################ + echo "###############" + echo "git push" + echo "###############" + git push --quiet --set-upstream origin +} diff --git a/.github/scripts/variables.env b/.github/scripts/variables.env new file mode 100644 index 000000000..8f496a7c8 --- /dev/null +++ b/.github/scripts/variables.env @@ -0,0 +1,21 @@ +### local vars +export LOCAL_TMP_DIR="/tmp" + +### git settings for cloning operations repository +export GIT_USER_MAIL="hi@caos.ch" +export GIT_USER_NAME="zitadel-pipeline" + +#path of opsrepository +export GIT_URL="https://$GIT_OPSREPO_DEPLOYTOKEN@github.com/caos/zitadel-ops.git" +export GIT_OPSREPO="citadel-ops" + +### application settings +export GIT_OPSREPO_APPFOLDER="k8s/workload" +export GIT_OPSREPO_APPLICATION_NAME="zitadel" +export GIT_OPSREPO_IMAGEFILE="imageversion.yaml" +export REGISTRY_IMAGE="$REGISTRY/$GITHUB_REPOSITORY/$IMAGE" + +### environment settings +#export TARGET_ENVIRONMENT="dev" + + diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index debde81b9..80fe07876 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -213,3 +213,14 @@ jobs: - name: Docker Push Latest run: docker push $REGISTRY/$GITHUB_REPOSITORY/$IMAGE:latest if: env.CAOS_NEXT_VERSION != '' + - name: Deploy DEV environment + env: + TARGET_ENVIRONMENT: "dev" + GIT_OPSREPO_DEPLOYTOKEN: ${{secrets.GIT_OPSREPO_DEPLOYTOKEN}} + run: | + source ./.github/scripts/githelper.sh + setup_git + checkout_project + change_image_version + upload_files + if: env.CAOS_NEXT_VERSION != ''