You can configure the source details for a build in the Build
custom resource (CR) by setting the value of the following fields:
-
source.git.url
: Defines the source location of the image available in a Git repository.
-
source.git.clonesecret
: References a secret in the namespace that contains the SSH private key for a private Git repository.
-
source.git.revision
: Defines a specific revision to select from the source Git repository. For example, a commit, tag, or branch name. This field defaults to the Git repository default branch.
-
source.contextDir
: Specifies the context path for the repositories where the source code is not present at the root folder.
The build controller does not automatically validate that the Git repository you specified for pulling an image exists. If you need to validate, set the value of the build.shipwright.io/verify.repository
annotation to true
, as shown in the following example:
apiVersion: shipwright.io/v1beta1
kind: Build
metadata:
name: buildah-golang-build
annotations:
build.shipwright.io/verify.repository: "true"
spec:
source:
git:
url: https://github.com/shipwright-io/sample-go
contextDir: docker-build
The build controller validates the existence of a Git repository in the following scenarios:
-
When you use the endpoint URL with an HTTP or HTTPS protocol.
-
When you have defined an SSH protocol, such as git@
, but not a referenced secret, such as source.git.clonesecret
.
The following examples show how you can configure a build with different set of source inputs.
Example: Configuring a build with credentials
You can configure a build with a source by specifying your credentials, as shown in the following example:
apiVersion: shipwright.io/v1beta1
kind: Build
metadata:
name: buildah-build
spec:
source:
git:
url: https://github.com/sclorg/nodejs-ex
clonesecret: source-repository-credentials
Example: Configuring a build with a context path
You can configure a build with a source that specifies a context path in the Git repository, as shown in the following example:
apiVersion: shipwright.io/v1beta1
kind: Build
metadata:
name: buildah-custom-context-dockerfile
spec:
source:
git:
url: https://github.com/userjohn/npm-simple
contextDir: docker-build
Example: Configuring a build with a tag
You can configure a build with a source that specifies the tag v.0.1.0
for the Git repository, as shown in the following example:
apiVersion: shipwright.io/v1beta1
kind: Build
metadata:
name: buildah-golang-build
spec:
source:
git:
url: https://github.com/shipwright-io/sample-go
revision: v0.1.0
Example: Configuring a build with environment variables
You can also configure a build that specifies environment variables, as shown in the following example:
apiVersion: shipwright.io/v1beta1
kind: Build
metadata:
name: buildah-golang-build
spec:
source:
git:
url: https://github.com/shipwright-io/sample-go
contextDir: docker-build
env:
- name: <example_var_1>
value: "<example_value_1>"
- name: <example_var_2>
value: "<example_value_2>"