Vermeiden Sie das Festlegen der globalen Konfiguration an git
Repost von https://stackoverflow.com/questions/53233742/avoiding-committing-of-global-config-to-git
Ich schreibe ein Bereitstellungsskript, um eine Bereitstellung mit einer älteren Anwendung zu parametrisieren (und schließlich zu verknüpfen). Ich habe eine Reihe von <env>.<appname>.conf
Dateien sowie ein Implementierungsskript in einem git-Repo und eine parametrisierte "globals.inc" -Datei in meinem Repo erstellt.
Mein Problem ist, dass ich es in meinem dev-Verzeichnis bearbeiten könnte, ohne es für git zu verpflichten.
Ich habe mir überlegt, es in meine .gitignore
Datei aufzunehmen, aber das würde bedeuten, dass ich andere Probleme hätte, wenn ich die globals.inc
Datei mit möglichen neuen Variablen aktualisieren möchte .
Meine ursprüngliche Lösung bestand darin, eine globals.inc.template
Datei zu haben, die dann globals.inc
in das Verzeichnis eingefügt wird und das ( globals.inc
) in der .gitignore
. Ich hätte gerne ein paar Informationen, ob es einen eleganten Git-Trick gibt, den ich verwenden kann, oder ich sollte einfach die Schablonenroute wählen und die Vorlage kopieren, bevor die aufregenden Teile des Bereitstellungsskripts ausgeführt werden.
deploy.sh
#! /bin/bash #Inspiration: https://blog.rjmetrics.com/2010/02/01/simple-deploy-script-for-php-applications/ #Deployscript # Detect exactly 1 argument APP_NAME=MyAPP #GIT_ROOT=localhost:/repo #GIT_USER=josste #APP_REPO=$GIT_ROOT/$APP_NAME.git RELEASE_NAME=`date +"%Y-%m-%d-%H%M%S"` #inspiration: https://clubmate.fi/replace-strings-in-files-with-the-sed-bash-command/ configurer(){ # Loop the config array for i in "${!confs[@]}" do search=$i replace=$ # Note the "" after -i, needed in OS X sed -i "s/$/$/g" $GLOBALS_FILE done } #Get environment if (($# == 1)); then DEPLOY_ENV=$1 echo "Deploying $APP_NAME to $DEPLOY_ENV environment." DEPLOY_FILE=$DEPLOY_ENV.appname.conf else echo "Usage: deploy.sh " exit 1 fi if [ -f $DEPLOY_FILE ]; then #load Configuration . $DEPLOY_FILE #check if directory exists if [ -d $DEPLOY_DIR ]; then echo "folder $DEPLOY_DIR exists. locating globals.inc" GLOBALS_FILE="$DEPLOY_DIR/globals.inc" if [ -f $GLOBALS_FILE ]; then echo "file $GLOBALS_FILE found" GLOBALS="" #replace all variables in globals.inc configurer #add git version to file VER="$(git -C $DEPLOY_DIR rev-parse HEAD)" echo "define("\"APP_VERSION\"","\"$VER\"");" >> $GLOBALS_FILE else echo "expected to find $GLOBALS_FILE but there was nothing there" fi else echo "folder $DEPLOY_DIR not found" fi else echo "Could not find deploy file for $DEPLOY_ENV environment, it should be located in $DEPLOY_FILE" exit 1 fi
globals.inc
<?php /** * GLOBAL variables * */ error_log("SERVER_ADDR: " . $_SERVER["SERVER_ADDR"]); define("SITE_TITLE","¤SITE_TITLE¤"); define("SITE_NAME", "¤SITE_NAME¤"); define("SITE_FQDN", "¤SITE_FQDN¤"); define("DEFAULT_FROM_EMAIL", "¤DEFAULT_FROM_EMAIL¤"); define("SESSION_NAME","¤SESSION_NAME¤"); define("MYSQL_USERNAME","¤MYSQL_USERNAME¤"); define("MYSQL_PASSWORD","¤MYSQL_PASSWORD¤"); define("MYSQLDATABASENAME","¤MYSQL_DB_NAME¤"); define("MYSQL_HOSTNAME","¤MYSQL_HOSTNAME¤"); $mysqlConn = new mysqli(MYSQL_HOSTNAME, MYSQL_USERNAME, MYSQL_PASSWORD, MYSQLDATABASENAME, 3306); if ($mysqlConn->connect_errno) { echo "Failed to connect to MySQL: (" . $mysqlConn->connect_errno . ") " . $mysqlConn->connect_error; } $mysqlConn->query("SET NAMES 'utf8'");
Beispiel dev.myapp.conf
declare -A confs confs=( [¤SITE_TITLE¤]="MyAPP TestSite" [¤SITE_NAME¤]=myapptest [¤SITE_FQDN¤]=myapp.local [¤DEFAULT_FROM_EMAIL¤]=spam@stevnsvig.com [¤SESSION_NAME¤]=MyAppTestSession [¤MYSQL_HOSTNAME¤]=localhost [¤MYSQL_DB_NAME¤]=myappdb [¤MYSQL_USERNAME¤]=myappdbuser [¤MYSQL_PASSWORD¤]=0c5a1a783e45edsfsdf798sdfh943h59fd643yth943 ) DEPLOY_DIR=/d/Udvikling/MyApp GIT_BRANCH=development
0 Antworten auf die Frage
Verwandte Probleme
-
9
Was ist der Unterschied zwischen den Befehlen "su -s" und "sudo -s"?
-
4
Gutes freies Ubuntu Server-VMWare-Image benötigt
-
4
Was sind die Unterschiede zwischen den großen Linux-Distributionen? Werde ich es merken
-
2
Begrenzung der CPU-Auslastung für Flash in Firefox?
-
2
Wie kann ich mein Mikrofon unter Debian GNOME zum Laufen bringen?
-
2
Conky-Setups - Beispiele / Ideen?
-
3
Was sind die Unterschiede zwischen Linux Window Managern?
-
2
ThunderBird / Lichtsynchronisation mit SE k770i
-
4
Linux-Dateisystem
-
6
Vollbild-Flash langsam in KDE 4