Publishing Workflows#

Common workflows for publishing layers to GeoServer using geoserver-cli.

PostGIS Publishing Workflow#

Complete Setup#

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# 1. Create workspace
./geoserver-cli workspace create production

# 2. Configure PostGIS connection in config file
# Edit configs/default.config.toml:
# [postgis]
# host = "db.example.com"
# database = "gis"
# user = "geoserver"
# password = "secure_password"

# 3. Publish all spatial tables
./geoserver-cli publish postgis --all -w production

# 4. Verify published layers
./geoserver-cli workspace get production

# 5. Apply styles
for layer in roads buildings water; do
  ./geoserver-cli style create ${layer}_style --sld @styles/${layer}.sld
  ./geoserver-cli layer update ${layer} --default-style ${layer}_style
done

# 6. Enable and advertise layers
for layer in roads buildings water; do
  ./geoserver-cli layer update ${layer} --enabled true --advertised true
done

Incremental Publishing#

1
2
3
4
# Publish new tables as they're added to PostGIS
./geoserver-cli publish postgis --all -w production

# Existing layers are automatically skipped

Schema-Specific Publishing#

1
2
3
4
5
# Publish from public schema
./geoserver-cli publish postgis --all -w production --pg-schema public

# Publish from staging schema
./geoserver-cli publish postgis --all -w staging --pg-schema staging_data

File Import Workflow#

Shapefile Import#

1
2
3
4
5
6
7
8
# 1. Prepare Shapefile (must be zipped)
zip -r data.shp.zip data.shp data.shx data.dbf data.prj

# 2. Import (requires Importer extension)
./geoserver-cli publish file --file data.shp.zip -w my_workspace

# 3. Configure layer
./geoserver-cli layer update data --default-style polygon_style --enabled true

GeoTIFF Import#

1
2
3
4
# Import raster
./geoserver-cli publish file --file elevation.tif -w my_workspace

# Note: Raster layers may need coverage store configuration

Multi-Environment Workflow#

Development → Staging → Production#

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
# Development
export GEOSRVCLI_CONFIG=dev
./geoserver-cli publish postgis --all -w dev

# Staging
export GEOSRVCLI_CONFIG=staging
./geoserver-cli publish postgis --all -w staging

# Production (with dry-run first)
export GEOSRVCLI_CONFIG=prod
./geoserver-cli publish postgis --all -w production --dry-run
./geoserver-cli publish postgis --all -w production

Automated Publishing#

Script Example#

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
#!/bin/bash
set -e

WORKSPACE="production"
CONFIG="prod"

export GEOSRVCLI_CONFIG=$CONFIG

# Publish all PostGIS tables
echo "Publishing PostGIS layers..."
./geoserver-cli publish postgis --all -w $WORKSPACE --concurrency 4

# Apply default style to all layers
echo "Applying styles..."
LAYERS=$(./geoserver-cli workspace get $WORKSPACE | awk '{print $1}')
for layer in $LAYERS; do
  ./geoserver-cli layer update $layer --default-style standard_style --enabled true
done

echo "Publishing complete!"

Validation Workflow#

Pre-Publish Validation#

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# 1. Dry run to see what would be published
./geoserver-cli publish postgis --all -w production --dry-run

# 2. Validate configuration
./geoserver-cli config validate

# 3. Test connection
./geoserver-cli workspace list

# 4. Publish
./geoserver-cli publish postgis --all -w production

Post-Publish Verification#

1
2
3
4
5
6
7
8
# 1. List published layers
./geoserver-cli workspace get production

# 2. Check layer configuration
./geoserver-cli layer update my_layer

# 3. Export for QGIS to verify
./geoserver-cli qgis export project -w production -o verify.qgs

Rollback Workflow#

Disable Layers#

1
2
3
4
# Disable problematic layers without deleting
for layer in problematic_layer1 problematic_layer2; do
  ./geoserver-cli layer update $layer --enabled false
done

Re-enable Layers#

1
2
3
4
# Re-enable after fixing issues
for layer in problematic_layer1 problematic_layer2; do
  ./geoserver-cli layer update $layer --enabled true
done

Best Practices#

  1. Always use dry-run first for production deployments
  2. Use version control for configuration files
  3. Test in development before staging/production
  4. Monitor concurrency - adjust based on server capacity
  5. Document workspace purposes and layer naming conventions
  6. Use filters to avoid publishing temporary/test tables
  7. Regular validation of configuration and published layers