Skip to content

yejune/gorelay

Repository files navigation

Gorelay

SSH deployment tool inspired by PHP Envoy

Installation

go install github.com/yejune/gorelay@latest

Or build from source:

git clone https://github.com/yejune/gorelay.git
cd gorelay
go install .

Quick Start

# 1. Initialize in your project folder
gorelay init

# 2. Edit Gorelayfile.yaml (server info, task settings)

# 3. Run deployment
gorelay deploy

Commands

Command Description
gorelay Show available tasks (if Gorelayfile.yaml exists)
gorelay init Create Gorelayfile.yaml template
gorelay list List available tasks
gorelay <task> Run a task
gorelay <task> --on=<server> Run on specific server only
gorelay <task> -v Run with verbose output
gorelay help Show help

Gorelayfile.yaml Structure

# Server definitions
servers:
  production:
    host: example.com
    user: ubuntu
    key: ~/.ssh/id_rsa    # default: ~/.ssh/id_rsa
    port: 22              # default: 22

  staging:
    host: staging.example.com
    user: deploy

# Task definitions
tasks:
  deploy:
    description: "Deploy to production"
    on: [production]      # servers to run on (defaults to first server)
    scripts:
      - local: echo "Building locally"
      - sync: ./app:/remote/path/app
      - run: sudo systemctl restart myapp

  logs:
    description: "View logs"
    on: [production]
    scripts:
      - run: sudo journalctl -u myapp -f

Script Types

local - Run command locally

scripts:
  - local: npm run build

sync - Upload with checksum comparison (changed files only)

scripts:
  - sync: ./server:/app/server
  - sync: ./dist:/var/www/html

Features:

  • Compares SHA256 checksums before upload
  • Only uploads changed files
  • Verifies integrity after upload

tar - Upload as tar.gz (atomic)

scripts:
  - tar: ./server:/app/server
  - tar: ./dist:/var/www/html

Features:

  • Creates tar.gz in memory
  • Uploads and extracts on remote server
  • Atomic: all or nothing (no partial uploads)
  • Best for production deployments

scp - Direct upload (no checksum)

scripts:
  - scp: ./server:/app/server
  - scp: ./dist:/var/www/html

Features:

  • Fastest method (no checksum comparison)
  • Uploads all files unconditionally
  • Use for quick development deploys

run - Run command on remote server

scripts:
  - run: echo "Hello from server"
  - run: |
      cd /app
      ./server restart
      sudo systemctl restart myapp

Upload Comparison

Method Checksum Atomic Speed Use Case
sync ✓ (before + after) Medium Incremental deploys
tar ✓ (tar content) Medium Production deploys
scp Fast Development deploys

Example: Go Web Server Deployment

servers:
  production:
    host: example.com
    user: ubuntu
    key: ~/.ssh/id_rsa

tasks:
  deploy:
    description: "Deploy to production"
    on: [production]
    scripts:
      # 1. Build for Linux locally
      - local: GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o server-linux .

      # 2. Upload with tar (atomic)
      - tar: server-linux:/app/server-new

      # 3. Replace and restart on server
      - run: |
          cd /app
          mv server server-old 2>/dev/null || true
          mv server-new server
          chmod +x server
          sudo systemctl restart myapp

      # 4. Clean up local build file
      - local: rm -f server-linux

  status:
    description: "Check service status"
    on: [production]
    scripts:
      - run: sudo systemctl status myapp --no-pager

  logs:
    description: "Real-time logs"
    on: [production]
    scripts:
      - run: sudo journalctl -u myapp -f

  rollback:
    description: "Rollback to previous version"
    on: [production]
    scripts:
      - run: |
          cd /app
          mv server server-failed
          mv server-old server
          sudo systemctl restart myapp

Gorelayonment Variables

Gorelayonment variables can be used in Gorelayfile.yaml:

servers:
  production:
    host: $DEPLOY_HOST
    user: $DEPLOY_USER
    key: $SSH_KEY_PATH

Multi-Server Deployment

Multiple Hosts (Array)

servers:
  web:
    hosts:
      - web1.example.com
      - web2.example.com
      - web3.example.com
    user: ubuntu

tasks:
  deploy:
    on: [web]  # automatically expands to web[0], web[1], web[2]
    parallel: true
    scripts:
      - tar: ./app:/app/server-new
      - run: sudo systemctl restart myapp

Sequential Execution (default)

tasks:
  deploy:
    on: [web1, web2]  # runs sequentially
    scripts:
      - tar: ./app:/app/server-new
      - run: sudo systemctl restart myapp

Parallel Execution

tasks:
  deploy:
    on: [web1, web2, web3]
    parallel: true  # run on all servers simultaneously
    scripts:
      - tar: ./app:/app/server-new
      - run: sudo systemctl restart myapp

When running in parallel:

  • Deploys to all servers simultaneously
  • Output from each server is buffered and displayed in order
  • Returns error if any server fails

Specify Specific Server

gorelay deploy --on=web1

Logging

Enable file logging in Gorelayfile.yaml:

log:
  enabled: true
  path: ./gorelay.log  # default: gorelay.log

When enabled, all output is saved to the log file with timestamps.

Verbose Mode

Use -v flag for detailed output:

gorelay deploy -v

Shows:

  • SHA256 checksums for uploads
  • Elapsed time for each step
  • Total execution time

License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published