Deploy Configuration
Overview
A deploy configuration defines how an application is released in one environment. Two modes are available: Standard deploy and Custom deploy.

Standard deploy
Spug pulls the code, builds and packages it, transfers it to the hosts and switches versions, with hook scripts you can customize at every stage. It suits most Git-based applications.
Standard deploy borrows ideas from the open-source project walle, thanks to its authors.
If you have used walle, you can migrate to standard deploy directly.
Basic settings

- Environment: the environment this configuration applies to, e.g. test / production. Several environments let the same application use different flows.
- Target hosts: one or more hosts the configuration deploys to; a deploy request can pick a subset of them.
- Git repository: the repository URL. For private repositories click Private repository? and choose Key authentication (add the public key of
Spugas a deploy key and use thesshURL) or Account / password authentication (http/httpsURL). - Deploy mode:
Paralleldeploys all hosts independently at the same time;Serialdeploys one host after another and stops on the first failure. - Review: when enabled, deploy requests must be approved by a user with review permission before they can be deployed.
- Notification: deploy result notifications via
DingTalk,Feishu,WeCombots or a customWebhook; enter the bot URL.
Build settings

- File filter:
IncludeorExcludepaths relative to the project root (one per line); only matching files are packaged or excluded, e.g. exclude.gitandnode_modules. - Before checkout: runs on the server (or container) that hosts
Spugin the repository directory. Avoid modifying tracked files here, otherwise the checkout may fail. - After checkout: runs on the
Spugserver in the checked-out source directory. This is where builds such asnpm run buildormvn packageusually happen.
Deploy settings

- Deploy path: the final path of the application on the hosts. The directory must not exist beforehand;
Spugcreates it and manages it as a symlink to the current version. Global variables can be used, e.g./www/$SPUG_APP_KEY. - Storage path: the directory on the hosts that keeps historical versions, e.g.
/data/repos/$SPUG_APP_KEY. - Versions: how many versions to keep; older build records and versions are deleted to free disk space, and this also limits how far you can roll back.
- Before deploy on host: runs on the target host in the directory of the new version before it goes live, for preparation steps.
- After deploy on host: runs on the target host in the live application directory, for example to restart services.
- All four hooks can use the global variables below and the configuration center values (exposed as
_SPUG_<identifier>_<key>environment variables); runenv | grep SPUGto list everything available. - The page keeps spinning after starting a background process with
nohupor&? - A deployment reports command not found?
Flow
- Build stage (server): pull the repository →
Before checkout→ check out the branch / tag / commit →After checkout→ package according to the file filter; the artifact is recorded in the build repository. - Deploy stage (hosts): remove versions beyond the configured count → transfer the artifact to the storage path →
Before deploy on host→ switch the deploy path symlink to the new version →After deploy on host.
One artifact can be released several times (for example to test hosts first and to production later); choosing a Build repository version in the deploy request skips the build stage.
Custom deploy
In this mode Spug simply runs the recorded actions in order and does not care where the code comes from. It suits unusual flows or artifacts produced by an external CI system.

