gopkg.in/openshift/source-to-image.v1@v1.2.0/docs/cli.md (about) 1 # s2i command line interface 2 3 This document describes thoroughly all `s2i` subcommands and flags with explanation 4 of their purpose as well as an example usage. 5 6 Currently `s2i` has five subcommands, each of which will be described in the 7 following sections of this document: 8 9 * [create](#s2i-create) 10 * [build](#s2i-build) 11 * [rebuild](#s2i-rebuild) 12 * [usage](#s2i-usage) 13 * [version](#s2i-version) 14 * [help](#s2i-help) 15 16 Before diving into each of the aforementioned commands, let's have a closer look 17 at common flags that can be used with all of the subcommands. 18 19 | Name | Description | 20 |:-------------------------- |:--------------------------------------------------------| 21 | `-h (--help)` | Display help for the specified command | 22 | `--loglevel` | Set the level of log output (0-5) (see [Log levels](#log-levels))| 23 | `-U (--url)` | URL of the Docker socket to use (default: `unix:///var/run/docker.sock`) | 24 25 #### Log levels 26 27 There are six log levels: 28 * Level `0` - produces output from containers running `assemble` and `assemble-runtime` scripts and all encountered errors 29 * Level `1` - produces basic information about the executed process 30 * Level `2` - produces very detailed information about the executed process 31 * Level `3` - produces very detailed information about the executed process, along with listing tar contents 32 * Level `4` - currently produces same information as level `3` 33 * Level `5` - produces very detailed information about the executed process, lists tar contents, Docker Registry credentials, and copied source files 34 35 **NOTE**: All of the commands and flags are case sensitive! 36 37 # s2i create 38 39 The `s2i create` command is responsible for bootstrapping a new S2I enabled 40 image repository. This command will generate a skeleton `.s2i` directory and 41 populate it with sample S2I scripts you can start hacking on. 42 43 Usage: 44 45 ``` 46 $ s2i create <image name> <destination directory> 47 ``` 48 49 # s2i build 50 51 The `s2i build` command is responsible for building the Docker image by combining 52 the specified builder image and sources. The resulting image will be named according 53 to the tag parameter. 54 55 Usage: 56 ``` 57 $ s2i build <source location> <builder image> [<tag>] [flags] 58 ``` 59 The build command parameters are defined as follows: 60 61 1. `source location` - the URL of a Git repository or a local path to the source code 62 1. `builder image` - the Docker image to be used in building the final image 63 1. `tag` - the name of the final Docker image (if provided) 64 65 If the build image is compatible with incremental builds, `s2i build` will look for 66 an image tagged with the same name. If an image is present with that tag and a 67 `save-artifacts` script is present in the scripts directory, `s2i build` will save the build artifacts from 68 that image and add them to the tar streamed to the container into `/artifacts`. 69 70 #### Build flags 71 72 | Name | Description | 73 |:----------------------------|:--------------------------------------------------------| 74 | `-u (--allowed-uids)` | Specify a range of allowed user ids for the builder and runtime images. Ranges can be bounded (`1-10001`) or unbounded (`1-`). | 75 | `-n (--application-name`) | Specify the display name for the application (default: output image name) | 76 | `--as-dockerfile` | EXPERIMENTAL: Output a Dockerfile to this path instead of building a new image | 77 | `--assemble-user` | Specify the user to run assemble with | 78 | `--assemble-runtime-user` | Specify the user to run assemble-runtime with | 79 | `--callback-url` | URL to be invoked after a build (see [Callback URL](#callback-url)) | 80 | `--cap-drop` | Specify a comma-separated list of capabilities to drop when running Docker containers | 81 | `--context-dir` | Specify the sub-directory inside the repository with the application sources | 82 | `-c (--copy)` | Use local file system copy instead of git cloning the source url (allows for inclusion of empty directories and uncommitted files) | 83 | `--description` | Specify the description of the application | 84 | `-d (--destination)` | Location where the scripts and sources will be placed prior doing build (see [S2I Scripts](https://github.com/openshift/source-to-image/blob/master/docs/builder_image.md#s2i-scripts)) | 85 | `--dockercfg-path` | The path to the Docker configuration file | 86 | `-e (--env)` | Environment variable to be passed to the builder eg. `NAME=VALUE` | 87 | `-E (--environment-file)` | Specify the path to the file with environment | 88 | `--exclude` | Regular expression for selecting files from the source tree to exclude from the build, where the default excludes the '.git' directory (see https://golang.org/pkg/regexp for syntax, but note that \"\" will be interpreted as allow all files and exclude no files) | 89 | `--ignore-submodules` | Ignore all git submodules when cloning application repository. (defaults to false)| 90 | `--incremental` | Try to perform an incremental build | 91 | `--incremental-pull-policy` | Specify when to pull the previous image for incremental builds (always, never or if-not-present) (default "if-not-present") | 92 | `-i (--inject)` | Inject the content of the specified directory into the path in the container that runs the assemble script | 93 | `--network` | Specify the default Docker Network name to be used in build process | 94 | `-p (--pull-policy)` | Specify when to pull the builder image (`always`, `never` or `if-not-present`. Defaults to `if-not-present`) | 95 | `-q (--quiet)` | Operate quietly, suppressing all non-error output | 96 | `-r (--ref)` | A branch/tag that the build should use instead of MASTER (applies only to Git source) | 97 | `--rm` | Remove the previous image during incremental builds | 98 | `--run` | Launch the resulting image after a successful build. All output from the image is being printed to help determine image's validity. In case of a long running image you will have to Ctrl-C to exit both s2i and the running container. (defaults to false) | 99 | `-a (--runtime-artifact)` | Specify a file or directory to be copied from the builder to the runtime image (see [How to use a non-builder image for the final application image](https://github.com/openshift/source-to-image/blob/master/docs/runtime_image.md)) | 100 | `--runtime-image` | Image that will be used as the base for the runtime image (see [How to use a non-builder image for the final application image](https://github.com/openshift/source-to-image/blob/master/docs/runtime_image.md)) | 101 | `--runtime-pull-policy` | Specify when to pull the runtime image (always, never or if-not-present) (default "if-not-present") | 102 | `--save-temp-dir` | Save the working directory used for fetching scripts and sources | 103 | `-s (--scripts-url)` | URL of S2I scripts (see [S2I Scripts](https://github.com/openshift/source-to-image/blob/master/docs/builder_image.md#s2i-scripts)) | 104 | `--use-config` | Store command line options to .s2ifile | 105 | `-v (--volume)` | Bind mounts a local directory into the container that runs the assemble script | 106 107 108 #### Context directory 109 110 In the case where your application resides in a directory other than your repository root 111 folder, you can specify that directory using the `--context-dir` parameter. The 112 specified directory will be used as your application root folder. 113 114 #### Injecting directories to build 115 116 If you want to inject files that should only be available during the build (ie 117 when the assemble script is invoked), you can specify the directories from which 118 the files will be copied into the container that runs the assemble script. To do 119 so you can invoke S2I as follows: 120 121 ```console 122 $ s2i build --inject /mydir:/container/dir file://source builder-image output-image 123 ``` 124 125 In this case the content of the `/mydir` directory will get copied into 126 `/container/dir` inside the container which runs the assemble script. 127 After the `assemble` script finishes, all files copied will be truncated and thus 128 not available in the output image. The files are truncated instead of deleted 129 because the user under which we run the container with the assemble script might not 130 have permissions to delete files in the destination directory (eg. `/etc/ssl`). 131 132 You can also specify multiple directories, for example: `--inject /dir1:/container/dir1 --inject /dir2:container/dir2`. 133 134 You can use this feature to provide SSL certificates, private configuration 135 files which contains credentials, etc. 136 137 #### Callback URL 138 139 Upon completion (or failure) of a build, `s2i` can execute a HTTP POST to a URL with information 140 about the build: 141 142 * `success` - flag indicating the result of the build process (`true` or `false`) 143 * `labels` - labels of the resulting image 144 145 Example: data posted will be in the form: 146 ``` 147 { 148 "success": true, 149 "labels": { 150 "io.k8s.display-name": "my-app", 151 "io.openshift.s2i.build.image": "builder-image:latest", 152 ... 153 } 154 } 155 ``` 156 157 #### Example Usage 158 159 Build a Ruby application from a Git source, using the official `ruby-23-centos7` builder 160 image, the resulting image will be named `ruby-app`: 161 162 ``` 163 $ s2i build https://github.com/openshift/ruby-hello-world centos/ruby-23-centos7 ruby-app 164 ``` 165 166 Build a Node.js application from a local directory, using a local image, the resulting 167 image will be named `nodejs-app`: 168 169 ``` 170 $ s2i build /home/user/nodejs-app local-nodejs-builder nodejs-app 171 ``` 172 173 In case of building from the local directory, the sources will be copied into 174 the builder images using plain filesystem copy if the Git binary is not 175 available. In that case the output image will not have the Git specific labels. 176 Use this method only for development or local testing. 177 178 **NOTE**: All your changes have to be committed by `git` in order to build them with S2I. 179 180 Build a Java application from a Git source, using the official `openshift/wildfly-101-centos7` 181 builder image but overriding the scripts URL from local directory. The resulting 182 image will be named `java-app`: 183 184 ``` 185 $ s2i build --scripts-url=file://s2iscripts --ref=7.1.x --context-dir=kitchensink https://github.com/jboss-developer/jboss-eap-quickstarts openshift/wildfly-101-centos7 java-app 186 ``` 187 188 Build a Ruby application from a Git source, specifying `ref`, and using the official 189 `ruby-23-centos7` builder image. The resulting image will be named `ruby-app`: 190 191 ``` 192 $ s2i build --ref=my-branch https://github.com/openshift/ruby-hello-world centos/ruby-23-centos7 ruby-app 193 ``` 194 195 ***NOTE:*** If the ref is invalid or not present in the source repository then the build will fail. 196 197 Build a Ruby application from a Git source, overriding the scripts URL from a local directory, 198 and specifying the scripts and sources be placed in `/opt` directory: 199 200 ``` 201 $ s2i build --scripts-url=file://s2iscripts --destination=/opt https://github.com/openshift/ruby-hello-world centos/ruby-23-centos7 ruby-app 202 ``` 203 204 # s2i rebuild 205 206 The `s2i rebuild` command is used to rebuild an image already built using S2I, 207 or the image that contains the required S2I labels. 208 The rebuild will read the S2I labels and automatically set the builder image, 209 source repository and other configuration options used to build the previous 210 image according to the stored labels values. 211 212 Optionally, you can set the new image name as a second argument to the rebuild 213 command. 214 215 Usage: 216 217 ``` 218 $ s2i rebuild <image name> [<new-tag-name>] 219 ``` 220 221 222 # s2i usage 223 224 The `s2i usage` command starts a container and runs the `usage` script which prints 225 information about the builder image. This command expects `builder image` name as 226 the only parameter. 227 228 Usage: 229 ``` 230 $ s2i usage <builder image> [flags] 231 ``` 232 233 #### Usage flags 234 235 | Name | Description | 236 |:-------------------------- |:--------------------------------------------------------| 237 | `-d (--destination)` | Location where the scripts and sources will be placed prior invoking usage (see [S2I Scripts](https://github.com/openshift/source-to-image/blob/master/docs/builder_image.md#s2i-scripts))| 238 | `-e (--env)` | Environment variable passed to the builder eg. `NAME=VALUE`) | 239 | `-p (--pull-policy)` | Specify when to pull the builder image (`always`, `never` or `if-not-present`) | 240 | `--save-temp-dir` | Save the working directory used for fetching scripts and sources | 241 | `-s (--scripts-url)` | URL of S2I scripts (see [Scripts URL](https://github.com/openshift/source-to-image/blob/master/docs/builder_image.md#s2i-scripts))| 242 243 #### Example Usage 244 245 Print the official `ruby-23-centos7` builder image usage: 246 ``` 247 $ s2i usage centos/ruby-23-centos7 248 ``` 249 250 251 # s2i version 252 253 The `s2i version` command prints the version of S2I currently installed. 254 255 256 # s2i help 257 258 The `s2i help` command prints help either for the `s2i` itself or for the specified 259 subcommand. 260 261 ### Example Usage 262 263 Print the help page for the build command: 264 ``` 265 $ s2i help build 266 ``` 267 268 ***Note:*** You can also accomplish this with: 269 ``` 270 $ s2i build --help 271 ```