Command line tool for publishing map services
NOTE: This is the current location for the slap
source code; the project was previously maintained at GISinc, but all new updates to the codebase will be made here.
Install from pip using pip install slap
- Basic example
- Migrating services through environments (i.e. dev, test, prod)
- Continous Integration
- Publishing Feature Services
- Importing slap modules in Python scripts
Slap supports the following commands:
Create a configuration file based on a directory; all arguments are optional.
usage: slap init [-h] [-c CONFIG] [-n NAME] [-r] [inputs [inputs ...]]
A list of directories to search for map documents when building the config; defaults to the current working directory.
Sets the hostname of the AGS server in config; defaults to hostname
.
Overrides the default config file path and name; defaults to config.json
in the current working directory.
Searches all map documents for data sources, and registers them with the geodatabase.
Publish services based on a configuration file
usage: slap publish [-h] -u USERNAME -p PASSWORD [-c CONFIG] [-g GIT] [-n NAME] [-s] [inputs [inputs ...]]
A list of map documents to publish; defaults to all documents listed in the config file.
Username for the AGS publisher account.
Password for the AGS publisher account.
Path to the config file to use for publishing; defaults to config.json
in the current working directory.
Republish all inputs that have changed since the previous commit; useful when publishing from a CI job.
Overrides the hostname of the AGS server in config; useful when publishing during a docker build.
Creates a new site before publishing; useful when publishing during a docker build.
Configuration files are handled per-environment; for example, you might have three separate config files, INT_config.json
, UAT_config.json
, and PROD_config.json
.
Each service is included in the config file as an object, grouped by service type.
An example configuration file might look like below. Note: The comments would need to be removed, json is not valid with them.
{
"agsUrl": "https://myagsserver.com:6443/arcgis/admin", // Required, URL for AGS admin endpoint
"tokenUrl": "https://myagsserver.com:6443/arcgis/tokens/generateToken", // Optional, URL for token service; defaults to AGS token endpoint
"verifyCerts": "/path/to/certs.pem", // Optional, either True to use default store, False to not verify, or path to cert file. Defaults to False.
"site": {}, // Optional, directory structure for creating a site
"json": {}, // Optional, specific parameters to use for all services, of all types.
"dataSources": [ // Optional, list of data items to add to the server store
{
"name": "slap-test",
"serverPath": "slap-test.gdb",
"clientPath": "slap-test.gdb"
}
],
"mapServices": {
"json": {}, // Optional, specific service parameters to use for all map services
"services": [
{
"input": "mxd/my_map_document.mxd", // Required
"output": "output/", // Optional, defaults to "output/"
"serviceName": "MyMapDocument", // Optional, defaults to MXD filename, "my_map_document" here
"serverType": "ARCGIS_SERVER", // Optional, defaults to "ARCGIS_SERVER"
"copyDataToServer": "False", // Optional, defaults to False
"folderName": "AutomationTests", // Optional, defaults to ""
"summary": "Test map service published automagically", // Optional, defaults to ""
"initialState": "STOPPED", // Optional, defaults to "STARTED"
"workspaces": [ // Optional; defaults to *NOT* replace workspace paths
{
"old": {
"path": "c:/path/to/integration/connectionFile.sde", // Required if workspaces is defined
"type": "SDE_WORKSPACE" // Optional, defaults to SDE_WORKSPACE, for file geodatabase, use "FILEGDB_WORKSPACE"
},
"new": {
"path": "c:/path/to/production/connectionFile.sde", // Required if workspaces is defined
"type": "SDE_WORKSPACE" // Optional, defaults to SDE_WORKSPACE, for file geodatabase, use "FILEGDB_WORKSPACE"
}
}
],
"json": {} // Optional, specific parameters for this service only
}
]
},
"gpServices": {
"json": {}, // Optional, specific service parameters to use for all gp services
"services": [
{
"input": "my_map_document.mxd", // Required, unique string to identify this entry
"result": "my_gp_service.rlt", // Required, path to result file,
"executionType", // Optional, defaults to 'Asynchronous'
"output": "output/", // Optional, defaults to "output/"
"serviceName": "MyGPService", // Optional, defaults to input value
"serverType": "ARCGIS_SERVER", // Optional, defaults to "ARCGIS_SERVER"
"copyDataToServer": "False", // Optional, defaults to False
"folderName": "AutomationTests", // Optional, defaults to ""
"summary": "Test GP service published automagically", // Optional, defaults to ""
"initialState": "STOPPED", // Optional, defaults to "STARTED"
"json": {} // Optional, specific parameters for this service only
}
]
}
}
Service properties can be specified at multiple levels in the file; the most
specific property will be used (i.e., service level, then type level, then
global). This allows for a minimum of configuration, while also allowing
for service parameters to vary. Note that the json
parameter is identical
what's specified in ESRI's REST API.
An example of the utilizing the json
parameter is enabling feature access
on a service.
To use separate credentials/data sources for different environments, you can supply an array of find/replace values under the workspaces
key. If this key is found,
the script will replace each old
workspace path (i.e., path to a connection file) with the new
value.
There are a few artifacts that need to be generated (via ArcMap) per service and/or environment, which are required for the process to run. These can be checked into source control if desired, and pulled down as needed.
- MXD files: "Source" document for map services
- Result files: "Source" document for GP services
- Database connection files: Needed per environment for publishing map services
- Config files: Needed per environment to specify publishing parameters
- Username/password: Credentials for publishing. These are not specified in the configuration file, but are passed in at the command line.
We welcome feedback and contributions; please see the contribution guide for details