Python script to deploy from a git repository to a local directory. Deseigned to be placed on a webserver, to deploy a web app.
- Place DEPLOY.py on destination web server.
- Create deployment config(s) in configs/ (under DEPLOYdir, from "config__APPENVNAME.json" example. (See "configs" section below.)
- Configure git credentials so "git" command can be run non-interactively.
- Execute:
python DEPLOY.py
orpython DEPLOY.py --status
- list available (configured) deployables- Deploy latest commit:
python DEPLOY.py APPENVNAME
- Deploy specific commit
python DEPLOY.py --hash SHORTCOMMITHASH APPENVNAME
- (Script will prompt user to execute again with an additional check parameter to confirm deployment.)
- Create deployment config in configs/ dir, with format "config__APPENVNAME.json". Config properties:
-
"gitCmd" (deprecated,optional): array of command args to run a local git commnand. Examples... ["git"], ["sudo", "-u", "otheruser", "git"]. Defaults to ["git"].
-
"cloneUrl": (optional) Will clone this git repository if a local repo doesn't exist.
-
"buildCmd_successCode": (optional) Deployment will be canceled if createBuildCmd return code != 0 (default). Supply a different value if createBuildCmd returns a less-standard code to indicate success. (e.g. Robocopy on Windows success return code is 1.)
-
"repoDir": path to local project repository dir. Can be an absolute path, or relative (relative to DEPLOY.py).
-
"branchName": git branch to checkout/deploy.
-
"createBuildCmd": custom create-a-build command (string), to be executed with python subprocess.call(). Must reference environment variable "BUILD_TEMP_DIR", and create a build there (Linux:
$BUILD_TEMP_DIR
, Windows:%BUILD_TEMP_DIR%
).- Executed from cwd=repoDir; (relative paths are relative to repoDir).
- To run multiple commands, insert multiple commands on one line.
- Examples:
- To just copy files from e.g. repoDir/source,
rsync -a source/dir/ $BUILD_TEMP_DIR
orcp -r source/dir/* $BUILD_TEMP_DIR
. - App has custom build cmd "repoDir/buildMe.py" that takes destination dir as an argument.
"python buildme.py $BUILD_TEMP_DIR"
. - App has custom build cmd "repoDir/buildMe.py" that creates build in hardcoded destination dir "repoDir/mybuild".
"python buildMe.py ; rsync -a mybuild/ $BUILD_TEMP_DIR"
.
- To just copy files from e.g. repoDir/source,
- Notes/quirks on commands for copying dirs:
- Note (rsync command): formats can be confusing, see https://stackoverflow.com/a/20301093. (ex:
rsync -a source/dir/ $BUILD_TEMP_DIR
) - Note (cp command): "*" in cp source path is a shell thing, not a command arg thing. [citation needed].
- Note: in Windows, "copy" command doesn't seem to work. Try xcopy, robocopy.
- Note (rsync command): formats can be confusing, see https://stackoverflow.com/a/20301093. (ex:
-
"deployToDir": final deploy destination on the server. Absolute path recommended.
-