Configure Your Java build & deploy pipeline
Zerops provides a customizable build and runtime environment for your Java 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:
zerops:
# define hostname of your service
- setup: app
# ==== how to build your application ====
build:
# REQUIRED. Set the base technology for the build environment:
base: java@latest
# OPTIONAL. Set the operating system for the build environment.
# os: ubuntu
# 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
buildCommands:
- ./mvnw clean install
# REQUIRED. Select which files / folders to deploy after
# the build has successfully finished
deployFiles: target/app.jar
# 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: java@latest
# OPTIONAL. Sets the internal port(s) your app listens on:
ports:
# port number
- port: 8080
# OPTIONAL. Customize the runtime Java environment by installing additional
# dependencies to the base Java 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 Java application is started.
# initCommands:
# - rm -rf ./cache
# REQUIRED. Your Java application start command
start: java -jar target/app.jar
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:
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 Java builds:
- java@21java@latest
- java@17
The base build environment contains Alpine Linux, the selected version
of Java, Zerops command line tool, git and
wget.
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:
See the full list of supported build base environments.
To customize your build environment use the prepareCommands attribute.
Modifying the base technology will invalidate your build cache. See our Build Cache Documentation for more details about cache invalidation.
os
OPTIONAL. Sets the operating system for the build environment.
Following options are available:
alpineubuntu
Default value is alpine.
We are currently using following os version:
- Alpine Linux
- Ubuntu
The os version is fixed and cannot be customized.
Changing the OS setting will invalidate your build cache. See our Build Cache Documentation for details about cache behavior.
prepareCommands
OPTIONAL. Customizes the build environment by installing additional dependencies or tools to the base build environment.
The base build environment contains:
- Alpine Linux
- selected version of Java defined in the base attribute
- Zerops command line tool
gitandwget
To install additional packages or tools add one or more prepare commands:
zerops:
# hostname of your service
- setup: app
# ==== how to build your application ====
build:
# REQUIRED. Set the base technology for the build environment:
base: java@latest
# 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
- create a build container
- download your application code from your repository
- 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.
These commands are skipped when using cached environment. Modifying prepareCommands will invalidate your build cache. See our Build Cache Documentation 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 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
OPTIONAL. Defines build commands.
Build commands are optional. Zerops triggers each command in the defined order in a dedicated build container, running from the /build/source directory.
Before the build commands are triggered the build container contains:
- base environment defined by the base attribute
- optional customisation of the base environment defined in the prepareCommands attribute
- your application code
Run build commands as a single shell instance
Use following syntax to run all commands in the same environment context. For example, if one command changes the current directory, the next command continues in that directory. When one command creates an environment variable, the next command can access it. Suppose your mvnw executable file is in a cmd directory.
Run build commands as a separate shell instances
When the following syntax is used, each command is triggered in a separate environment context. For example, each shell instance starts in the home directory again. When one command creates an environment variable, it won't be available for the next command. Suppose your mvnw executable file is in a cmd directory.
Command exit code
If any command fails, it returns an exit code other than 0 and the build is canceled. Read the build log to troubleshoot the error. If the error log doesn't contain any specific error message, try to run your build with the -X debug option.
If the command ends successfully, it returns the exit code 0 and Zerops triggers the following command. When all buildCommands are finished, the application build is completed and ready for the deploy phase.
deployFiles
REQUIRED. Selects which files or folders will be deployed after the build has successfully finished. To filter out specific files or folders, use .deployignore file.
Determines files or folders produced by your build, which should be deployed to your runtime service containers.
The path starts from the root directory of your project (the location of zerops.yaml). You must enclose the name in quotes if the folder or the file name contains a space.
The files/folders will be placed into /var/www folder in runtime, e.g. ./src/assets/fonts would result in /var/www/src/assets/fonts.
Examples
Deploys a folder, and a file from the project root directory:
Deploys the whole content of the build container:
Deploys a folder, and a file in a defined path:
How to use a wildcard in the path
Zerops supports the ~ character as a wildcard for one or more folders in the path.
Deploys all file.txt files that are located in any path that begins with /path/ and ends with /to/
Deploys all folders that are located in any path that begins with /path/to/
Deploys all folders that are located in any path that begins with /path/ and ends with /to/
By default, ./src/assets/fonts deploys to /var/www/src/assets/fonts, keeping the full path. Adding ~, like ./src/assets/~fonts, shortens it to /var/www/fonts
.deployignore
Add a .deployignore file to the root of your project to specify which files and folders Zerops should ignore during deploy. The syntax follows the same pattern format as .gitignore.
To ignore a specific file or directory path, start the pattern with a forward slash (/). Without the leading slash, the pattern will match files with that name in any directory.
For consistency, it's recommended to configure both your .gitignore and .deployignore files with the same patterns.
Examples:
The example above ignores file.txt only in the root src directory.
This example above ignores file.txt in ANY directory named src, such as:
/src/file.txt/folder2/folder3/src/file.txt/src/src/file.txt
.deployignore file also works with zcli service deploy command.
cache
OPTIONAL. Defines which files or folders will be cached for the next build.
The cache attribute helps optimize build times by preserving specified files between builds.
The cache attribute supports the ~ wildcard character.
Learn more about the build cache system in Zerops.
envVariables
OPTIONAL. Defines the environment variables for the build environment.
Enter one or more env variables in following format:
Read more about environment variables in Zerops.
Runtime configuration
base
OPTIONAL. Sets the base technology for the runtime environment.
If you don't specify the run.base attribute, Zerops keeps the current Java version for your runtime.
Following options are available for Java builds:
- java@21java@latest
- java@17
zerops:
# hostname of your service
- setup: app
# ==== how to build your application ====
build:
# REQUIRED. Sets the base technology for the build environment:
base: java@latest
...
# ==== how to run your application ====
run:
# OPTIONAL. Sets the base technology for the runtime environment:
base: java@latest
...
The base runtime environment contains Alpine Linux, the selected major
version of Java, Zerops command line tool, gitandwget`.
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:
zerops:
# hostname of your service
- setup: app
# ==== how to build your application ====
build:
# REQUIRED. Sets the base technology for the build environment:
base: java@latest
...
# ==== how to run your application ====
run:
# OPTIONAL. Sets the base technology for the runtime environment:
base:
- java@latest
prepareCommands:
- zsc add nodejs@latest
...
See the full list of supported run base environments.
To customize your build environment use the prepareCommands attribute.