Compare commits

..

No commits in common. "316230a68209e23129dfd220ca3afdec92b92791" and "f7ab9acac3f4c42740f7a825ad80e4cd2416a8a1" have entirely different histories.

18 changed files with 222 additions and 245 deletions

4
.gitignore vendored
View File

@ -1,7 +1,3 @@
bin/cron/ bin/cron/
var/ var/
systems/*
script/clone

View File

@ -1,11 +1,10 @@
# GIT branch in bash START # set GIT branch in bash
parse_git_branch() { parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/' git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
} }
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[01;31m\]$(parse_git_branch)\[\033[00m\]\$ ' PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[01;31m\]$(parse_git_branch)\[\033[00m\]\$ '
# GIT branch in bash END
# SSH Setup START # ssh setup
SSH_ENV="$HOME/.ssh/agent-environment" SSH_ENV="$HOME/.ssh/agent-environment"
function start_agent { function start_agent {
echo "Initialising new SSH agent..." echo "Initialising new SSH agent..."
@ -26,4 +25,3 @@ if [ -f "$SSH_ENV" ]; then
else else
start_agent start_agent
fi fi
# SSH Setup END

View File

@ -1,9 +0,0 @@
# Systems configuration
# configure the systems for the dev-env with the following pattern:
#
# <identifier>=<path/to/folder> <git repo link>
#
# LIKE CRON - THE FILE HAS TO END WITH AN EMPTY LINE
#
backend weedkeeper/backend ssh://git@docker.local:222/flo/weedkeeper-backend.git
frontend weedkeeper/frontend ssh://git@docker.local:222/flo/weedkeeper-frontend.git

View File

@ -1,53 +0,0 @@
Folgende Kommandos müssen abgebildet werden:
befehle:
denv
- init -> call script
- update -> call script
- build -> dcom
- stop -> dcom
- down -> dcom
- up -> dcom
drun
- docker exec
- examples:
drun composer install # Executes composer install in container associated with current directory
drun weedkeeper-backend composer install # Executes composer install in weedkeeper-backend container
dcom
- build
- stop
- down
- up
- examples:
dcom build # Executes docker compose build with docker-compose file located in docker/
dcom weedkeeper-backend build # Executes docker compose build with docker-compose file located in weedkeeper-backend/docker/
dev-env:
bin:
denv
drun
dcom
script:
init
clone
update
docker:
build
stop
down
up -d
system:
.env
script
init
update
firstRun
docker
docker-compose.yml

View File

@ -1,64 +0,0 @@
#!/bin/bash
ENV_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )/.." &> /dev/null && pwd )
source $ENV_DIR/bin/denv_msg
dcom() {
if [ $# -lt 1 ]; then
denv_error_msg "Verwendung: dcom [system] <docker-compose command>"
return 1
fi
local SYSTEMS_CONFIG="$ENV_DIR/.systems"
SYSTEM_IDENTIFIER="$1"
SYSTEM_PATH=$(grep "^$SYSTEM_IDENTIFIER" "$SYSTEMS_CONFIG" | cut -d' ' -f2)
if [ -z "$SYSTEM_PATH" ]; then # First Parameter is not a valid system identifier
SYSTEMS_DIRECTORY=$(realpath "$ENV_DIR/systems")
CURRENT_DIRECTORY=$(realpath $(pwd))
# We currently are in a subdirectory of dev-env/systems
if [[ "$CURRENT_DIRECTORY" == "$SYSTEMS_DIRECTORY"* ]]; then
ASSUMED_SYSTEM_PATH=$(realpath --relative-to="$SYSTEMS_DIRECTORY" "$CURRENT_DIRECTORY")
SYSTEM_PATH=$(grep "$ASSUMED_SYSTEM_PATH" "$SYSTEMS_CONFIG" | cut -d' ' -f2)
if [ -z "$SYSTEM_PATH" ]; then # You are NOT in a configured system directory (though in a subdirectory of dev-env/systems).
denv_error_msg "$CURRENT_DIRECTORY is not a configured dev-env system path.\nPlease register the system in $ENV_DIR/.systems, navigate to a registered system, or provide a system identifer as the first parameter of dcom."
return 1
else # You are in a configured system directory
SYSTEM_IDENTIFIER=$(grep "$ASSUMED_SYSTEM_PATH" "$SYSTEMS_CONFIG" | cut -d' ' -f1)
fi
else
denv_error_msg "$CURRENT_DIRECTORY is not a subdirectory of $ENV_DIR/systems.\nPlease navigate to a configured system, or provide a system identifer as the first parameter of dcom."
return 1
fi
else # First Parameter is a valid system identifier
shift # Remove first Parameter
fi
SYSTEM_PATH="$ENV_DIR/systems/$SYSTEM_PATH"
SYSTEM_ENV_FILE="$SYSTEM_PATH/.env"
DOCKER_COMPOSE_COMMAND="$@"
DOCKER_COMPOSE_FILE="$SYSTEM_PATH/docker/docker-compose.yml"
# Set .env variables if a file exist
if [[ ! -f "$DOCKER_COMPOSE_FILE" ]]; then
denv_error_msg "$DOCKER_COMPOSE_FILE was not found. Have you run init yet?"
return 1
fi
denv_info_msg "System: $SYSTEM_IDENTIFIER"
denv_info_msg "Command: $DOCKER_COMPOSE_COMMAND"
if [[ -f "$SYSTEM_ENV_FILE" ]] ; then
export $(grep -v '^#' "$SYSTEM_ENV_FILE" | xargs)
fi
docker compose -f "$DOCKER_COMPOSE_FILE" $DOCKER_COMPOSE_COMMAND
# Unset .env variables if a file exist
if [[ -f "$SYSTEM_ENV_FILE" ]] ; then
unset $(grep -v '^#' "$SYSTEM_ENV_FILE" | sed -E 's/(.*)=.*/\1/' | xargs)
fi
}

