Rancher API container execution tool https://github.com/emcniece/rgon-exec
126
#RGoN-Executor
A simple binary that executes a command on a container via Rancher API. Useful for quick access to container contents.
##Requirements
Must have 3 environment variables present to work:
CATTLE_URL=http://000.000.0.00:8080/v1
CATTLE_ACCESS_KEY=1234567890ABCDEFGHIJ
CATTLE_SECRET_KEY=1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcd
To provide these automatically within Rancher, add the Service Account labels to this stack:
labels:
io.rancher.container.create_agent: 'true'
io.rancher.container.agent.role: 'environment'
##Usage
~ ./rgon-exec -name=my-container-name -cmd="echo test"
Executing [echo test] on container [my-container-name]
test
websocket: close 1000 (normal)
~
###Flags
-name=myContainer: The name of a container, single string-cmd="": Command to send. Can be formatted like -name but should be wrapped in quotes if the command is multiple words.-debug: Optional Prints debug information##How It Works
For the following, assume that http://localhost:8080 is a Rancher instance, and that 1i160 is the ID of a container.
The Rancher API can be explored in a UI at http://localhost:8080/v1. This program makes calls to the Rancher API to find the URLs needed for making execute requests on containers.
The request sequence consists of 3 steps:
execute URL for the given containerexecute URL and specified commandThe execute URL can be obtained from http://localhost:8080/v1/containers/1i160 - it is grouped in the "actions" list. The right-side UI lets users click "execute" and will assist with building the execute command. Sending this request provides a response:
{
"id": null,
"type": "hostAccess",
"links": { },
"actions": { },
"baseType": "hostAccess",
"token": "biglongtokenstringetcetc...",
"url": "ws://localhost:8080/v1/exec/"
}
The token in this response contains data about the target container and command. After obtaining this response, the token is sent to the websocket URL, at which time the command is executed on the container.
##Building
Run with Go: go run executor.go -name=myContainer -cmd="echo test" -debug
Build with Go: go build
Content type
Image
Digest
Size
5.8 MB
Last updated
over 9 years ago
docker pull emcniece/rgon-exec:dev