How To customize buildConfig

77 views
Skip to first unread message

cmou...@redhat.com

unread,
Nov 9, 2017, 3:51:30 AM11/9/17
to fabric8
Hi,

Is there a trick that I could use with f-m-p to customize the BuildConfig created as we can't define a buildconfig under src/main/fabric8 folder ? I want by example to setup an environment var such as ARTIFACT_COPY_ARGS=*.war ?

Regards

Charles

James Strachan

unread,
Nov 9, 2017, 5:48:03 AM11/9/17
to Charles Moulliard, fabric8
you could look at reusing the "mvn fabric8:import" goal to setup the BuildConfig. Maybe that could be configured/parameterised with additional env vars to add to the BuildConfig? There's work ongoing to improve that goal right now if you wanna help:

--
You received this message because you are subscribed to the Google Groups "fabric8" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fabric8+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
James
-------
Red Hat

Twitter: @jstrachan
Email: james.s...@gmail.com
Blog: https://medium.com/@jstrachan/

open source development platform

cmou...@redhat.com

unread,
Nov 9, 2017, 1:22:07 PM11/9/17
to fabric8
OpenShiftBuildService of f-m-p defines the BuildStrategy

            return new BuildStrategyBuilder()
                    .withType("Source")
                    .withNewSourceStrategy()
                    .withNewFrom()
                    .withKind(fromKind)
                    .withName(fromName)
                    .withNamespace(StringUtils.isEmpty(fromNamespace) ? null : fromNamespace)
                    .endFrom()
                    .endSourceStrategy()
                    .build();

but I don't know how I could add env var to the BuildStrategy as it is supported now since Openshift >= 1.5

  source:
    type: Binary
    binary: {}
  strategy:
    type: Source
    sourceStrategy:
      from:
        kind: DockerImage
        name: redhat-openjdk-18/openjdk18-openshift
      env:
        - name: ARTIFACT_COPY_ARGS
          value: '*.war'

Do we have a withEnvVar method fo the builder to pass additional env var ?

James Strachan

unread,
Nov 9, 2017, 2:53:42 PM11/9/17
to Charles Moulliard, fabric8

--
You received this message because you are subscribed to the Google Groups "fabric8" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fabric8+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

cmou...@redhat.com

unread,
Nov 10, 2017, 3:32:36 AM11/10/17
to fabric8
Got it ;-) I will update the following code to be able to set env vars

Idea to be investigated -->

            List<EnvVar> ret = new ArrayList<>();
            Map<String, EnvVar> envMap = convertToEnvVarMap(imageConfig.getBuildConfiguration().getEnv());
            ret.addAll(envMap.values());

            return new BuildStrategyBuilder()
                    .withType("Source")
                    .withNewSourceStrategy()
                    .withNewFrom()
                    .withKind(fromKind)
                    .withName(fromName)
                    .withNamespace(StringUtils.isEmpty(fromNamespace) ? null : fromNamespace)
                    .endFrom()
                    .addAllToEnv(ret) // WHERE ENV VAR WILL BE PASSED
                    .endSourceStrategy()
                    .build();



Question:

Is it the best place to pass env vars using the Image tag (--> which is imported into the ImageConfiguration object)

<images>
  <image>
    <name>${project.artifactId}:%t</name>
    <alias>spring-boot-mvc-jsp</alias>
     <build>
       <from>redhat-openjdk-18/openjdk18-openshift</from>
       <assembly>
         <basedir>/deployments</basedir>
         <descriptorRef>artifact</descriptorRef>
       </assembly>
       <env>
         <ARTIFACT_COPY_ARGS>*.war</ARTIFACT_COPY_ARGS>

instead of having a new xml tag that we could map to BuildConfiguration ?

E.g. 

  <buildConfig> 
     <sourceStrategy>
        <env>
          <ARTIFACT_COPY_ARGS>*.war</ARTIFACT_COPY_ARGS>
        ...

Ideally, we should offer the possibility to enrich the BuildConfig created using a yaml|json file

spec:
  strategy:
    sourceStrategy:
      env:
        - name: ARTIFACT_COPY_ARGS
          value: '*.war'

On Thursday, November 9, 2017 at 9:51:30 AM UTC+1, cmou...@redhat.com wrote:
Reply all
Reply to author
Forward
0 new messages