Browse code

gitserver: allow specifying build strategy

Cesar Wong authored on 2016/05/26 05:00:32
Showing 4 changed files
... ...
@@ -221,3 +221,25 @@ metadata:
221 221
 **NOTE**: A build will be started for the BuildConfig matching the name of the repository and for any BuildConfig 
222 222
 that has an annotation pointing to the source repository. If there is a BuildConfig that has a matching name but
223 223
 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 env dc/git BUILD_STRATEGY=docker
236
+```
237
+
238
+For OpenShift online which does not allow Docker type builds, you will need to set the strategy to `source` 
239
+if your repository contains a `Dockerfile`:
240
+
241
+```sh
242
+oc set env dc/git BUILD_STRATEGY=source
243
+```
244
+
245
+Valid values for BUILD_STRATEGY are "" (empty string), `source`, and `docker`.
... ...
@@ -79,6 +79,13 @@ items:
79 79
           - name: GENERATE_ARTIFACTS
80 80
             value: "true"
81 81
 
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
+
82 89
           # The script to use for custom language detection on a
83 90
           # repository. See hooks/detect-language for an example.
84 91
           # To use new-app's default detection, leave this variable
... ...
@@ -79,6 +79,13 @@ items:
79 79
           - name: GENERATE_ARTIFACTS
80 80
             value: "true"
81 81
 
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
+
82 89
           # The script to use for custom language detection on a
83 90
           # repository. See hooks/detect-language for an example.
84 91
           # To use new-app's default detection, leave this variable
... ...
@@ -16,18 +16,24 @@ function detect {
16 16
   local repoURL="$1"
17 17
   local repoName="$2"
18 18
   local detectionScript=${DETECTION_SCRIPT:-}
19
+  local buildStrategy=${BUILD_STRATEGY:-}
20
+  local strategyArg=""
21
+  if [[ -n "$buildStrategy" ]]; then 
22
+    strategyArg="--strategy=${buildStrategy}"
23
+  fi
24
+
19 25
   # The purpose of using a custom detection script is that users can customize the 
20 26
   # 'detect-language' script to return the image that's appropriate for their needs. 
21 27
   # It is possible to just have new-app do code detection. In that case, just set
22 28
   # the DETECTION_SCRIPT variable to an empty string.
23 29
   if [[ -z $detectionScript ]]; then
24
-    oc new-app "${repoURL}"
30
+    oc new-app "${repoURL}" $strategyArg
25 31
   else
26 32
     if ! lang=$($(dirname $0)/${detectionScript}); then
27 33
       return
28 34
     fi
29 35
     echo "detect: found language ${lang} for ${repoName}"
30
-    oc new-app "${lang}~${repoURL}"
36
+    oc new-app "${lang}~${repoURL}" $strategyArg
31 37
   fi
32 38
   # TODO: when a command to set a secret is available,
33 39
   # set an optional secret on the resulting build configuration