Giter Club home page Giter Club logo

s4's Introduction

English | 中文简体

Travel back and forth between local and remote workflow

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

Screenshot

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 the 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\""]
TRY Same as RUN, but will proceed to the next step regardless of the results TRY exit 1
RUN ls -lh
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 the 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 executing the command line

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

This will execute command at remote and set stdout to a 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 the current working directory of the 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 a 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 the 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 the remote server

eg COPY data.db data.db.bak

MOVE

Move file at the remote server

eg MOVE data.db data.db.bak

DELETE

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

eg DELETE file1 file2

RUN

Run the command at the local or remote server

Run at the 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 the local machine

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

Same as RUN, but will proceed to the next step regardless of the results

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.

of course, We can 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.

Tools

vscode-s4

License

The MIT License

s4's People

Contributors

axetroy avatar renovate[bot] avatar renovate-bot avatar imgbot[bot] avatar

Stargazers

祀画 avatar Jin avatar Banou avatar  avatar lihui (eric) avatar Amor avatar  avatar heimanba avatar  avatar iceice avatar  avatar Heyward Fann avatar

Watchers

 avatar ChunFuWu avatar  avatar  avatar

s4's Issues

重新定义格式

当前格式主要有几个问题

  1. 语意化不清晰
  2. 不支持多服务器
CONNECT [email protected]:22 AS 服务器1

SERVER 服务器1 {
	RUN echo "server 1"
	CWD /home/root/project
}

RUN echo "server local"

CONNECT [email protected]:22 AS 服务器2

SERVER 服务器2 {
	RUN echo "server 2"
	  
	CONNECT [email protected]:22 AS 服务器3

    SERVER 服务器3 {
       RUN echo "server 3"
    }
}

Dependency Dashboard

This issue provides visibility into Renovate updates and their statuses. Learn more

This repository currently has no open or pending branches.


  • Check this box to trigger a request for Renovate to run again on this repository

feat: support PIPE action to pipe remote stream to local

Initial version

cat ./path/to/remote_file.txt run at remote server and pipe stream to local command node node ./write_file.js

Proposal: 1

PIPE cat ./path/to/remote_file.txt | node ./write_file.js

Syntax: PIPE <remote command1> | <local command2>

Proposal: 2

RUN cat ./path/to/remote_file.txt PIPE node ./write_file.js

Syntax: RUN <remote command1> PIPE <local command2>

support VAR keyword

type 1

Set string literals

VAR webpackVersion = 3.0.0

RUN npm install webpack-cli@{{ webpackVersion }} -g

type 2

Setting environment variables

VAR LOCAL_GOPATH = $GOPATH:local

VAR REMOTE_GOPATH = $GOPATH:remote

RUN ls -lh {{LOCAL_GOPATH}}

RUN ls -lh {{REMOTE_GOPATH}}

type 3

set command output which runs in local

VAR npm_version <= ["node", "-p", "require('./package.json').version"]

RUN echo "local npm version {{ npm_version }}"

type 4

set command output which runs in remote

VAR npm_version <= node -p "require('./package.json').version"

RUN echo "local npm version {{ npm_version }}"

combine CMD and RUN action

This is a breaking change

# run in local machine
RUN ["node", "index.js"]

# run in remote server
RUN node index.js

To simplify the configuration file.

This also involves the problem of multi-text wrap.

eg.

RUN npm run lint \
 && npm run test \
 && npm run build

feat: add TRY action

The functions of TRY and RUN are basically the same

The difference is that TRY will continue to the next operation regardless of the success or failure of the command.

TRY ["do", "what", "ever", "you", "want"]

Action Required: Fix Renovate Configuration

There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.

Error type: undefined. Note: this is a nested preset so please contact the preset author if you are unable to fix it yourself.

remove BASH action

use CMD instead

you can also use like this:

BASH npm run build
CMD ["npm", "run", "build"]

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.