__devenv
This commit is contained in:
parent
f7ab9acac3
commit
b28b069884
4
.gitignore
vendored
4
.gitignore
vendored
@ -1,3 +1,7 @@
|
||||
bin/cron/
|
||||
var/
|
||||
|
||||
systems/*
|
||||
|
||||
|
||||
script/clone
|
||||
6
.profile
6
.profile
@ -1,10 +1,11 @@
|
||||
# set GIT branch in bash
|
||||
# GIT branch in bash START
|
||||
parse_git_branch() {
|
||||
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\]\$ '
|
||||
# GIT branch in bash END
|
||||
|
||||
# ssh setup
|
||||
# SSH Setup START
|
||||
SSH_ENV="$HOME/.ssh/agent-environment"
|
||||
function start_agent {
|
||||
echo "Initialising new SSH agent..."
|
||||
@ -25,3 +26,4 @@ if [ -f "$SSH_ENV" ]; then
|
||||
else
|
||||
start_agent
|
||||
fi
|
||||
# SSH Setup END
|
||||
9
.systems
Normal file
9
.systems
Normal file
@ -0,0 +1,9 @@
|
||||
# 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
|
||||
53
README.md
Normal file
53
README.md
Normal file
@ -0,0 +1,53 @@
|
||||
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
|
||||
53
bin/dcom
Normal file
53
bin/dcom
Normal file
@ -0,0 +1,53 @@
|
||||
#!/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"
|
||||
DOCKER_COMPOSE_COMMAND="$@"
|
||||
DOCKER_COMPOSE_FILE="$SYSTEM_PATH/docker/docker-compose.yml"
|
||||
|
||||
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"
|
||||
|
||||
docker compose -f "$DOCKER_COMPOSE_FILE" $DOCKER_COMPOSE_COMMAND
|
||||
}
|
||||
8
bin/denv
8
bin/denv
@ -1,14 +1,8 @@
|
||||
#!/bin/bash
|
||||
|
||||
ENV_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )/../" &> /dev/null && pwd )
|
||||
|
||||
denv() {
|
||||
if [ ! -z $1 ]
|
||||
then
|
||||
if [[ "$1" == "setup" ]]; then
|
||||
echo "SETUP IS ONLY ALLOWED ONCE AFTER CLOING THE ENVIRONMENT!!!"
|
||||
exit 0
|
||||
fi
|
||||
if [ ! -z $1 ] then
|
||||
$ENV_DIR/$1
|
||||
else
|
||||
cd $ENV_DIR
|
||||
|
||||
25
bin/denv_msg
Normal file
25
bin/denv_msg
Normal file
@ -0,0 +1,25 @@
|
||||
#!/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}$@"
|
||||
}
|
||||
@ -1,30 +0,0 @@
|
||||
#!/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
|
||||
@ -1,11 +0,0 @@
|
||||
#!/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
|
||||
@ -1,27 +0,0 @@
|
||||
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`)"
|
||||
34
init
34
init
@ -1,33 +1,17 @@
|
||||
#!/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
|
||||
|
||||
EXIT=0
|
||||
ENV_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
|
||||
|
||||
# Check docker-compose.yml file
|
||||
if [ ! -f "$SCRIPT_DIR/docker/docker-compose.yml" ]
|
||||
if [ ! -f "$ENV_DIR/docker/docker-compose.yml" ]
|
||||
then
|
||||
cp "$SCRIPT_DIR/docker/docker-compose.yml.dist" "$SCRIPT_DIR/docker/docker-compose.yml"
|
||||
EXIT=1
|
||||
cp "$ENV_DIR/docker/docker-compose.yml.dist" "$ENV_DIR/docker/docker-compose.yml"
|
||||
fi
|
||||
|
||||
# Check docker-compose-mac.yml file
|
||||
if [ ! -f "$SCRIPT_DIR/docker/docker-compose-mac.yml" ]
|
||||
then
|
||||
cp "$SCRIPT_DIR/docker/docker-compose-mac.yml.dist" "$SCRIPT_DIR/docker/docker-compose-mac.yml"
|
||||
EXIT=1
|
||||
fi
|
||||
# Update .profile
|
||||
$ENV_DIR/script/update_profile
|
||||
|
||||
# Clone all systems.
|
||||
$ENV_DIR/script/clone
|
||||
|
||||
if [ $EXIT -eq 1 ]
|
||||
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
|
||||
# Run init for all systems
|
||||
./script/foreachSystem init
|
||||
|
||||
33
script/foreachSystem
Executable file
33
script/foreachSystem
Executable file
@ -0,0 +1,33 @@
|
||||
#!/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
|
||||
|
||||
# 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_PATH..."
|
||||
$COMMAND_PATH
|
||||
fi
|
||||
done < "$CONFIG_FILE"
|
||||
34
script/update_profile
Executable file
34
script/update_profile
Executable file
@ -0,0 +1,34 @@
|
||||
#!/bin/bash
|
||||
ENV_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )/.." &> /dev/null && pwd )
|
||||
|
||||
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
|
||||
echo "[DEV-ENV]: Template file '$TEMPLATE_FILE' does not exist. Skip updating .profile."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
TEMPLATE_CONTENT=$(<"$TEMPLATE_FILE")
|
||||
|
||||
echo "[DEV-ENV]: Update $PROFILE_FILE"
|
||||
|
||||
# Check if start marker already exists in profile file
|
||||
if grep -q "$START_MARKER" "$PROFILE_FILE"; then
|
||||
echo "[DEV-ENV]: Section already exists. Update contents..."
|
||||
|
||||
# Remove contents between start and end marker
|
||||
sed -i "/$START_MARKER/,/$END_MARKER/d" "$PROFILE_FILE"
|
||||
else
|
||||
echo "[DEV-ENV]: Section does not exists. Adding contents..."
|
||||
fi
|
||||
|
||||
# Add contents
|
||||
echo -e "\n$START_MARKER\n$TEMPLATE_CONTENT\n$END_MARKER" >> "$PROFILE_FILE"
|
||||
|
||||
echo "[DEV-ENV]: Successfully updated $PROFILE_FILE"
|
||||
33
setup
33
setup
@ -1,33 +0,0 @@
|
||||
#!/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
2
systems/.gitignore
vendored
@ -1,2 +0,0 @@
|
||||
*
|
||||
!.gitignore
|
||||
Loading…
Reference in New Issue
Block a user