# Configure Your Ubuntu build & deploy pipeline Zerops provides a customizable build and runtime environment for your Ubuntu application. ## Add zerops.yaml to your repository Start by adding `zerops.yaml` file to the **root of your repository** and modify it to fit your application: ```yaml zerops: # define hostname of your service - setup: app # ==== how to build your application ==== build: # REQUIRED. Set the base technology for the build environment: base: ubuntu@24.04 # OPTIONAL. Customize the build environment by installing additional packages # or tools to the base build environment. prepareCommands: - sudo apt-get something - curl something else # OPTIONAL. Build your application, e.g. with not officially supported version of your favourite technology buildCommands: - go build -o app main.go # REQUIRED. Select which files / folders to deploy after # the build has successfully finished deployFiles: app # OPTIONAL. Which files / folders you want to cache for the next build. # Next builds will be faster when the cache is used. cache: some_file # ==== how to run your application ==== run: # OPTIONAL. Sets the base technology for the runtime environment: base: ubuntu@24.04 # OPTIONAL. Sets the internal port(s) your app listens on: ports: # port number - port: 8080 # OPTIONAL. Customize the runtime Ubuntu environment by installing additional # dependencies to the base Ubuntu runtime environment. prepareCommands: - sudo apt-get something - curl something else # OPTIONAL. Run one or more commands each time a new runtime container # is started or restarted. These commands are triggered before # your Ubuntu application is started. initCommands: - rm -rf ./cache # REQUIRED. Your Ubuntu application start command start: ./app ``` The top-level element is always `zerops`. ### Setup The first element `setup` contains the **hostname** of your service. A runtime service with the same hostname must exist in Zerops. Zerops supports the definition of multiple runtime services in a single `zerops.yaml`. This is useful when you use a monorepo. Just add multiple setup elements in your `zerops.yaml`: ```yaml zerops: # definition for app service - setup: app # optional build: ... # optional deploy: ... # required run: ... # definition for api service - setup: api # optional build: ... # optional deploy: ... # required run: ... ``` Each service configuration contains at least the `run` section. Optional `build` and `deploy` sections can be added to further customize your process. ## Build pipeline configuration ### base _REQUIRED._ Sets the base technology for the build environment. Following options are available for Ubuntu builds: ```yaml zerops: # hostname of your service - setup: app # ==== how to build your application ==== build: # REQUIRED. Sets the base technology for the build environment: base: ubuntu@24.04 ... ```
The base build environment contains Ubuntu, [Zerops command line tool](/references/cli), `git` and `wget`.
:::info You can change the base environment when you need to. Just simply modify the `zerops.yaml` in your repository. ::: If you need to install more technologies to the build environment, set multiple values as a yaml array. For example: ```yaml zerops: # hostname of your service - setup: app # ==== how to build your application ==== build: # REQUIRED. Sets the base technology for the build environment: base: - ubuntu@24.04 prepareCommands: - zsc add nodejs@latest ... ``` See the full list of supported [build base environments](/zerops-yaml/base-list#runtime-services). To customize your build environment use the [prepareCommands](#preparecommands) attribute. :::note Modifying the base technology will invalidate your build cache. See our [Build Cache Documentation](/features/build-cache) for more details about cache invalidation. ::: ### prepareCommands _OPTIONAL._ Customizes the build environment by installing additional dependencies or tools to the base build environment. The base build environment contains: - Ubuntu - [Zerops command line tool](/references/cli) - `git` and `wget` To install additional packages or tools add one or more prepare commands: ```yaml zerops: # hostname of your service - setup: app # ==== how to build your application ==== build: # REQUIRED. Set the base technology for the build environment: base: ubuntu@24.04 # OPTIONAL. Customize the build environment by installing additional packages # or tools to the base build environment. prepareCommands: - sudo apt-get something - curl something else ... ``` When the first build is triggered, Zerops will 1. create a build container 2. download your application code from your repository 3. run the prepare commands in the defined order The application code is available in `/build/source` before the prepare commands are triggered, so you can use any file from your repository in your prepare commands (e.g. a configuration file). The commands themselves run in the `/home/zerops` directory. :::note These commands are skipped when using cached environment. Modifying `prepareCommands` will invalidate your build cache. See our [Build Cache Documentation](/features/build-cache) for details about cache invalidation. ::: #### Command exit code If any command fails, it returns an exit code other than 0 and the build is canceled. Read the [build log](/ubuntu/how-to/logs#build-log) to troubleshoot the error. If the command ends successfully, it returns the exit code 0 and Zerops triggers the following command. When all prepare commands are finished, your custom build environment is ready for the build phase. #### Single or separated shell instances You can configure your prepare commands to be run in a single shell instance or multiple shell instances. The format is identical to [build commands](#buildcommands). ### buildCommands _OPTIONAL._ Defines build commands. ```yaml zerops: # hostname of your service - setup: app # ==== how to build your application ==== build: # REQUIRED. Set the base technology for the build environment: base: ubuntu@24.04 # OPTIONAL. Build your application buildCommands: -The base runtime environment contains Ubuntu, Zerops command line tool, `git` and `wget`.
:::info You can change the base environment when you need to. Just simply modify the `zerops.yaml` in your repository. ::: If you need to install more technologies to the runtime environment, set multiple values as a yaml array. For example: ```yaml zerops: # hostname of your service - setup: app # ==== how to build your application ==== build: # REQUIRED. Sets the base technology for the build environment: base: ubuntu@24.04 ... # ==== how to run your application ==== run: # OPTIONAL. Sets the base technology for the runtime environment: base: - ubuntu@24.04 prepareCommands: - zsc add nodejs@latest ... ``` See the full list of supported [run base environments](/zerops-yaml/base-list). To customise your build environment use the `prepareCommands` attribute. ### ports _OPTIONAL._ Specifies one or more internal ports on which your application will listen. Projects in Zerops represent a group of one or more services. Services can be of different types (runtime services, databases, message brokers, object storage, etc.). All services of the same project share a **dedicated private network**. To connect to a service within the same project, just use the service hostname and its internal port. For example, to connect to a Ubuntu service with hostname = "app" and port = 8080 from another service of the same project, simply use `app:8080`. Read more about [how to access a Ubuntu service](/references/networking/internal-access#basic-service-communication). Each port has following attributes: | **Parameter** | **Description** | | --- | --- | | port | Defines the port number. You can set any port number between *10* and *65435*. Ports outside this interval are reserved for internal Zerops systems. | | protocol | **Optional.** Defines the protocol. Allowed values are `TCP` or `UDP`. Default value is `TCP`. | | httpSupport | **Optional.** `httpSupport = true` is the default setting for TCP protocol. Set `httpSupport = false` if a web server isn't running on the port. Zerops uses this information for the configuration of public access. `httpSupport = true` is available only in combination with the TCP protocol. | ### prepareCommands _OPTIONAL._ Customises the Ubuntu runtime environment by installing additional dependencies or tools to the runtime base environment.The base Ubuntu environment contains Ubuntu, [Zerops command line tool](/references/cli) and `git` and `wget`. To install additional packages or tools add one or more prepare commands:
```yaml zerops: # hostname of your service - setup: app # ==== how to build your application ==== build: ... # ==== how to run your application ==== run: # OPTIONAL. Customise the runtime environment by installing additional packages # or tools to the base Ubuntu runtime environment. prepareCommands: - sudo apt-get something - curl something else ... ``` When the first deploy with a defined prepare attribute is triggered, Zerops will 1. create a prepare runtime container 2. optionally: [copy selected folders or files from your build container](#copy-folders-or-files-from-your-build-container) 3. run the `prepareCommands` commands in the defined order :::note `run.prepareCommands` run in the `/home/zerops` directory. ::: #### Command exit code If any command fails, it returns an exit code other than 0 and the deploy is canceled. Read the [prepare runtime log](/ubuntu/how-to/logs#prepare-runtime-log) to troubleshoot the error. If the command ends successfully, it returns the exit code 0 and Zerops triggers the following command. When all `prepareCommands` commands are finished, your custom runtime environment is ready for the deploy phase. #### Cache of your custom runtime environment Some packages or tools can take a long time to install. Therefore, Zerops caches your custom runtime environment after the installation of your custom packages or tools is completed. When the second or following deploy is triggered, Zerops will use the custom runtime cache from the previous deploy if following conditions are met: 1. Content of the [build.addToRunPrepare](#copy-folders-or-files-from-your-build-container) and `run.prepareCommands` attributes didn't change from the previous deploy 2. The custom runtime cache wasn't invalidated in the Zerops GUI. To invalidate the Zerops runtime cache go to your service detail in Zerops GUI, choose **Service dashboard & runtime containers** from the left menu and click on the **Open pipeline detail** button. Then click on the **Clear runtime prepare cache** button. When the prepare cache is used, Zerops doesn't create a prepare runtime container and executes the deployment of your application directly. #### Single or separated shell instances You can configure your prepare commands to be run in a single shell instance or multiple shell instances. The format is identical to [build commands](#buildcommands). ### Copy folders or files from your build containerThe prepare runtime container contains Ubuntu, [Zerops command line tool](/references/cli) and `git` and `wget`.
The prepare runtime container does not contain your application code nor the built application. If you need to copy some folders or files from the build container to the runtime container (e.g. a configuration file) use the `addToRunPrepare` attribute in the [build section](#build-pipeline-configuration). ```yaml zerops: # hostname of your service - setup: app # ==== how to build your application ==== build: ... addToRunPrepare: ./runtime-config.yaml # ==== how to run your application ==== run: # OPTIONAL. Customise the runtime environment by installing additional packages # or tools to the base Ubuntu runtime environment. prepareCommands: - sudo apt-get something - curl something else ... ``` In the example above Zerops will copy the `runtime-config.yaml` file from your build container **after the build has finished** into the new **prepare runtime** container. The copied files and folders will be available in the `/home/zerops` folder in the new prepare runtime container before the prepare commands are triggered. ### initCommands _OPTIONAL._ Defines one or more commands to be run each time a new runtime container is started or a container is restarted. ```yaml zerops: # hostname of your service - setup: app # ==== how to build your application ==== build: ... # ==== how to run your application ==== run: # OPTIONAL. Run one or more commands each time a new runtime container # is started or restarted. These commands are triggered before # your Ubuntu application is started. initCommands: - rm -rf ./cache ``` These commands are triggered in the runtime container before your Ubuntu application is started via the [start command](#start). :::note `run.initCommands` run in the `/var/www` directory. ::: Use init commands to clean or initialise your application cache or similar operations. :::caution The init commands will delay the start of your application each time a new runtime container is started (including the horizontal [scaling](/ubuntu/how-to/scaling) or when a runtime container is restarted). Do not use the init commands for customising your runtime environment. Use the [run:prepareCommands](#preparecommands-1) attribute instead. ::: #### Command exit code If any of the `initCommands` fails, it returns an exit code other than 0, but deploy is **not** canceled. After all init commands are finished, regardless of the status code, the application is started. Read the [runtime log](/ubuntu/how-to/logs#runtime-log) to troubleshoot the error. #### Single or separated shell instances You can configure your `initCommands` to be run in a single shell instance or multiple shell instances. The format is identical to [build commands](#buildcommands). ### envVariables _OPTIONAL._ Defines the environment variables for the runtime environment. Enter one or more env variables in following format: ```yaml zerops: # define hostname of your service - setup: app # ==== how to run your application ==== run: # OPTIONAL. Defines the env variables for the runtime environment: envVariables: MODE: production DB_NAME: db DB_HOST: db DB_USER: db DB_PASS: ``` Read more about [environment variables](/ubuntu/how-to/env-variables) in Zerops. ### start _OPTIONAL._ Defines the start command for your Ubuntu application. ```yaml zerops: # hostname of your service - setup: app # ==== how to build your application ==== build: ... # ==== how to run your application ==== run: # OPTIONAL. Your Ubuntu application start command start: ./app ``` ### health check _OPTIONAL._ Defines a health check. `healthCheck` requires either one `httpGet` object or one `exec` object. #### httpGet Configures the health check to request a local URL using a HTTP GET method. Following attributes are available: | Parameter | Description | | --- | --- | | port | Defines the port of the HTTP GET request. The readiness check will trigger a GET request on `{'http://127.0.0.1:{port}/{path}'}` | | path | Defines the URL path of the HTTP GET request. The readiness check will trigger a GET request on `{'http://127.0.0.1:{port}/{path}'}` | | host | **Optional.** The readiness check is triggered from inside of your runtime container so it always uses the localhost `127.0.0.1`. If you need to add a `host` to the request header, specify it in the `host` attribute. | | scheme | **Optional.** The readiness check is triggered from inside of your runtime container so no https is required. If your application requires a https request, set `scheme: https` | **Example:** ```yaml zerops: # hostname of your service - setup: app # ==== how to build your application ==== build: ... # ==== how to run your application ==== run: # OPTIONAL. Your Ubuntu application start command start: ./app # OPTIONAL. Define a health check with a HTTP GET request option. # Configures the check on http://127.0.0.1:80/status healthCheck: httpGet: port: 80 path: /status ``` #### exec Configures the health check to run a local command. Following attributes are available: | **Parameter** | **Description** | | --- | --- | | **command** | Defines a local command to be run. The command has access to the same environment variables as your Ubuntu application. A single string is required. If you need to run multiple commands create a shell script or, use a multiline format as in the example below. | **Example:** ```yaml zerops: # hostname of your service - setup: app # ==== how to build your application ==== build: ... # ==== how to run your application ==== run: # REQUIRED. Your Ubuntu application start command start: ./app # OPTIONAL. Define a health check with a shell command. healthCheck: exec: command: | touch grass rm -rf life mv /outside/user /home/user ``` ### crontab _OPTIONAL._ Defines cron jobs. Setup cron jobs in the following format: ```yaml zerops: # define hostname of your service - setup: app # ==== how to run your application ==== run: crontab: # REQUIRED. Sets the command to execute: - command: "" # REQUIRED. Sets the interval time to execute: timing: "0 * * * *" ``` Read more about setting up [cron](/zerops-yaml/cron) in Zerops. ## Deploy configuration ### readiness check _OPTIONAL._ Defines a readiness check. Read more about how the [readiness check works](/ubuntu/how-to/deploy-process#readiness-checks) in Zerops. `readinessCheck` requires either one `httpGet` object or one `exec` object. #### httpGet Configures the readiness check to request a local URL using a http GET method. Following attributes are available: | Parameter | Description | | --- | --- | | port | Defines the port of the HTTP GET request. The readiness check will trigger a GET request on `{'http://127.0.0.1:{port}/{path}'}` | | path | Defines the URL path of the HTTP GET request. The readiness check will trigger a GET request on `{'http://127.0.0.1:{port}/{path}'}` | | host | **Optional.** The readiness check is triggered from inside of your runtime container so it always uses the localhost `127.0.0.1`. If you need to add a `host` to the request header, specify it in the `host` attribute. | | scheme | **Optional.** The readiness check is triggered from inside of your runtime container so no https is required. If your application requires a https request, set `scheme: https` | **Example:** ```yaml zerops: # hostname of your service - setup: app # ==== how to build your application ==== build: ... # ==== how to deploy your application ==== deploy: # OPTIONAL. Define a readiness check with a HTTP GET request option. # Configures the check on http://127.0.0.1:80/status readinessCheck: httpGet: port: 80 path: /status # ==== how to run your application ==== run: ... ``` Read more about how the [readiness check works](/ubuntu/how-to/deploy-process#readiness-checks) in Zerops. #### exec Configures the readiness check to run a local command. Following attributes are available: | **Parameter** | **Description** | | --- | --- | | **command** | Defines a local command to be run. The command has access to the same environment variables as your Ubuntu application. A single string is required. If you need to run multiple commands create a shell script or, use a multiline format as in the example below. | **Example:** ```yaml zerops: # hostname of your service - setup: app # ==== how to build your application ==== build: ... # ==== how to deploy your application ==== deploy: # OPTIONAL. Define a readiness check with a HTTP GET request option. # Configures the check on http://127.0.0.1:80/status readinessCheck: exec: command: | touch grass rm -rf life mv /outside/user /home/user ``` Read more about how the [readiness check works](/ubuntu/how-to/deploy-process#readiness-checks) in Zerops.