Build & Release Scripts
Build and release scripts allow you to customize what happens during your deployment process. Build scripts run during the deployment phase to prepare your application, while release scripts run after deployment to perform post-deployment tasks. Both are optional, but can be extremely useful for production applications.
Build Scripts
Build scripts run during the deployment process and are used to install dependencies, compile assets, and prepare your application for production. This is where you’ll run commands or build your static site.
When to Use Build Scripts
Build scripts are essential for:
- Installing dependencies - Running
npm install, orcomposer install - Compiling assets - Building frontend assets with tools like Vite, Webpack, or esbuild
- Static site generation - Running static site generators like Hugo, Jekyll, or Gatsby
- Transpiling code - Compiling TypeScript, Sass, or other preprocessors
- Optimizing production builds - Minifying assets or creating production bundles
Setting Up Your Build Script
- Create a build script file in your repository. We recommend
.webslice/build.shfor consistency, but you can place it anywhere in your repository. - Make the script executable by running
chmod +x .webslice/build.shbefore committing it. - Configure the script path in your website settings via the Webslice Console under
Settings»Build & Deploy.
Example Build Scripts
#!/bin/bashset -e
# Install Composer dependencies (production only)composer install --no-dev --optimize-autoloader
# Install Node dependencies and build assetsnpm cinpm run build
# Cache Laravel configuration/routes/templatesphp artisan config:cachephp artisan route:cachephp artisan view:cache#!/bin/bashset -e
# Install specific Hugo version if needed# wget https://github.com/gohugoio/hugo/releases/download/v0.120.0/hugo_extended_0.120.0_Linux-64bit.tar.gz# tar -xzf hugo_extended_0.120.0_Linux-64bit.tar.gz
# Build the static sitehugo --minify --environment productionRelease Scripts
Release scripts run after your deployment is live and serving traffic. They’re designed for tasks that should happen post-deployment, such as cache warming, database migrations, or notifying external services.
When to Use Release Scripts
Release scripts are useful for:
- Database migrations - Running schema updates or data migrations safely
- Cache warming - Pre-populating caches to improve performance
- External notifications - Notifying monitoring services about the deployment
- Post-deployment cleanup - Removing temporary files or clearing old caches
Setting Up Your Release Script
- Create a release script file in your repository. We recommend
.webslice/release.shfor consistency - Make the script executable with
chmod +x .webslice/release.shbefore committing it - Configure the script path in your website settings via the Webslice Console under
Settings»Build & Deploy
Example Release Scripts
#!/bin/bashset -e
# Run database migrationsphp artisan migrate --force
# Clear old cachesphp artisan cache:clear
# Warm up the application cachephp artisan cache:warm#!/bin/bashset -e
# Warm critical pagescurl -s https://yoursite.com/ > /dev/nullcurl -s https://yoursite.com/about > /dev/nullcurl -s https://yoursite.com/products > /dev/null
echo "Cache warming completed"Webslice Environment Flag
We automatically set the WEBSLICE environment variable to 1 during both build and release scripts. You can use this to conditionally run code specifically for Webslice deployments.
#!/bin/bashif [ "$WEBSLICE" = "1" ]; then echo "Running on Webslice platform" # Run Webslice-specific commandsfiAll environment variables you’ve configured in your website settings are also available during both build and release scripts, allowing you to use API keys, configuration values, and other secrets securely.
Viewing Logs
You can view the output from your build and release scripts at any time through the Webslice Console. Navigate to your website and look under the Activity section for:
- Website Deployment - Shows logs from your build script execution
- Website Release Phase - Shows logs from your release script execution
These logs are invaluable for debugging failed deployments, verifying that your scripts ran correctly, or troubleshooting performance issues. Each deployment maintains its own logs, so you can review historical deployments as well.
Best Practices
- Keep scripts idempotent: Scripts should be safe to run multiple times without causing issues
- Use version pinning: Lock dependency versions in
package-lock.json,composer.lockto ensure consistent builds - Fail fast: Use
set -eto stop immediately on errors rather than continuing with a bad build - Log important steps: Use
echostatements to log progress, making it easier to debug issues from logs - Test locally: Run your build and release scripts locally before deploying to catch issues early
- Keep them focused: Build scripts should build, release scripts should release. Don’t mix concerns