Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/v2/environments export #10

Open
wants to merge 13 commits into
base: feature/v2/local-trigger
Choose a base branch
from
65 changes: 13 additions & 52 deletions app-deploy.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
#!/usr/bin/env bash

source ./.deploy-options.sh
if [ -z "$1" ] || [ "$1" == 'trigger' ] ; then
source ./.deploy-options.sh
source /usr/local/bin/.app-deploy-sources/__trigger_deploy.sh
fi
source /usr/local/bin/.app-deploy-sources/__constants.sh
source /usr/local/bin/.app-deploy-sources/__auto_update.sh
source /usr/local/bin/.app-deploy-sources/__init.sh
source /usr/local/bin/.app-deploy-sources/__initial_checkup.sh
source /usr/local/bin/.app-deploy-sources/__base_tag_handling.sh
source /usr/local/bin/.app-deploy-sources/__deploy_tags.sh
source /usr/local/bin/.app-deploy-sources/__env_extractor.sh

###############################################################
# DEPLOY SCRIPT #
Expand All @@ -20,69 +25,25 @@ source /usr/local/bin/.app-deploy-sources/__deploy_tags.sh

# Use global variables at your own risk as this can be overridden in the future.
set -e
bold=$(tput bold)
normal=$(tput sgr0)

#################################
# MAIN #
#################################

# Private part of the script...
#
# In general, you don't have to edit
# this part of the script but feel free
# to edit any part of it as suits your needs.

function main {

# BASE INFO
# commit, tag, synced head,...
__initial_checkup

# CREATE TAG

deploy_options # Get from .deploy-options.sh, setup per project
__input_to_tags

if [ -z "$script_version" ] || [ "$script_version" == "v1" ]; then
__create_app_version_and_build_number
elif [ "$script_version" == "v2" ]; then
__create_trigger_ci_timestamp_tag
fi

# CREATE CHANGELOG

__generate_tag_and_changelog

# DEPLOY

__push_tag_and_start_deploy
}

#################################
# START EVERYTHING #
#################################

if $use_automatic_console_clean ; then
clear
fi
echo
echo "###############################################################"
echo "# DEPLOY SCRIPT #"
echo "# #"
echo "# Copyright (c) 2024 Infinum. #"
echo "###############################################################"
echo

if [ "$1" == '--update' ] ; then
__clear_console
__script_auto_update
elif [ "$1" == 'init' ] ; then
__clear_console
__init
elif [ -z "$1" ] || [ "$1" == 'trigger' ] ; then # Empty input or "trigger"
main
__clear_console
__trigger_deploy
elif [ "$1" == 'environments' ] ; then
__env_extractor "$2"
else
echo
echo "Unsuported command!"
echo
exit 0
exit 29
fi
12 changes: 8 additions & 4 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@ normal=$(tput sgr0)
echo "==> ${bold}This script will install:${normal}"
echo "/usr/local/bin/app-deploy"
echo
read -r -p "Do you want to proceed? [y/n] " c
if ! [[ ${c} =~ ^(yes|y|Y) ]] || [ -z ${c} ]; then
exit 1

if ! [[ "$0" == "--silent" ]]; then
read -r -p "Do you want to proceed? [y/n] " c
if ! [[ ${c} =~ ^(yes|y|Y) ]] || [ -z ${c} ]; then
exit 1
fi
fi

echo
echo "Fetching script data..."

Expand All @@ -34,7 +38,7 @@ else
fi

# Get install files
git clone --quiet https://github.com/infinum/app-deploy-script.git --branch feature/v2/local-trigger .app_deploy_tmp
git clone --quiet https://github.com/infinum/app-deploy-script.git --branch feature/v2/environments-export .app_deploy_tmp
echo "Installing..."

# Move main script to bin folder
Expand Down
4 changes: 4 additions & 0 deletions sources/__auto_update.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
source /usr/local/bin/.app-deploy-sources/__constants.sh

#################################
# UPDATE #
#################################