View File

@ -1,8 +1,14 @@
#!/bin/bash #!/bin/bash
ENV_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )/../" &> /dev/null && pwd ) ENV_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )/../" &> /dev/null && pwd )
denv() { denv() {
if [ ! -z $1 ] then if [ ! -z $1 ]
then
if [[ "$1" == "setup" ]]; then
echo "SETUP IS ONLY ALLOWED ONCE AFTER CLOING THE ENVIRONMENT!!!"
exit 0
fi
$ENV_DIR/$1 $ENV_DIR/$1
else else
cd $ENV_DIR cd $ENV_DIR

View File

@ -1,25 +0,0 @@
#!/bin/bash
Black='\033[0;30m'
Red='\033[0;31m'
Green='\033[0;32m'
Yellow='\033[0;33m'
Blue='\033[0;34m'
Purple='\033[0;35m'
Cyan='\033[0;36m'
White='\033[0;37m'
denv_error_msg () {
echo -e "${Red}$@${White}"
}
denv_success_msg () {
echo -e "${Green}$@${White}"
}
denv_info_msg () {
echo -e "${Cyan}$@${White}"
}
denv_echo_msg () {
echo -e "${White}$@"
}

72
bin/dexec Normal file
View File

@ -0,0 +1,72 @@
#!/bin/bash
denvexec() {
if [ $# -lt 1 ]; then
echo "Verwendung: denvexec <docker command>"
return 1
fi
local DOCKER_COMMAND="$@"
local ENV_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )/.." &> /dev/null && pwd )
echo ""
echo "Directory: ${ENV_DIR}"
#MAC
if [[ "$OSTYPE" == "darwin"* ]]; then
docker compose -f "${ENV_DIR}/docker/docker-compose-mac.yml" $DOCKER_COMMAND
echo "done"
#LINUX
elif [[ "$OSTYPE" == "linux-gnu" ]]; then
docker compose -f "${ENV_DIR}/docker/docker-compose.yml" $DOCKER_COMMAND
echo "done"
else
echo "Dieses Skript wird auf deinem Gerät nicht unterstützt"
exit 1
fi
}
dexec() {
if [ $# -lt 2 ]; then
echo "Verwendung: dexec <system> <docker command>"
return 1
fi
local systemPart="${1%-*}" # before "-" e.g. auth / bee / etc
local typePart="${1##*-}" # after "-" e.g. backend / frontend
local SYSTEM_DIR="$typePart/$systemPart"
shift # removes first argument
local DOCKER_COMMAND="$@"
local ENV_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )/.." &> /dev/null && pwd )
echo ""
echo "Directory: ${ENV_DIR}/systems/${SYSTEM_DIR}"
local DOT_ENV_PATH="${ENV_DIR}/systems/${SYSTEM_DIR}/.env"
#SET ENV VARIABLES FROM .ENV
if [ -e "$DOT_ENV_PATH" ]; then
export $(grep -v '^#' "$DOT_ENV_PATH" | xargs)
fi
#MAC
if [[ "$OSTYPE" == "darwin"* ]]; then
docker compose -f "${ENV_DIR}/systems/${SYSTEM_DIR}/docker/docker-compose-mac.yml" $DOCKER_COMMAND
echo "done"
#LINUX
elif [[ "$OSTYPE" == "linux-gnu" ]]; then
docker compose -f "${ENV_DIR}/systems/${SYSTEM_DIR}/docker/docker-compose.yml" $DOCKER_COMMAND
echo "done"
else
echo "Dieses Skript wird auf deinem Gerät nicht unterstützt"
exit 1
fi
#UNSET ENV VARIABLES FROM .ENV
if [ -e "$DOT_ENV_PATH" ]; then
unset $(grep -v '^#' "$DOT_ENV_PATH" | sed -E 's/(.*)=.*/\1/' | xargs)
fi
}

View File

@ -6,3 +6,6 @@ acp() {
git push git push
} }
co() {
git checkout $1
}

30
bin/script/foreachSystem Executable file
View File

@ -0,0 +1,30 @@
#!/bin/bash
COMMAND="$@"
ENV_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )/../.." &> /dev/null && pwd )
source ${ENV_DIR}/bin/dexec
if [ $# -lt 1 ]; then
echo "Verwendung: foreachSystem up -d"
return 1
fi
for SYSTEM in $ENV_DIR/systems/*/*/ ; do
relative_path="${SYSTEM#*/systems/}"
relative_path="${relative_path%/}"
typePart="${relative_path%/*}" # before "/" eg. backend / frontend
systemPart="${relative_path##*/}" # after "/" eg. bee / auth / etc
SYSTEM_CODE="$systemPart-$typePart"
DENV_COMMAND="dexec"
if [[ "$COMMAND" == "init" ]]; then
$ENV_DIR/systems/$typePart/$systemPart/bin/script/init
elif [[ "$COMMAND" == "update" ]]; then
$ENV_DIR/systems/$typePart/$systemPart/bin/script/update
else
$DENV_COMMAND $SYSTEM_CODE $COMMAND
fi
done

11
bin/script/pull Executable file
View File

@ -0,0 +1,11 @@
#!/bin/bash
EXEC_DIR=$(pwd)
echo "Execute git pull in each system"
for SYSTEM in $EXEC_DIR/systems/*/*/ ; do
cd $SYSTEM
git pull
cd $EXEC_DIR
done

View File

@ -0,0 +1,27 @@
networks:
template:
name: template
services:
traefik:
image: traefik:v3.0
networks:
- template
command:
- "--providers.docker=true"
- "--entrypoints.web.address=:80"
- "--entrypoints.web.http.redirections.entrypoint.to=websecure"
- "--entrypoints.web.http.redirections.entrypoint.scheme=https"
- "--entrypoints.websecure.address=:443"
- "--certificatesresolvers.le.acme.tlschallenge=true"
- "--certificatesresolvers.le.acme.email=florian_feistel@outlook.de"
- "--certificatesresolvers.le.acme.storage=/letsencrypt/acme.json"
ports:
- "80:80"
- "443:443"
- "8080:8080"
volumes:
- "./letsencrypt:/letsencrypt"
- "/var/run/docker.sock:/var/run/docker.sock"
labels:
- "traefik.http.routers.traefik.rule=Host(`traefik.template.local`)"

36
init
View File

@ -1,19 +1,33 @@
#!/bin/bash #!/bin/bash
ENV_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
source $SCRIPT_DIR/bin/denv
source $SCRIPT_DIR/bin/dexec
source $SCRIPT_DIR/bin/drun
EXIT=0
# Check docker-compose.yml file # Check docker-compose.yml file
if [ ! -f "$ENV_DIR/docker/docker-compose.yml" ] if [ ! -f "$SCRIPT_DIR/docker/docker-compose.yml" ]
then then
cp "$ENV_DIR/docker/docker-compose.yml.dist" "$ENV_DIR/docker/docker-compose.yml" cp "$SCRIPT_DIR/docker/docker-compose.yml.dist" "$SCRIPT_DIR/docker/docker-compose.yml"
EXIT=1
fi fi
# Update .profile # Check docker-compose-mac.yml file
$ENV_DIR/script/update_profile if [ ! -f "$SCRIPT_DIR/docker/docker-compose-mac.yml" ]
echo "" then
cp "$SCRIPT_DIR/docker/docker-compose-mac.yml.dist" "$SCRIPT_DIR/docker/docker-compose-mac.yml"
EXIT=1
fi
# Clone all systems.
$ENV_DIR/script/clone
echo ""
# Run init for all systems if [ $EXIT -eq 1 ]
./script/foreachSystem init then
echo "docker-compose files created, please change variables and call init again"
exit 1
fi
denvexec up -d
$SCRIPT_DIR/bin/script/foreachSystem init

View File

@ -1,38 +0,0 @@
#!/bin/bash
COMMAND="$@"
ENV_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )/.." &> /dev/null && pwd )
CONFIG_FILE="$ENV_DIR/.systems"
source $ENV_DIR/bin/denv_msg
# Check if .systems configuration exists
if [ ! -f "$CONFIG_FILE" ]; then
denv_error_msg "$CONFIG_FILE not found."
exit 1
fi
denv_info_msg "[dev-env]: Execute $COMMAND foreach System"
# Iterate through all lines in .systems configuration
while IFS=' ' read -r IDENTIFIER DIRECTORY GIT; do
# Skip comments and emtpy lines
if [[ "$IDENTIFIER" =~ ^#.* ]] || [ -z "$IDENTIFIER" ]; then
continue
fi
denv_info_msg "System $IDENTIFIER"
SYSTEM_SCRIPT_DIRECTORY=$(realpath "systems/$DIRECTORY/bin/script")
COMMAND_PATH="$SYSTEM_SCRIPT_DIRECTORY/$COMMAND";
# Check if system directory already exists
if [ ! -f "$COMMAND_PATH" ]; then
denv_error_msg "$COMMAND_PATH not found."
exit 1
else
denv_echo_msg "Executing $COMMAND..."
$COMMAND_PATH
fi
denv_info_msg "System $IDENTIFIER done"
echo ""
done < "$CONFIG_FILE"

View File

@ -1,36 +0,0 @@
#!/bin/bash
ENV_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )/.." &> /dev/null && pwd )
source $ENV_DIR/bin/denv_msg
PROFILE_FILE="$HOME/.profile"
TEMPLATE_FILE="$ENV_DIR/.profile"
START_MARKER="#DEV ENV SETUP START"
END_MARKER="#DEV ENV SETUP END"
# Check if template file exists
if [ ! -f "$TEMPLATE_FILE" ]; then
denv_error_msg "[dev-env]: Template file '$TEMPLATE_FILE' does not exist. Skip updating .profile."
exit 1
fi
TEMPLATE_CONTENT=$(<"$TEMPLATE_FILE")
denv_info_msg "[dev-env]: Update $PROFILE_FILE"
# Check if start marker already exists in profile file
if grep -q "$START_MARKER" "$PROFILE_FILE"; then
denv_echo_msg "[dev-env]: Section already exists. Update contents..."
# Remove contents between start and end marker
sed -i "/$START_MARKER/,/$END_MARKER/d" "$PROFILE_FILE"
else
denv_echo_msg "[dev-env]: Section does not exists. Adding contents..."
fi
# Add contents
echo -e "\n$START_MARKER\n$TEMPLATE_CONTENT\n$END_MARKER" >> "$PROFILE_FILE"
denv_success_msg "[dev-env]: Successfully updated $PROFILE_FILE"

33
setup Executable file
View File

@ -0,0 +1,33 @@
#!/bin/bash
# THIS SCRIPT NEEDS TO BE EXECUTED FIRST AFTER CLONING THE ENVIRONMENT AND SHALL NEVER BE EXECUTED AGAIN
# IT SETS UP THE ENVIRONMENT IN THE PROFILE TO ENABLE CORE COMMANDS LIKE denv drun dexec
# MAC
if [[ "$OSTYPE" == "darwin"* ]]; then
home="$HOME"
# LINUX
elif [[ "$OSTYPE" == "linux-gnu" ]]; then
home="$HOME"
else
echo "Dieses Skript wird auf deinem Gerät nicht unterstützt"
exit 1
fi
ENV_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
echo "Setup dev-env..."
echo "Adding sourcing of environment commands to .profile"
echo "" >> ~/.profile
echo "# denv commands setup" >> ~/.profile
echo "source $ENV_DIR/bin/denv" >> ~/.profile
echo "source $ENV_DIR/bin/drun" >> ~/.profile
echo "source $ENV_DIR/bin/dexec" >> ~/.profile
echo "source $ENV_DIR/bin/git" >> ~/.profile
echo "appending dev-env .profile to .profile"
echo "" >> ~/.profile
cat .profile >> ~/.profile

2
systems/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
*
!.gitignore

10
up
View File

@ -0,0 +1,10 @@
#!/bin/bash
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
source $SCRIPT_DIR/bin/denv
source $SCRIPT_DIR/bin/dexec
source $SCRIPT_DIR/bin/drun
denvexec up -d
$SCRIPT_DIR/bin/script/foreachSystem up -d