From fe4dd320695c0bba7bd6965c9948d16409b118ec Mon Sep 17 00:00:00 2001 From: Oscar Zhou Date: Wed, 16 Mar 2022 16:31:06 +1300 Subject: [PATCH] initial commit --- README.md | 10 +++ build_manager.sh | 177 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 187 insertions(+) create mode 100644 README.md create mode 100755 build_manager.sh diff --git a/README.md b/README.md new file mode 100644 index 0000000..0595bab --- /dev/null +++ b/README.md @@ -0,0 +1,10 @@ +# A toolkit for Portainer development work + +## How to use build_manager? + + +Make sure that the build_manager.sh executable `chmod +x build_manager.sh` + +``` +./build_manager.sh +``` \ No newline at end of file diff --git a/build_manager.sh b/build_manager.sh new file mode 100755 index 0000000..2ea900d --- /dev/null +++ b/build_manager.sh @@ -0,0 +1,177 @@ +#!/bin/bash + +set -eu + +WORKDIR=/home/oscarzhou/source/github.com/portainer +TRUE=0; +FALSE=1; + +# PORTAINER_FLAGS= +# PORTAINER_FLAGS=--enable-init true + +ERROR_COLOR='\033[0;31m'; +HIGHLIGHT_COLOR='\033[0;32m'; +NO_COLOR='\033[0m'; + +function is_ce_project() { + read -p "Choose the working project EE/(CE):" REPO + + if [ -z "$REPO" ]; then + REPO="EE"; + fi + + if [[ "${REPO}" == "ee" || "${REPO}" == "EE" ]]; then + return $FALSE; + + elif [[ "${REPO}" == "ce" || "${REPO}" == "CE" ]]; then + return $TRUE; + fi +} + +function is_root() { + if [ "$EUID" -ne 0 ]; then + printf "${HIGHLIGHT_COLOR}Please run as root${NO_COLOR}\n" + exit; + fi +} + +function check_branch() { + printf "Your current checkout branch \n$(git branch)\n" + read -p "Continue N/(Y)?" CORRECT_BRANCH + if [ -z "$CORRECT_BRANCH" ]; then + CORRECT_BRANCH="N"; + fi + + if [[ "${CORRECT_BRANCH}" == "N" || "${CORRECT_BRANCH}" == "n" ]]; then + printf "${ERROR_COLOR}Exit.\n"; + return $FALSE; + fi + return $TRUE; +} + +function export_volume() { + local VOLUME=~/volumes/portainer-ee-data + if is_ce_project; then + VOLUME=~/volumes/portainer-ce-data + cd ${WORKDIR}/portainer + + else + cd ${WORKDIR}/portainer-ee + fi + + export PORTAINER_DATA=${VOLUME} + printf "${HIGHLIGHT_COLOR}export PORTAINER_DATA=${PORTAINER_DATA}${NO_COLOR}\n" +} + + +function build_portainer_frontend_without_prompt() { + printf "${HIGHLIGHT_COLOR}Build Portainer Frontend${NO_COLOR}\n" + + yarn start:client +} + +function build_portainer_backend_without_prompt() { + printf "${HIGHLIGHT_COLOR}Build Portainer Backend${NO_COLOR}\n" + + if [ -z dist/portainer ]; then + rm dist/portainer; + fi + + yarn start:server +} + +function build_portainer_frontend() { + export_volume + + if ! check_branch; then + exit; + fi + + build_portainer_frontend_without_prompt + +} + +function build_portainer_backend() { + export_volume + + if ! check_branch; then + exit; + fi + + build_portainer_backend_without_prompt +} + +function build_portainer_all() { + printf "${HIGHLIGHT_COLOR}Build Portainer all${NO_COLOR}\n" + + export_volume + + if ! check_branch; then + exit; + fi + + build_portainer_frontend_without_prompt + + build_portainer_backend_without_prompt +} + +function run_before_commit() { + printf "${HIGHLIGHT_COLOR}Run before commit${NO_COLOR}\n" + + if is_ce_project; then + cd ${WORKDIR}/portainer + else + cd ${WORKDIR}/portainer-ee + fi + + if ! check_branch; then + exit; + fi + + printf "${HIGHLIGHT_COLOR}yarn format${NO_COLOR}\n" + yarn format + + printf "${HIGHLIGHT_COLOR}yarn lint${NO_COLOR}\n" + yarn lint +} + + + +function menu() { + PS3='Please select the option: ' + OPTIONS=( + 'Build Portainer All' + 'Build Portainer Frontend' + 'Build Portainer Backend' + 'Run Before Commit' + 'Quit' + ) + + select opt in "${OPTIONS[@]}" + do + case $opt in + 'Build Portainer All') + build_portainer_all + ;; + 'Build Portainer Frontend') + build_portainer_frontend + ;; + 'Build Portainer Backend') + build_portainer_backend + ;; + 'Run Before Commit') + run_before_commit + ;; + 'Quit') + break + ;; + esac + done +} + +# check if the function exists (bash specific) +if [ "$#" -eq 0 ]; then + menu +else + "$@" +fi