Another take on infrastructure as code.
npm install infcoAnother take on infrastructure as code.
Options
* salt (hex-encoded bytes)
* iv (hex-encoded bytes)
* cipherAlgorithm (string)
* hashAlgorithm (string)
* value (hex-encoded bytes)
``JSON`
{
"transform":"decrypt",
"salt":"3748a5b3f1",
"iv":"3748a5b3f1",
"cipherAlgorithm":"AES-256-CFB",
"hashAlgorithm":"sha256",
"value":"3748a5b3f1"
}`
To make it easier to obtain the appropriate JSON string, InfCo can be run with the command "encrypt" and the value to be encrypted. It will prompt for a password and then output the serialized JSON.shell`
infco encrypt someValue
Options
* path
* format ("string", "buffer")
`JSON`
{"transform": "fileContents", "path": "/tmp/myFile.txt", "format": "buffer"}
Options
* template (a template string)
`JSON`
{"transform": "template", "template": "VAR={{var1}}"}
Options
* format ("ISO" (default))
* part ("full" (default), "date")
`JSON`
{"transform": "utcTimestamp", "part": "date"}
config
* command (string | array of string)
`JSON`
{
"type": "exec",
"title": "create a directory",
"config": {
"command": [
"mkdir /tmp/test",
"touch /tmp/test/test.txt"
]
}
}
config
* host (string)
* port (number)
* socketPath (string)
* url (string)
* method (string): e.g. "get", "put", "post", "delete"
* ...
Either "host" and "port", or "socketPath" have to be specified.
`JSON`
{
"type": "request",
"title": "get page",
"config": {
"protocol": "http",
"host": "127.0.0.1",
"port": 80,
"method": "get",
"url": "/",
}
}
config
* filename (string)
* string (string)
`JSON`
{
"type": "fileFromString",
"title": "create a file from a string",
"config": {
"filename": "/tmp/test.txt",
"string": "test string"
}
}
config
* filename (string)
* line (string)
`JSON`
{
"type": "lineInFile",
"title": "put a line of text in a file",
"config": {
"filename": "/tmp/test.txt",
"line": "test string"
}
}
config
* protocol (string, default: "http")
* host (string)
* port (number)
* socketPath (string)
* urlPrefix (string): prefix to be used, if the database is not at root
* dockerContainer (string): name of the Docker container the database runs in
* dockerNetwork (string): name of the Docker network the database container is a member of
* name (string): name of the database
* auth (object): authentication object
* auth.username (string)
* auth.password (string)
* security (object)
* security.admins (object)
* security.admins.names (array of string): names of admin users
* security.admins.roles (array of string): roles of admin users
* security.members (object)
* security.members.names (array of string): names of members
* security.members.roles (array of string): roles of members
Either "host" and "port", "socketPath", or "dockerContainer" and "dockerNetwork" need to be specified.
If they are not specified, "127.0.0.1" is used as the default host and 5984 as the default port.
If "dockerContainer" and "dockerNetwork" are specified, the ip address of the container "dockerContainer" in the network "dockerNetwork" is set as the host.
Docker is contacted using the socket "/var/run/docker.sock".
`JSON`
{
"type": "couchDb",
"title": "creating couchDb",
"config": {
"urlPrefix": "/bookmark_couchdb",
"name": "bookmark",
"auth": {
"username": "couchDbUser",
"password": "couchDbPass"
},
"security": {
"admins": { "names": [], "roles": [ "bookmark_admin" ] },
"members": { "names": [], "roles": [ "bookmark_read", "bookmark_write" ] }
}
}
}
config
* url (string)
* content (string)
`JSON`
{
"type": "couchDbDocument",
"title": "checking CouchDb document",
"config": {
"method": "get",
"url": "/url",
"content": "{\"doc\": \"doc\"}",
"auth": {
"username": "couchDbUser",
"password": "couchDbPass"
}
}
}
config
* direction (string): either "get" or "put"
* remotePath (string)
* localPath (string)
`JSON`
{
"type": "transfer",
"title": "transferring file",
"config": {
"direction": "put",
"localPath": "/tmp/test.txt",
"remotePath": "/tmp/test2.txt"
}
}
config
* path (string): path of the backup files
* days (array of string)
* suffix (string): suffix of backup files
`JSON`
{
"type": "reviewBackups",
"title": "reviewing backups",
"config": {
"path": "/backup/",
"days": [0,1,7,28],
"suffix": "_mydata.zip"
}
}
config
* protocol (string, default: "http")
* host (string)
* port (number)
* socketPath (string, default: "/var/run/docker.sock"): path of a UNIX socket
* data (JSON object): Docker Composter configuration to process
* actions (array of strings): array of actions to perform
Either "host" and "port", or "socketPath" need to be provided.
If neither is provided, the default value for "socketPath" is used.
"data" only needs to be provided for the "create" action.
Allowed values for actions are:
* up (create the containers, networks, and volumes as specified in the Docker Composter configuration)
* down (remove the containers, networks, and volumes as specified in the Docker Composter configuration)
`JSON`
{
"type": "dockerComposter",
"title": "create containers, networks, and volumes",
"config": {
"data": {
"networks": {"test1_net": {}},
"volumes": {},
"containers": {
"test1_cont": {
"config": {
"Image": "nginx:alpine",
"NetworkingConfig": {"EndpointsConfig": {"test1_net": {}}}
}
}
}
},
"actions": ["up"]
}
}
config
* protocol (string, default: "http")
* host (string)
* port (number)
* socketPath (string, default: "/var/run/docker.sock"): path of a UNIX socket
* name (string): container name
* data (JSON object): data to be send with the request to create a container (see Docker API)
* actions (array of strings): array of actions to perform
Either "host" and "port", or "socketPath" need to be provided.
If neither is provided, the default value for "socketPath" is used.
"data" only needs to be provided for the "create" action.
Allowed values for actions are:
* create (create the container, if it does not exist)
* start (starts or restarts the container)
* stop
* wait (waits until the container exits)
* remove (removes a container, if it exists)
`JSON`
{
"type": "dockerContainer",
"title": "create and start container",
"config": {
"name": "test",
"data": {
"Image": "couchdb",
"Env": [
{"transform": "template", "template": "COUCHDB_USER={{user}}"}
],
"HostConfig": {
"RestartPolicy": {"Name": "on-failure", "MaximumRetryCount": 10},
"Binds": [
"/opt/bookmark/couchdb/data:/opt/couchdb/data:z",
"/opt/bookmark/couchdb/config:/opt/couchdb/etc/local.d:z"
]
}
},
"actions": [
"create"
"start"
]
}
}
config
* protocol (string, default: "http")
* host (string)
* port (number)
* socketPath (string, default: "/var/run/docker.sock"): path of a UNIX socket
* actions (array of string)
* images (array of string): image to be created
Either "host" and "port", or "socketPath" need to be provided.
If neither is provided, the default value for "socketPath" is used.
Allowed values for actions are:
* prune (remove unused images)
* create
`JSON`
{
"type": "dockerImage",
"title": "prune images",
"config": {
"actions": [
"prune"
]
}
}
config
* protocol (string, default: "http")
* host (string)
* port (number)
* socketPath (string, default: "/var/run/docker.sock"): path of a UNIX socket
* networkName (string)
* containers (array of string)
* actions (array of string)
Either "host" and "port", or "socketPath" need to be provided.
If neither is provided, the default value for "socketPath" is used.
"containers" is only used for the actions "connect", "update", and "disconnect".
Allowed values for actions are:
* create (creates a network, if it does not exist)
* connect (adds the containers given in "containers" to the network)
* update (adds and removes containers from the network to ensure all containers from "containers" are in the network and only those)
* disconnect (removes the containers given in "containers" to the network)
* remove (removes a network, if it exists)
* prune (removes networks, which are not in use)
`JSON`
{
"type": "dockerNetwork",
"title": "confirm network",
"config": {
"networkName": "couch_test_network",
"containers": [
"couch_test"
],
"actions": [
"create",
"connect"
]
}
}
config
* protocol (string, default: "http")
* host (string)
* port (number)
* socketPath (string, default: "/var/run/docker.sock"): path of a UNIX socket
* volumeName (string)
* actions (array of string)
Either "host" and "port", or "socketPath" need to be provided.
If neither is provided, the default value for "socketPath" is used.
Allowed values for actions are:
* create (creates a volume, if it does not exist)
* remove (removes a volume, if it exists)
`JSON`
{
"type": "dockerVolume",
"title": "create volume",
"config": {
"volumeName": "couch_test_volume",
"actions": [
"create"
]
}
}
config
* ms (integer): wait time in milliseconds
`JSON`
{
"type": "wait",
"title": "wait for some time",
"config": {
"ms": 200
}
}
JSON
{
"hosts": [
{
"title": "Droplet",
"tags": ["test"],
"context": {
"type": "contextSsh",
"config": {
"host": "167.71.45.63",
"port": 22,
"username": "root",
"privateKey": { "transform": "fileContents", "format": "buffer", "path": "/home/user/.ssh/id_rsa"}
}
}
}
]
}
`
Task configuration
`JSON
{
"tags": ["test"],
"vars": {
"value": "testValue"
},
"tasks": [
{
"type": "fileFromString",
"title": "create file",
"config": {
"filename": "/tmp/templ.txt",
"string": {
"transform": "template",
"template": {"transform": "fileContents", "format": "string", "path": "exampleFiles/test.tmpl"}
}
}
}
]
}
`
Command
`shell
infco process -h hostConfig.json -t taskConfig.json
``