Create a build configuration that pulls source from public repository
If your source is located in a public repository, create a build configuration with settings that include information about where to pull source from a public repository. For the build output, you can choose to specify registry details along with a registry secret to access your built image in the registry. Or, you can choose to let Code Engine take care of building the image for you from your source and storing the image in IBM Cloud Container Registry. For this case, you do not need to specify a registry secret or the location of the image registry.
Creating a build configuration does not create an image, but creates the configuration to build an image. You must then run a build that references the build configuration to create an image. The build configuration is not validated or used to create an image until the build is run. The build configuration enables multiple subsequent builds of an image, such as when changes are applied to the source repository.
You can choose to ignore certain file patterns from within your source code by using the .ceignore
file, which behaves similarly to a .gitignore
file. For example, entries for a .ceignore
file for a node.js
application might include node_modules
and .npm
. For more sample file patterns to ignore, see the GitHub .gitignore repository.
Creating a build configuration from the console (public repo)
-
Go to the Code Engine dashboard.
-
Select the project where you added your container registry.
-
From the project page, click Image builds.
-
From the Image build tab, click Create. The Specify build details side panel opens where you enter the details of your build.
-
In the Source section, enter a name for your build, the URL of your source repository, and your code repo access.
- If your code is in a public repo, use an HTTPS URL and select None for the code repo access. An example of an HTTPS URL is
https://github.com/IBM/CodeEngine
. - If your code is in a private repo, use an SSH URL for the code repo URL and either select the name of an existing code repo access or create a code repo access. An example
of an SSH URL is
git@github.com:IBM/CodeEngine.git
. - Optionally, select a source branch name. If you do not provide a branch name and you leave the field empty, Code Engine automatically uses the default branch of the specified repository. You can enter any other branch name, tag, or commit ID.
Click Next to continue.
- If your code is in a public repo, use an HTTPS URL and select None for the code repo access. An example of an HTTPS URL is
-
In the Strategy section, select the strategy that you want to use.
- If you select Dockerfile, you can also specify an alternative path for your Dockerfile.
- Select the size of your build under Build resources.
Click Next to continue.
-
In the Output section, enter the details of your container image.
- Select an existing registry secret, or click Create registry secret to add a new one.
- If you are building your image to a Container Registry instance that is in your account, you can select
Code Engine managed secret
and Code Engine creates and manages the secret for you. - Then, select the namespace, repository, and tag of the image you want to build. You can choose for Code Engine tp create and manage the namespace in Container Registry for you.
- If your image exists in Container Registry, you can select from the existing images, or enter a new repository or tag.
-
Click Done to finish the creation of the build.
After you create the build configuration, you must run the build to create the image file. After your image file is created, you can deploy an app or run a job with your newly built image file.
Creating a build configuration with the CLI (public repo)
To create a build configuration with the CLI, use the build create
command. For a complete listing of options, see the ibmcloud ce build create
command.
With the build create
command, you can choose to let Code Engine take care of building the image from your source for you and then storing the image in IBM Cloud Container Registry. For this automatic access case, you do not need to specify a registry secret or the location of the image registry. Or, you can specify the location for your build image output and provide a registry secret so that Code Engine can access and push the build result to
your registry.
Creating a build configuration with the CLI (with public repo source and automatic access to registry)
In this scenario, Code Engine builds an image from your public Git repository source, and automatically uploads the image to IBM Cloud Container Registry with automatic access. See Setting up authorities for image registries for more information about setting required permissions for Code Engine to automatically access these images in Container Registry.
Before you begin
-
Create a build configuration to build an image from a public Git repo and let Code Engine automatically store and access the image. For example, the following
build create
command creates a build configuration that is calledhelloworld-build
that builds from source in the public Git repohttps://github.com/IBM/CodeEngine
. In this example, the command uses the defaultdockerfile
strategy, and the defaultmedium
build size. Because the branch name of the repository is not specified with the--commit
option, Code Engine automatically uses the default branch of the specified repository, which ismain
for this Git repo. By not specifying the location of the image registry or a registry secret, Code Engine pushes the build output to IBM Cloud Container Registry with automatic access.ibmcloud ce build create --name helloworld-build --source https://github.com/IBM/CodeEngine --context-dir /hello
Example output
Creating build helloworld-build... OK
The following table summarizes the options that are used with the
build create
command in this example. For more information about the command and its options, see theibmcloud ce build create
command.Command description Option Description --name
The name of the build. Use a name that is unique within the project. This value is required.
- The name must begin with a lowercase letter.
- The name must end with a lowercase alphanumeric character.
- The name must be 55 characters or fewer and can contain letters, numbers, and hyphens (-).
--source
The URL of the Git repository that contains your source code; for example, https://github.com/IBM/CodeEngine
.--context-dir
The directory in the repository that contains the buildpacks file or the Dockerfile. Specify this value if your buildpacks file or Dockerfile is contained in a subdirectory. This value is optional. -
Use the
build get
command to check the status of your build.ibmcloud ce build get --name helloworld-build
Example output
Notice the generated name for the image, and that the name of the automatically created registry secret is of the format,
ce-auto-icr-private-<region>
.Getting build 'helloworld-build' OK Name: helloworld-build ID: abcdefgh-abcd-abcd-abcd-1a2b3c4d5e6f Project Name: myproject Project ID: 01234567-abcd-abcd-abcd-abcdabcd1111 Age: 2d15h Created: 2022-05-24T09:58:43-05:00 Build Type: git Status: Succeeded Reason: all validations succeeded Image: private.us.icr.io/ce--e97a8-odof2whblw5/build-helloworld-build Registry Secret: ce-auto-icr-private-us-south Build Strategy: dockerfile-medium Timeout: 10m0s Source: https://github.com/IBM/CodeEngine Commit: main Context Directory: /hello Dockerfile: Dockerfile
After you create the build configuration, you must run the build to create the image file. After your image file is created, you can deploy an app or run a job with your newly built image file.
Creating a build configuration with the CLI (with public repo source and user-provided access to registry)
In this scenario, Code Engine builds an image from your public Git repository source, and then uploads the image to your container registry with the registry access that you provide.
Before you begin
- Set up your Code Engine CLI environment.
- Create and work with a project.
- Create a registry secret so you can save your image.
-
Create a build configuration to build an image from a public Git repo and specify the location of the image registry for the build output with a registry secret. With the
build create
command, specify the--image
option to provide the location of the image registry, and specify the--registry-secret
option to access the registry. For example, the following command creates a build configuration that is calledhelloworld-build2
that builds from the public Git repohttps://github.com/IBM/CodeEngine
, and stores the image tous.icr.io/mynamespace/codeengine-helloworld
by using themyregistry
registry secret. In this example, the command uses the defaultdockerfile
strategy, and the defaultmedium
build size. Because the branch name of the repository is not specified with the--commit
option, Code Engine automatically uses the default branch of the specified repository, which ismain
for this Git repo.If you are using the
--strategy
option with the value ofdockerfile
, then ensure the--dockerfile
option is correctly set to the name of thedockerfile
. The default value for the--strategy
option isDockerfile
.ibmcloud ce build create --name helloworld-build2 --image us.icr.io/mynamespace/codeengine-helloworld --registry-secret myregistry --source https://github.com/IBM/CodeEngine --context-dir /hello
Example output
Creating build helloworld-build2... OK
The following table summarizes the options that are used with the
build create
command in this example. For more information about the command and its options, see theibmcloud ce build create
command.Command description Option Description --name
The name of the build. Use a name that is unique within the project. This value is required.
- The name must begin with a lowercase letter.
- The name must end with a lowercase alphanumeric character.
- The name must be 55 characters or fewer and can contain letters, numbers, and hyphens (-).
--image
The location of the image registry. The format of the location must be REGISTRY/NAMESPACE/REPOSITORY
orREGISTRY/NAMESPACE/REPOSITORY:TAG
whereTAG
is optional. IfTAG
is not specified, the default islatest
.--registry-secret
The registry secret that is used to access the registry. You can add the registry secret by running the secret create --format registry
command. The registry secret is used to authenticate with a private registry.--source
The URL of the Git repository that contains your source code; for example, https://github.com/IBM/CodeEngine
.--context-dir
The directory in the repository that contains the buildpacks file or the Dockerfile. Specify this value if your buildpacks file or Dockerfile is contained in a subdirectory. This value is optional. -
Use the
build get
command to check the status of your build.ibmcloud ce build get --name helloworld-build2
Example output
Getting build 'helloworld-build2' OK Name: helloworld-build2 ID: abcdefgh-abcd-abcd-abcd-1a2b3c4d5e6f Project Name: myproject Project ID: 01234567-abcd-abcd-abcd-abcdabcd1111 Age: 2d15h Created: 2021-03-14T14:48:19-05:00 Status: Succeeded Reason: all validations succeeded Image: us.icr.io/mynamespace/codeengine-helloworld Registry Secret: myregistry Build Strategy: dockerfile-medium Timeout: 10m0s Source: https://github.com/IBM/CodeEngine Commit: main Context Directory: /hello Dockerfile: Dockerfile
After you create the build configuration, you must run the build to create the image file. After your image file is created, you can deploy an app or run a job with your newly built image file.
If you receive a command validation failure, check that your secret exists. If you refer to an registry secret (--registry-secret
) for your image and the secret does not exist, see Accessing container registries.
For more information about builds, check the troubleshooting tips.