function __script_auto_update {

__header_print
echo
echo "Please wait until main script is finished with updating..."
echo
Expand Down
6 changes: 4 additions & 2 deletions sources/__base_tag_handling.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
source /usr/local/bin/.app-deploy-sources/__constants.sh

#################################
# CREATE TAG #
#################################
Expand Down Expand Up @@ -77,15 +79,15 @@ function __create_trigger_ci_timestamp_tag {
tags_to_deploy=()

# Prefix ci
trigger_tag="ci/"
trigger_tag="$TRIGGER_TAG_PREFIX"

# Environments
for target in "${environments_to_build[@]}"; do
trigger_tag+="$target/"
done

# Sufix timestamp
trigger_tag+="$(date +%Y-%m-%dT%H-%M-%S)"
trigger_tag+="$TRIGGER_TAG_SUFIX"

# Assign to shared property
tags_to_deploy=("$trigger_tag")
Expand Down
22 changes: 22 additions & 0 deletions sources/__constants.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#################################
# CONSTANTS #
#################################

function __header_print {
echo
echo "###############################################################"
echo "# DEPLOY SCRIPT #"
echo "# #"
echo "# Copyright (c) 2024 Infinum. #"
echo "###############################################################"
echo
}

function __clear_console {
if $use_automatic_console_clean ; then
clear
fi
}
TRIGGER_TAG_PREFIX="ci/"
TRIGGER_TAG_SUFIX="$(date +%Y-%m-%dT%H-%M-%S)"
TRIGGER_TAG_SUFIX_REGEX=([0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}-[0-9]{2}-[0-9]{2})
36 changes: 36 additions & 0 deletions sources/__env_extractor.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
source /usr/local/bin/.app-deploy-sources/__constants.sh

#################################
# ENVIRONMENT EXTRACTOR #
#################################

function __env_extractor {

# Check if input is valid
if [ -z "$1" ] ; then
echo "Missing input value!"
echo
echo "Usage: app-deploy environments input"
echo "- input: a value from which 'environments' command shoudl extract data. Should be trigger tag generated by this script."
exit 1
fi

if [[ $1 =~ ^$TRIGGER_TAG_PREFIX(.+)/$TRIGGER_TAG_SUFIX_REGEX$ ]]; then
paths="${BASH_REMATCH[1]}"

# Split the captured paths into individual words
IFS='/' read -ra words <<< "$paths"
echo "$(IFS=$'\n'; echo "${words[*]}")"
else
echo
echo "Incorrect input value."
echo
echo "The environment can only be extracted from the official trigger tag."
echo
echo "Please use this script for generating the trigger tag, or use the tag in the format:"
echo "prefix: ci/"
echo "environments: env1/env2/..."
echo "sufix: /timestamp where timestamp should be in the format of +%Y-%m-%dT%H-%M-%S (2024-12-06T11-24-53)"
echo "EXAMPLE: ci/env1/env2/2024-12-06T11-24-53"
fi
}
4 changes: 4 additions & 0 deletions sources/__init.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
source /usr/local/bin/.app-deploy-sources/__constants.sh

#################################
# INIT NEW PROJECT #
#################################

function __init {

__header_print

if [ -e "./.deploy-options.sh" ]; then
echo "Options file already exists."
echo "If you continue, stored options will be overriden!"
Expand Down
41 changes: 41 additions & 0 deletions sources/__trigger_deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

#################################
# DEPLOYMENT TRIGGER TAG #
#################################

# Private part of the script...
#
# In general, you don't have to edit
# this part of the script but feel free
# to edit any part of it as suits your needs.

bold=$(tput bold)
normal=$(tput sgr0)

function __trigger_deploy {

__header_print

# BASE INFO
# commit, tag, synced head,...
__initial_checkup

# CREATE TAG

deploy_options # Get from .deploy-options.sh, setup per project
__input_to_tags

if [ -z "$script_version" ] || [ "$script_version" == "v1" ]; then
__create_app_version_and_build_number
elif [ "$script_version" == "v2" ]; then
__create_trigger_ci_timestamp_tag
fi

# CREATE CHANGELOG

__generate_tag_and_changelog

# DEPLOY

__push_tag_and_start_deploy
}