Code Monkey home page Code Monkey logo

s4's Introduction

Build Status Coverage Status Go Report Card Latest Version License Repo Size

s4

Integrate local and remote workflow.

Features:

  • Cross platform support
  • Declarative workflow
  • Upload local files to remote
  • Download remote files to local
  • Execute commands on the remote server

Usage

step 1: create a file name .s4

CONNECT [email protected]:22

RUN ls -lh

step 2: run the following command

> s4
[Step 1]: CONNECT [email protected]:22
? Please type remote server's password **********
[Step 2]: RUN ls -lh
total 20K
drwxr-xr-x  4 root root 4.0K Mar 15 10:10 test1
drwxr-xr-x  2 root root 4.0K Sep 23  2018 test2
drwxr-xr-x  6 root root 4.0K Sep 23  2018 test3
drwxr-xr-x  4 root root 4.0K Aug 27 16:25 test4

for more detail about command. print s4 --help

Documentation

Syntax Description Example
CONNECT Connect to the server. CONNECT [email protected]:22
CONNECT [email protected]:22 WITH PASSWORD 123
ENV Setting environment variables for remote server. ENV PRIVATE_KEY = 123
VAR Defining variables. VAR PRIVATE_KEY = 123
RUN echo {{PRIVATE_KEY}}
CD Change current working directory of remote server. CD /home/axetroy
UPLOAD Upload local files to remote server dir. UPLOAD local_file.txt ./remote_dir
DOWNLOAD Download remote files to local dir. DOWNLOAD remote_file.txt ./local_dir
COPY Copy file at remote server. COPY remote.db remote.db.bak
MOVE Move file at remote server. MOVE remote.bak remote.db
DELETE Delete files at remote server. DELETE remote_file_1.txt remote_file_2.txt
RUN Run command at local machine or remote server. RUN echo "run at remote"
RUN ["echo", "\"run at local\""]
CONNECT

Connect to remote SSH server. Its format should be <username>@<address>:<port> [WITH [PASSWORD|FILE] [VALUE]]

eg CONNECT [email protected]:22

eg CONNECT [email protected]:22 WITH PASSWORD you_password

eg CONNECT [email protected]:22 WITH FILE ./path/to/private/key/file

If password or private key file not provide. it will ask you to enter in terminal.

ENV

Set environmental variable for RUN command

eg ENV PRIVATE_KEY = 123

VAR

Defining variables. It has 3 ways to define it.

Set string literals

Its format is this VAR {key} = {value}

VAR PRIVATE_KEY = 123

RUN echo {{PRIVATE_KEY}}

Set environmental variable

Its format is this VAR {key} = ${envKey}:{tag}

tag can be local/remote. Used to specify to get local/remote environment variables.

CONNECT [email protected]:22

VAR GOPATH_LOCAL = $GOPATH:local

VAR GOPATH_REMOTE = $GOPATH:remote

RUN echo "remote GOPATH: {{GOPATH_REMOTE}}, local GOPATH: {{GOPATH_LOCAL}}"

Set stdout from execute the command line

Its format is this VAR {key} <= {bashCommand}.

This will execute command at remote and set stdout to variable.

or use the format VAR {key} <= ["{command}", "{argument1}", "{argument2}"]. It will run in local.

VAR NODE_VERSION_LOCAL <= ["node", "-v"]

VAR NODE_VERSION_REMOTE <= node -v

RUN echo "remote version: {{NODE_VERSION_REMOTE}}, local version: {{NODE_VERSION_LOCAL}}"
VAR PRIVATE_KEY = 123
ENV PRIVATE_KEY = {{PRIVATE_KEY}}
RUN echo {{PRIVATE_KEY}}
CD

Change current working directory of remote server

eg CD /home/axetroy

If the directory does not exist, an error will be thrown

This will affect all operations on the remote server, including upload/download/run commands, etc.

UPLOAD

Upload local files to remote server

eg UPLOAD start.py ./server

It required at least two parameters. The last parameter is the remote server's directory where should be uploaded.

The rest of the parameters are local files path.

DOWNLOAD

Download remote files to local

eg DOWNLOAD start.py ./server

It required at least two parameters. The last parameter is the local directory where should be downloaded.

The rest of the parameters are remote files path.

COPY

Copy file at remote server

eg COPY data.db data.db.bak

MOVE

Move file at remote server

eg MOVE data.db data.db.bak

DELETE

Delete files at remote server, for security, Linux dangerous directories will be ignored

eg DELETE file1 file2

RUN

Run command at local or remote server

Run at remote server

eg RUN python ./remote/start.py

It supports multi-line wrap

# run at remote
RUN npm version \
    && npm run build \
    && npm run test \
    && npm run publish

Run at local machine

# run at local machine
RUN ["npm", "run", "build"]

Installation

Download the executable file for your platform at release page

Then set the environment variable.

eg, the executable file is in the ~/bin directory.

# ~/.bash_profile
export PATH="$PATH:~/bin"

finally, try it out.

s4 --help

Upgrade

You can re-download the executable and overwrite the original file.

or type the following command to upgrade to the latest version. VAR

> s4 upgrade

Build from source code

> go get -v -u github.com/axetroy/s4
> cd $GOPATH/src/github.com/axetroy/s4
> make build

Test

make test

Why?

Why do I need such a tool? What is its use?

In development, we need to operate remote servers locally, such as deploying services, restarting services, upload files, etc.

We can of course do this with a bash script.

But that is quite cumbersome.

So, I wrote this tool to release my hands.

I hope this helps you.

License

The MIT License

s4's People

Contributors

axetroy avatar renovate-bot avatar renovate[bot] avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.