Skip to content

Commit dca53eb

Browse files
committed
gitserver: allow specifying build strategy
1 parent e65adfa commit dca53eb

File tree

4 files changed

+37
-2
lines changed

4 files changed

+37
-2
lines changed

examples/gitserver/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,3 +221,18 @@ metadata:
221221
**NOTE**: A build will be started for the BuildConfig matching the name of the repository and for any BuildConfig
222222
that has an annotation pointing to the source repository. If there is a BuildConfig that has a matching name but
223223
has an annotation pointing to a different repository, a build will not be invoked for it.
224+
225+
Build Strategy
226+
--------------
227+
228+
When automatically starting a build, the git server will create a Docker type build if a Dockerfile is present
229+
in the repository. Otherwise, it will attempt a source type build. To force the git server to always use one
230+
strategy, set the BUILD_STRATEGY environment variable.
231+
232+
Setting the BUILD_STRATEGY to `docker` will force new builds to be created with the Docker strategy:
233+
234+
```sh
235+
oc set dc/git BUILD_STRATEGY=docker
236+
```
237+
238+
Valid values for BUILD_STRATEGY are "" (empty string), `source`, and `docker`.

examples/gitserver/gitserver-ephemeral.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@ items:
7979
- name: GENERATE_ARTIFACTS
8080
value: "true"
8181

82+
# The strategy to use when creating build artifacts from a repository.
83+
# With the default empty value, a Docker build will be generated if
84+
# a Dockerfile is present in the repository. Otherwise, a source build
85+
# will be created. Valid values are: "", docker, source
86+
- name: BUILD_STRATEGY
87+
value: ""
88+
8289
# The script to use for custom language detection on a
8390
# repository. See hooks/detect-language for an example.
8491
# To use new-app's default detection, leave this variable

examples/gitserver/gitserver-persistent.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@ items:
7979
- name: GENERATE_ARTIFACTS
8080
value: "true"
8181

82+
# The strategy to use when creating build artifacts from a repository.
83+
# With the default empty value, a Docker build will be generated if
84+
# a Dockerfile is present in the repository. Otherwise, a source build
85+
# will be created. Valid values are: "", docker, source
86+
- name: BUILD_STRATEGY
87+
value: ""
88+
8289
# The script to use for custom language detection on a
8390
# repository. See hooks/detect-language for an example.
8491
# To use new-app's default detection, leave this variable

examples/gitserver/hooks/post-receive

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,24 @@ function detect {
1616
local repoURL="$1"
1717
local repoName="$2"
1818
local detectionScript=${DETECTION_SCRIPT:-}
19+
local buildStrategy=${BUILD_STRATEGY:-}
20+
local strategyArg=""
21+
if [[ -n "$buildStrategy" ]]; then
22+
strategyArg="--strategy=${buildStrategy}"
23+
fi
24+
1925
# The purpose of using a custom detection script is that users can customize the
2026
# 'detect-language' script to return the image that's appropriate for their needs.
2127
# It is possible to just have new-app do code detection. In that case, just set
2228
# the DETECTION_SCRIPT variable to an empty string.
2329
if [[ -z $detectionScript ]]; then
24-
oc new-app "${repoURL}"
30+
oc new-app "${repoURL}" $strategyArg
2531
else
2632
if ! lang=$($(dirname $0)/${detectionScript}); then
2733
return
2834
fi
2935
echo "detect: found language ${lang} for ${repoName}"
30-
oc new-app "${lang}~${repoURL}"
36+
oc new-app "${lang}~${repoURL}" $strategyArg
3137
fi
3238
# TODO: when a command to set a secret is available,
3339
# set an optional secret on the resulting build configuration

0 commit comments

Comments
 (0)