Nomad Deployment Guide
This guide explains how to use the ProductifyFW CLI to manage Nomad deployments efficiently.
Overview
The pfy nomad commands streamline the deployment workflow by:
- Automatically updating Docker image versions in Nomad HCL files
- Validating job configurations before deployment
- Integrating with project version management
- Providing dry-run and plan-only modes for safety
Prerequisites
1. Install Nomad CLI
The pfy nomad commands require the Nomad CLI to be installed and accessible:
# macOS
brew install nomad
# Linux
wget https://releases.hashicorp.com/nomad/1.7.0/nomad_1.7.0_linux_amd64.zip
unzip nomad_1.7.0_linux_amd64.zip
sudo mv nomad /usr/local/bin/
# Verify installation
nomad version2. Configure Nomad Connection
Set up Nomad connection via environment variables:
export NOMAD_ADDR=http://nomad.example.com:4646
export NOMAD_TOKEN=your-nomad-token # If ACLs are enabledOr create a Nomad configuration file at ~/.nomad.d/config.hcl.
3. Initialize Project Configuration
# Initialize project configuration
pfy init --name my-project --language go
# This creates project.yaml with CI/registry configuration4. (Optional) Configure Nomad File Path
Add the nomad_file path to your project.yaml to avoid specifying it in every command:
ci:
type: github
language: go
registry: ghcr.io
image_name: my-project
nomad_file: nomad/manager.nomad # Path to your Nomad job fileWith this configured, you can run:
pfy nomad deploy --use-project-version
# Instead of:
pfy nomad deploy -f nomad/manager.nomad --use-project-versionBasic Deployment Workflow
1. Update Version
First, update your project version:
# Bump patch version (e.g., 1.2.3 -> 1.2.4)
pfy version bump --part patch
# Or set a specific version
pfy version set --version 1.3.0
# Check current version
pfy version show2. Deploy to Nomad
Deploy using the project version:
pfy nomad deploy -f path/to/job.nomad --use-project-versionThis will:
- Read version from
project.yaml - Update the Docker image tag in the Nomad HCL file
- Validate the job file
- Deploy the job to Nomad
Advanced Usage
Manual Image and Tag
Specify image and tag explicitly:
pfy nomad deploy -f manager.nomad \
--image ghcr.io/productifyfw/manager \
--tag v1.2.3Update Tag Only
Update just the tag while keeping the existing image name:
pfy nomad deploy -f manager.nomad --tag v1.2.3Safe Deployment with Planning
Preview changes before deploying:
# Plan the deployment
pfy nomad deploy -f manager.nomad --tag v1.2.3 --plan-only
# Review the output, then deploy
pfy nomad deploy -f manager.nomad --tag v1.2.3Dry Run
See what would change without modifying anything:
pfy nomad deploy -f manager.nomad --tag v1.2.3 --dry-runSkip Validation
If you're confident in your HCL file:
pfy nomad deploy -f manager.nomad --tag v1.2.3 --skip-validationMulti-Environment Deployments
Directory Structure
Organize Nomad files by environment:
nomad/
├── dev/
│ ├── manager.nomad
│ └── optimizer.nomad
├── staging/
│ ├── manager.nomad
│ └── optimizer.nomad
└── prod/
├── manager.nomad
└── optimizer.nomadDevelopment Environment
# Deploy latest development build
pfy nomad deploy -f nomad/dev/manager.nomad --tag dev-latestStaging Environment
# Promote a specific version to staging
pfy nomad deploy -f nomad/staging/manager.nomad --tag v1.2.3Production Environment
# Always use plan-only first in production
pfy nomad deploy -f nomad/prod/manager.nomad --tag v1.2.3 --plan-only
# Review the plan carefully, then deploy
pfy nomad deploy -f nomad/prod/manager.nomad --tag v1.2.3CI/CD Integration
GitHub Actions Example
name: Deploy to Nomad
on:
push:
tags:
- "v*"
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install pfy CLI
run: |
curl -LO https://github.com/ProductifyFW/cli/releases/latest/download/pfy-linux-amd64
chmod +x pfy-linux-amd64
sudo mv pfy-linux-amd64 /usr/local/bin/pfy
- name: Set up Nomad
env:
NOMAD_ADDR: ${{ secrets.NOMAD_ADDR }}
NOMAD_TOKEN: ${{ secrets.NOMAD_TOKEN }}
run: |
# Extract version from tag
VERSION=${GITHUB_REF#refs/tags/v}
# Deploy to staging
pfy nomad deploy -f nomad/staging/manager.nomad --tag v$VERSION
- name: Deploy to Production
if: github.event_name == 'release'
env:
NOMAD_ADDR: ${{ secrets.NOMAD_ADDR }}
NOMAD_TOKEN: ${{ secrets.NOMAD_TOKEN }}
run: |
VERSION=${GITHUB_REF#refs/tags/v}
pfy nomad deploy -f nomad/prod/manager.nomad --tag v$VERSIONGitLab CI Example
deploy:staging:
stage: deploy
script:
- VERSION=$(cat .version)
- pfy nomad deploy -f nomad/staging/manager.nomad --tag v$VERSION
environment:
name: staging
only:
- main
deploy:production:
stage: deploy
script:
- VERSION=$(cat .version)
- pfy nomad deploy -f nomad/prod/manager.nomad --tag v$VERSION --plan-only
# Requires manual approval in GitLab
environment:
name: production
only:
- tags
when: manualWorkflow Examples
Complete Release Workflow
# 1. Bump version
pfy version bump --part minor
# 2. Commit version change
git add project.yaml
git commit -m "Bump version to $(pfy version show)"
# 3. Create git tag
git tag v$(pfy version show)
git push && git push --tags
# 4. Deploy to staging
pfy nomad deploy -f nomad/staging/manager.nomad --use-project-version
# 5. Test staging...
# 6. Deploy to production (with plan)
pfy nomad deploy -f nomad/prod/manager.nomad --use-project-version --plan-only
# 7. Review plan, then deploy
pfy nomad deploy -f nomad/prod/manager.nomad --use-project-versionHotfix Workflow
# 1. Create hotfix branch
git checkout -b hotfix/critical-fix
# 2. Make fixes and bump patch version
pfy version bump --part patch
# 3. Deploy directly to production with planning
pfy nomad deploy -f nomad/prod/manager.nomad --use-project-version --plan-only
# 4. After review, deploy
pfy nomad deploy -f nomad/prod/manager.nomad --use-project-version
# 5. Merge back to main
git checkout main
git merge hotfix/critical-fixRollback Workflow
# 1. Find previous version
git log --oneline project.yaml
# 2. Deploy previous version
pfy nomad deploy -f nomad/prod/manager.nomad --tag v1.2.2
# Or update project.yaml and use project version
pfy version set --version 1.2.2
pfy nomad deploy -f nomad/prod/manager.nomad --use-project-versionTroubleshooting
Nomad Connection Issues
# Verify Nomad connection
nomad status
# Check environment variables
echo $NOMAD_ADDR
echo $NOMAD_TOKENValidation Failures
# Validate the job file
pfy nomad validate -f manager.nomad
# Or use Nomad directly
nomad job validate manager.nomadImage Not Found
Ensure the image exists in your registry:
# Check if image:tag exists
docker pull ghcr.io/productifyfw/manager:v1.2.3Deployment Failures
# Check Nomad job status
nomad job status manager
# View allocations
nomad alloc logs <alloc-id>
# Check events
nomad alloc status <alloc-id>Best Practices
1. Always Plan Before Production
# Never deploy to production without planning first
pfy nomad deploy -f nomad/prod/app.nomad --tag v1.0.0 --plan-only2. Use Project Version Management
# Keep versions in sync with project.yaml
pfy nomad deploy -f job.nomad --use-project-version3. Tag Docker Images Properly
# Use semantic versioning for tags
pfy nomad deploy -f job.nomad --tag v1.2.3
# Avoid using 'latest' in production4. Separate Environment Configurations
Maintain separate Nomad job files for each environment with appropriate resource allocations and constraints.
5. Automate in CI/CD
Integrate deployment commands into your CI/CD pipeline for consistency and traceability.
6. Document Deployments
# Use git tags and commit messages
git tag -a v1.2.3 -m "Release v1.2.3: New features and bug fixes"