This lib implements docker wraps, where wrap is (image + container + related scripts in user env).
Tested in ubuntu. But, may work with other systems. This lib use jq
and docker
, which is going to be installed by script if not installed yet. Also all script are written on bash
, as it is default for development and clear to check what it does.
Why bash
- not to install unnecessary packages and keep the environment clean.
build.run.before
with all basedOn wraps taking into account, depends on is it asAbstact or not- Building image
- If new image have diffent id and not used
- Remove old one
build.run.after
- Init image
- If container doesn`t exist
- Run container with all basedOn wraps taking into account
- If container exists
- Compare container image id with current image id
- If it is different
- Remove container with all basedOn wraps taking into account
- Do all steps as for container not existing
- If it is same
- If container running
- Do exec on container with
run.args
andrun.commands
andother same options as for run
- Do exec on container with
- If container not running
- Start container with all basedOn wraps taking into account
- If container running
- If container running
- Stop container with all basedOn wraps taking into account
- If container running
- Kill container with all basedOn wraps taking into account
- If container running
- Kill wrap
- Remove container
- If no image of the same wrap
- Clean
- Remove image
- If no container of the same wrap
- Clean
Returns name of image or container taking into account uniquePrefix
Each dockerfile that will use basedOn should be started with this lines if based on is expected to work correctly.
ARG BASED_ON=""
FROM $BASED_ON
Used when image not created and just build options is forwarded, can be used only if wrap based on another wrap.
build
options will be executed depending on this property, so if asAbstact - not used for image before, but forwarded to image with basedOn.asAbstact
equals to true. That is what basedOn wraps taking into account means.
Means that wrap will be used, so uniquePrefix will be added, properties forwarded.
If you mention array - not the object in the basedOn
property - it will be treated as sequence of basedOn, where the first element is the closest to current wrap (so it will be used as BASED_ON argument), and the last one - the farthest. Moreover based on, elements closest to current wrap have higher priority than basedOns inside another basedOn wrap.
You can use get sequence
command to see the full sequence of basedOns. Or resolve it to a new file using resolve-sequence
command to see config by which the wrap will be created.
{
"uniquePrefix": "string", // all images and containers created from this file will have this prefix. It is expected that all images with this prefix created from this file
"wraps": {
"wrapName": {
"basedOn": "basedOn config schema OR array of basedOn config schemas", // optional, inform what will be set as BASED_ON argument
"dockerfile": "string", //optional, path to dockerfile
"build": {
"context": "string", // path to context, optional if can be extracted from basedOn
"run": {
"before": [
"string", //adding this string
{"value": "string", "action": "add|remove", "basedOnScope": "string" } // some action to do with value
], // optional, commands to do before making build
"after": [
"string", //adding this string
{"value": "string", "action": "add|remove", "basedOnScope": "string" } // some action to do with value
], // optional, commands to do after making build
},
"options": [
"string", //adding this string
{"value": "string", "action": "add|remove"} // some action to do with value
], // optional, additional options for build command
},
"run": {
"options":[
"string", //adding this string
{"value": "string", "action": "add|remove"} // some action to do with value
], // optional, additional options for run command
"volumes": [
{
"destination": "string",
"source": "string|null", //null meaning to remove
"readonly": "boolean", //optional
"nocopy": "boolean" //optional
}
], // optional, volumes for run command (it is only type=bind for now)
"entrypoint": {
"tool": "string|null", //optional
"args": [
"string",
{"value": "string", "action": "add|remove"} // some action to do with value
], //optional
"commands": [
"string", //adding this string
{"value": "string", "action": "add|remove", "continueInError": "boolean"/*optional, by default - false, when add, if remove - mentioned one or existing*/ } // some action to do with value
] //optional
},
"interactive": "boolean", //optional, boolean
},
"stop": {
"options":[
"string", //adding this string
{"value": "string", "action": "add|remove"} // some action to do with value
], // optional, additional options for stop command
"signal": "string|null", //optional
"timeout": "string|null", //optional
},
"kill": {
"options":[
"string", //adding this string
{"value": "string", "action": "add|remove"} // some action to do with value
], // optional, additional options for kill command
"signal": "string|null", //optional
},
"clean": [
"string", //adding this string
] //optional (commands to do to remove all staff left in the system) - this will be not executed during init, as do before fully implement it.
},
}, // Here will be all info about wraps, optional
}
{
"name": "string", // name of image, if expected to be done from this file uniquePrefix should not be added
"tag": "string", // tag for image, if expected to be created should be latest
"precreate": "boolean", // optional, is to create from this file. By default - false
"asAbstract": "boolean", // optional, by default - false, meaning is to extend only values
}
Commands below use main.sh
, so that file you need to create using example.sh
in the folder where you would like to execute it.
Also you need to create config file, you can use schema above, or use example.json
as a template.
You can use relative path depending where your main.sh
is located. You are free on choosing names. Also check that newly create file has right permissions. chmod +x ./main.sh
is recommended.
Command | Explanation | Syntax |
---|---|---|
get name |
Retrieves the name of the image or container associated with the specified configuration and wrap. | ./main.sh get name image <wrap_name> or ./main.sh get name container <wrap_name> |
get sequence |
Retrieves the basedOn sequence of some wrap. | ./main.sh get sequence <wrap_name> |
resolve-sequence |
Makes a new file with resolved sequence based on mentioned wrap. | ./main.sh resolve-sequence <wrap_name> <file_for_new_config> |
remove |
Removes the image or container associated with the specified configuration and wrap. | ./main.sh remove image <wrap_name> or ./main.sh remove container <wrap_name> or ./main.sh remove both <wrap_name> or ./main.sh remove all <container|image> or ./main.sh remove all <container|image|both> |
init |
Initializes resources (such as images or containers) based on the configuration and wrap. | ./main.sh init <wrap_name> |
start |
Starts the container or service defined by the configuration and wrap. | ./main.sh start <wrap_name> |
stop |
Stops the running container or service defined by the configuration and wrap. | ./main.sh stop <wrap_name> |
kill |
Forcefully stops (kills) the running container or service defined by the configuration and wrap. | ./main.sh kill <wrap_name> |
Replace <wrap_name>
with your actual paths and wrap name as needed.