Fields
- Environment / Target hosts / Deploy mode / Review / Notification: same as standard deploy.
- Local actions: any number of actions executed on the
Spugserver, always before the host actions. - Host actions: any number of actions executed on the target hosts in order. A host action is either Execute command or Data transfer.
Data transfer
A data transfer action copies files from the container or server running Spug to the target hosts:
- Data source
- Local path: a file or directory on the
Spugserver, as an absolute path. - Upload on deploy: the file is uploaded when the deploy request is created.
- Local path: a file or directory on the
- Filter: only for local paths;
IncludeandExcluderules with paths relative to the local path, several paths separated by commas. Ignored when the source is a file. - Target path: for uploads the target must be a file path (e.g.
/tmp/upload.tar.gz); for local paths the type must match the source (a file source needs a file target, a directory source a directory target), see the examples below.
For uploads note the following:
- The target can be a file path such as
/data/upload.jaror an existing directory on the host; in the latter case the file keeps its original name inside that directory. In most cases another action is needed to process the uploaded file. - When the target is a file path that does not exist yet,
Spugcreates the parent directory (/datain the example above) automatically. - The action overwrites an existing file every time it runs.
The examples below use the source code of Spug at /data/spug to illustrate local-path sources.
-
Local path
/data/spug, target/www/spug, filter offResultThe whole
/data/spugdirectory is copied to/www/spugon the hosts. If/www/spugalready exists there, it is deleted first. -
Local path
/data/spug, target/www/spug, filterIncludespug_api,spug_web/distResultOnly
spug_apiandspug_web/distare copied, so/www/spugon the hosts contains just these two directories afterwards.Excludeworks the same way but copies everything except the listed paths. -
Local path
/data/spug/README.md, target/www/spug/README.md, filterIncludespug_apiResultOnly
README.mdis copied; the filter is ignored because the source is a file. -
Local path
/data/spug/README.md, target/www/spug, filter offResultREADME.mdreplaces/www/spug, which becomes a file with the content ofREADME.md. This is a counter-example: when copying a file, give the target a full file path. -
Local path
/data/spug, target/www/spug/README.md, filter offResultThe whole
/data/spugdirectory is copied and namedREADME.md, so/www/spug/README.mdbecomes a directory. Another counter-example: when copying a directory, give the target a directory path.
Global variables
SPUG_APP_NAMEapplication nameSPUG_APP_KEYapplication identifierSPUG_APP_IDapplication IDSPUG_REQUEST_IDdeploy request IDSPUG_REQUEST_NAMEdeploy request titleSPUG_VERSIONdeploy request versionSPUG_BUILD_VERSIONinternal version number of the requestSPUG_ENV_IDenvironment IDSPUG_ENV_KEYenvironment identifierSPUG_DEPLOY_IDdeploy configuration IDSPUG_DEPLOY_TYPEdeploy type ("1" normal, "2" rollback, "3" webhook-triggered)SPUG_API_TOKENtoken for reading the configuration centerSPUG_HOST_IDID of the current host (host stage only)SPUG_HOST_NAMEIP / domain of the current host (host stage only)
Standard deploy variables
SPUG_REPOS_DIRsource storage directory, injected for standard and custom deploys ($SPUG_REPOS_DIR/$SPUG_DEPLOY_IDis the source directory of this deploy)SPUG_BUILD_IDID of the build record used by this deploySPUG_DST_DIRdeploy path on the target hostSPUG_GIT_BRANCHselected Git branch (branch-based deploys)SPUG_GIT_COMMIT_IDselected Git commit (branch-based deploys)SPUG_GIT_TAGselected Git tag (tag-based deploys)
Custom deploy variables
-
SPUG_RELEASEtheSPUG_RELEASEvalue entered in the deploy requestTipSPUG_RELEASE is split on spaces into numbered variables;
abc 123 defyields four variables:SPUG_RELEASE = abc 123 defSPUG_RELEASE_1 = abcSPUG_RELEASE_2 = 123SPUG_RELEASE_3 = def
Configuration center variables
The configuration of the application in the deploy environment (including dependent applications and services) is injected as _SPUG_ plus the upper-cased key, e.g. api_order_db_host becomes _SPUG_API_ORDER_DB_HOST. See Configuration API.
Passing variables between stages and updating configuration
Two special environment variables exported by server-side scripts (Before / After checkout or local actions of a custom deploy) are captured by Spug:
-
SPUG_GEV_*: variables with theSPUG_GEV_prefix are passed on to the host stage, so values computed during the build (an image tag, for instance) reach the host scripts:# After checkoutexport SPUG_GEV_IMAGE_TAG=$(git rev-parse --short HEAD)# After deploy on hostecho "deploying image $SPUG_GEV_IMAGE_TAG" -
SPUG_SET: in the formapp-or-service-identifier:environment-identifier:key=value, creates or updates a configuration center value during the deploy; the change is recorded in the configuration history:export SPUG_SET="api_order:prod:release_version=$SPUG_VERSION"