dplz

command module
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 18, 2020 License: MIT Imports: 20 Imported by: 0

README

Dplz

Dplz is a deployment system that only requires BASH and SSH. No installation is required on the remote machine in order for it to work.

Dplz is capable of running shell commands and copying any type of file or directory contents. Dplz will also output a report that will tell the user if commands worked or failed.

Right now this software is in beta, but I would love for anyone and everyone to try it out and flood me with issues to work on.

On the horizon

  1. Basic tests
  2. Localhost support
  3. More advanced filtering
  4. Verbose output mode
  5. [insert your suggestion here]

How to install

# Get the project using go get
$ go get github.com/zveinn/dplz
# use go to install
$ go install .

How to get started

  1. Define a server
    • Server files can be located anywhere you please
  2. Define a deployment (optional)
    • Deployment files can be located anywhere you please
  3. Define variables
    • Variable files can be located anywhere you please
  4. Define a script
    • Script files need to be located within your project directory
  5. Run a deployment

Running deployments

# Just run a basic deployment
$ dplz -deployment=[PATH_TO_YOUR_DEPLOYMENT_FILE] 
# Run a deployment and ignore warning prompt
$ dplz -deployment=[PATH_TO_YOUR_DEPLOYMENT_FILE] -ignorePrompt 
# Run a deployment, ignore the warning prompt and use a filter.
$ dplz -deployment=[PATH_TO_YOUR_DEPLOYMENT_FILE] -ignorePrompt -filter "script.cmd"

# Run a deployment using command line arguments only.
$ dplz -servers=[PATH_TO_SEVER_FOLDER] -project=[PATH_TO_PROJECT_FOLDER] -vars=[PATH_TO_VARIABLES_FILE]

Command Line Arguments

Command line arguments can be combines with deployment json files. If you do combine them, the command line arguments will overwrite the deployment file settings.

	flag.String("deployment", "", "The path to your deployment file")
	flag.String("project", "", "The path to your project files (not needed if using a deployment file)")
	flag.String("servers", "", "The path to your server files (not needed if using a deployment file)")
	flag.String("vars", "", "The path to your variables file (not needed if using a deployment file)")
	flag.Bool("ignorePrompt", false, "Add this flag to skipt the confirmation prompt")
	flag.String("filter", "", "Only scripts or commands with this tag will be executed. Example: SCRIPT.CMD ")

Defining servers

Before you defined any deployments you need to define a target server.
Each server object contains some basic connections information, custom variables and PRE/POST scripts.

  • Variables are accessable in commands and tamplates.
  • Pre scripts will run BEFORE any other scripts run on that server
  • Post scripts will run AFTER all scripts have been executed.
{
    "hostname": "googlecloud-dev-01",
    "ip": "131.161.181.11", 
    "port": "22", 
    "key": "/home/user/.ssh/ssh-key", 
    "user": "root", 
    "variables": { 
        "privateIP": "11.11.11.11",
        "dns": "1.1.1.1"
    },
    "pre": [ 
        {"run": "echo 'This runs before all scripts'"}
    ],
    "post": [ 
        {"run": "echo 'This runs after all script'"}
    ]
}

Defining deployments

This part is purely optional, you can input all of the below parameters are command line arguments. But for the sake of replicating deployments we decided to add this "highest level object".
A Deployment will define the location of your server json files, project json files and the variables json file.

  • NOTE: Deployment wide variables are only configurable inside a deployment json file
{
    "servers": "PATH_TO_YOUR_SERVER_FOLDER",
    "project": "PATH_TO_YOUR_PROJECT_FOLDER",
    "vars": "PATH_TO_YOUR_VARIABLES_FILE",
    "variables": {
        "example": "This is an example custom variable"
    }
}

Defining variables

Variables are defined in a json.file and the -vars flag is used to load variables each time you run a deployment.

  • These variables are available inside commands and templates.
{
    "testVariable": "Dev variables loaded",
    "redisIP": "198.168.0.66",
    "sqlIP": "192.168.0.67"
}

Defining scripts

This is a basic script, it will contain some variables and some commands to execute. There are three types of commands:

  1. Run - Only runs a commands on the server
  2. File - Copies a file AS IS to the server ( follows SCP syntax )
  3. Template - Copies a file AND replaces variables ( follows SCP syntax )
{
    "name": "Basic deployment",
    "filter": "basic",
    "variables": {
        "name": "Some random name",
        "testVariable": "Here is some random text you can inject into a file..."
    },
    "cmd": [
        {
            "template": {
                "local": "files/webserver.template.conf",
                "remote": "/home/sveinn/meow/test.template",
                "mode": "0777"
            },
            "filter": "templates",
            "async": true
        },
        {
            "file": {
                "local": "files/meow",
                "remote": "/home/sveinn/meow/test.file",
                "mode": "0777"
            },
            "filter": "files",
            "async": true
        },
        {
            "run": "mkdir /home/sveinn/meow",
            "filter": "dir",
            "async": false
        },
        {
            "directory": {
                "local": "files",
                "remote": "/home/sveinn/meow",
                "mode": "0777"
            },
            "filter": "dir",
            "async": false
        },
        {
            "run": "uname -a",
            "filter": "uname",
            "async": false
        },
        {
            "run": "ls -la",
            "filter": "list"
        }
    ]
}

Ordering of scripts

Scripts do not have any guarentee to be ran in a particular order. The ordering is soly based on the directory walking machanism, which makes it non-dependable.

Ordering of commands

Commands present inside scripts will always be executed in order. Except if the async tag is specified, then ordering is not guaranteed for the commands flagged as async.

filtering

The filtering is currently a strict matching filter. The filter tag and the filter variables on the script or command need to match exactly.

Run a certain script and commands that match the filter

  • -filter scripts.cmd

Run a certain set of commands inside all filters

  • -filter *.cmd

Run all commands inside a scripts matching the filter

  • -filter scripts.*

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL