Skip to content

Latest commit

 

History

History
101 lines (84 loc) · 7.1 KB

CheatSheet.md

File metadata and controls

101 lines (84 loc) · 7.1 KB

ShutItFile Cheat Sheet

Commonly-used commands

CommandDescription
ASSERT_OUTPUT [arg] If the output from the previous command does not match, then throw an error
COMMENT [arg] Comment to pass through to the ShutIt script
CONFIG [name_arg] [default_value] A config item that can be defaulted to default_value (optional), with the name name_arg. Can be referred to elsewhere in the module with {{ shutit.name_arg }}.
For example, if you have a line 'CONFIG foo bar' then you could have another line such as: 'RUN rm {{ shutit.foo }}' which would be run as: 'RUN rm bar'. If no default is given, it is requested from the user.
CONFIG_SECRET [name_arg] [default_value] Same as CONFIG, but inputs the command interactively without echoing.
DELIVERY [arg] ShutIt delivery type (bash, docker)
DEPENDS [arg] Stipulate a dependency on a MODULE_ID
DESCRIPTION [arg] A description of the module
ELIF_NOT [condition] [arg] Start an ELSE block that runs commands if the condition is met (see conditions)
ELIF [condition] [arg] Start else ELSE block that runs commands if the if the condition is met (see conditions)
ELSE else block for an IF block
ENDIF end the IF block
ENV [name]=[value] Exports a variable in the local build context
EXPECT [arg] Continue if the specified regexp is seen in the output
EXPECT_MULTI ['[name1]=[value1]','[name2]=[value2]',...] A series of name-value pairs. If the 'name' is seen as a prompt, then SEND the value. eg EXPECT_MULTI ['sername=myuser','assword=mypass'] The name need not be seen in the output to continue successfully.
EXPECT_REACT ['[name1]=[value1]','[name2]=[value2]',...] A series of name-value pairs. If the 'name' is seen in the previous SEND's output, then SEND the value. eg EXPECT_REACT ['ERROR=echo ERROR > /tmp/res','OK=echo OK /tmp/res']
GET_PASSWORD [arg] Get a password from the user where appropriate. Only allowed after a LOGIN or USER line. [arg] is the prompt the user sees eg 'Input the password for the machine x'
IF [condition] [arg] Start an IF block that runs commands if the condition is met (see conditions)
IF_NOT [condition] [arg] Start an IF block that runs commands if the condition is met (see conditions)
INSTALL [arg] Install a package. Figures out local package manager
LOG [arg] Set the log level to [arg], which can be one of: DEBUG, INFO, WARNING, ERROR, CRITICAL
LOGIN [arg] Log in to a fresh shell with the given command (eg 'ssh user@host', or just 'bash'). Must be matched by a LOGOUT within the same section. See also LOGOUT, USER, GET_PASSWORD
LOGOUT Log out from a LOGIN/USER command
MAINTAINER [arg] Maintainer of the ShutIt module that is created
MODULE_ID [arg] A unique identifying string for this module, eg com.mycorp.myproject.mymodule
PAUSE_POINT [arg] Pause the build and give the user a shell to interact with. [arg] is the message the user sees eg 'Check all is ok'
QUIT [arg] Exit the run with a message [arg].
REMOVE [arg] Remove a package. Figures out local package manager
REPLACE_LINE ['filename=[filename]','line=[new line]','pattern=[regexp]'] Replace the line matched by pattern in filename with the newline
RUN [arg] See SEND
SCRIPT_BEGIN The lines following this directive are run as a shell script. See also SCRIPT_END
SCRIPT_END The termination of a SCRIPT section. See also SCRIPT_BEGIN
SEND [arg] String to input at terminal
UNTIL [arg] Send the previous command until the specified regexp is seen in the output
USER [arg] Become user specified (with su -). See also LOGIN, GET_PASSWORD, LOGOUT. Must be matched by a LOGOUT within the same section
VAGRANT_LOGIN [arg] Log into vagrant machine specified as root
VAGRANT_LOGOUT Log out of vagrant machine
WORKDIR [arg] Change directory during build

Conditions

ConditionDescription
FILE_EXISTS [arg]Conditional argument hinging on whether file (or directory) exists
RUN [arg]Conditional argument hinging on whether the command returned successfully
INSTALL_TYPE [arg]Conditional argument hinging on the type of installs in this env (eg apt, yum, emerge et al)

Examples:

Create a file if it does not exist:

IF_NOT FILE_EXISTS /tmp/mytmpfolder
	RUN mkdir /tmp/mytmpfolder
ENDIF

If wget not installed, create a file to mark that:

IF_NOT RUN wget --version
	RUN touch /tmp/no_wget
ENDIF

Docker delivery method

The following are only usable when 'DELIVERY docker' line is included, and are as per the Dockerfile syntax. ShutIt-specific notes are made here.

CommandDescription
FROM See Docker docs.
EXPOSE See Docker docs.
CMD See Docker docs.
ADD See Docker docs.
COPY See Docker docs.
VOLUME See Docker docs.
COMMIT Commit the container at this point. is the repository name, eg myrepo_name:mytag
PUSH Push the image with the tag

ShutIt Lifecycle specifiers

This is advanced, and optional functionality.

If not specified, then it is assumed we are in a 'BUILD' section.

CommandDescription
BUILD_BEGIN / BUILD_END Build section (the default). This is the body of the run.
TEST_BEGIN / TEST_END Test section. After all the modules' build sections are run, these sections are run. If any commands in these TEST sections fail, the entire run is deemed a failure.