Skip to content

Commit 693ec0e

Browse files
authored
Merge pull request #37205 from rolfedh/RHDEVDOCS-3000
RHDEVDOCS-3000 Document: Build Resource Volume Mounts
2 parents 8626575 + c2a1ad0 commit 693ec0e

11 files changed

+249
-63
lines changed

cicd/builds/build-strategies.adoc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ toc::[]
88
The following sections define the primary supported build strategies, and how to
99
use them.
1010

11+
// Docker build strategy
12+
1113
include::modules/builds-strategy-docker-build.adoc[leveloffset=+1]
1214

1315
include::modules/builds-strategy-docker-from-image.adoc[leveloffset=+2]
@@ -20,6 +22,13 @@ include::modules/builds-strategy-docker-build-arguments.adoc[leveloffset=+2]
2022

2123
include::modules/builds-strategy-docker-squash-layers.adoc[leveloffset=+2]
2224

25+
:context: build-strategies-docker
26+
27+
include::modules/builds-using-build-volumes.adoc[leveloffset=+2]
28+
29+
30+
// S2I build strategy
31+
2332
include::modules/builds-strategy-s2i-build.adoc[leveloffset=+1]
2433

2534
include::modules/builds-strategy-s2i-incremental-builds.adoc[leveloffset=+2]
@@ -40,6 +49,12 @@ include::modules/images-create-s2i-build.adoc[leveloffset=+3]
4049

4150
include::modules/images-create-s2i-scripts.adoc[leveloffset=+3]
4251

52+
:context: build-strategies-s2i
53+
54+
include::modules/builds-using-build-volumes.adoc[leveloffset=+2]
55+
56+
// Custom build strategy
57+
4358
include::modules/builds-strategy-custom-build.adoc[leveloffset=+1]
4459

4560
include::modules/builds-strategy-custom-from-image.adoc[leveloffset=+2]
@@ -50,6 +65,8 @@ include::modules/builds-strategy-custom-environment-variables.adoc[leveloffset=+
5065

5166
include::modules/images-custom.adoc[leveloffset=+2]
5267

68+
// Pipeline build strategy
69+
5370
include::modules/builds-strategy-pipeline-build.adoc[leveloffset=+1]
5471

5572
include::modules/builds-understanding-openshift-pipeline.adoc[leveloffset=+2]

modules/builds-adding-input-secrets-configmaps.adoc

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
// Module included in the following assemblies:
22
//
3-
// * builds/creating-build-inputs.adoc
3+
// * cicd/builds/creating-build-inputs.adoc
4+
// * cicd/builds/builds-using-build-volumes.adoc
5+
6+
:_module-type: PROCEDURE
47

58
[id="builds-adding-input-secrets-configmaps_{context}"]
69
= Adding input secrets and config maps
710

8-
In some scenarios, build operations require credentials or other configuration data to access dependent resources, but it is undesirable for that information to be placed in source control. You can define input secrets and input config maps for this purpose.
11+
[role="_abstract"]
12+
To provide credentials and other configuration data to a build without placing them in source control, you can define input secrets and input config maps.
13+
14+
In some scenarios, build operations require credentials or other configuration data to access dependent resources. To make that information available without placing it in source control, you can define input secrets and input config maps.
915

1016
.Procedure
1117

@@ -20,16 +26,51 @@ $ oc create configmap settings-mvn \
2026
----
2127
+
2228
This creates a new config map named `settings-mvn`, which contains the plain text content of the `settings.xml` file.
29+
+
30+
[TIP]
31+
====
32+
You can alternatively apply the following YAML to create the config map:
33+
[source,yaml]
34+
----
35+
apiVersion: core/v1
36+
kind: ConfigMap
37+
metadata:
38+
name: settings-mvn
39+
data:
40+
settings.xml: |
41+
<settings>
42+
… # Insert maven settings here
43+
</settings>
44+
----
45+
====
46+
2347

2448
. Create the `Secret` object, if it does not exist:
2549
+
2650
[source,terminal]
2751
----
2852
$ oc create secret generic secret-mvn \
2953
--from-file=id_rsa=<path/to/.ssh/id_rsa>
54+
--type=kubernetes.io/ssh-auth
3055
----
3156
+
3257
This creates a new secret named `secret-mvn`, which contains the base64 encoded content of the `id_rsa` private key.
58+
+
59+
[TIP]
60+
====
61+
You can alternatively apply the following YAML to create the input secret:
62+
[source,yaml]
63+
----
64+
apiVersion: core/v1
65+
kind: Secret
66+
metadata:
67+
name: secret-mvn
68+
type: kubernetes.io/ssh-auth
69+
data:
70+
ssh-privatekey: |
71+
# Insert ssh private key, base64 encoded
72+
----
73+
====
3374

3475
. Add the config map and secret to the `source` section in the existing
3576
`BuildConfig` object:

modules/builds-create-imagestreamtag.adoc

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,53 @@ The benefit of using image stream tags this way is that doing so grants access t
1717
+
1818
[source,terminal]
1919
----
20-
$ oc tag --source=docker registry.redhat.io/ubi7/ubi:latest ubi:latest -n openshift
20+
$ oc tag --source=docker registry.redhat.io/ubi8/ubi:latest ubi:latest -n openshift
2121
----
22+
+
23+
[TIP]
24+
====
25+
You can alternatively apply the following YAML to create an `ImageStreamTag` in the `openshift` namespace:
26+
[source,yaml]
27+
----
28+
apiVersion: image.openshift.io/v1
29+
kind: ImageStream
30+
metadata:
31+
name: ubi
32+
namespace: openshift
33+
spec:
34+
tags:
35+
- from:
36+
kind: DockerImage
37+
name: registry.redhat.io/ubi8/ubi:latest
38+
name: latest
39+
referencePolicy:
40+
type: Source
41+
----
42+
====
2243

2344
* To create an `ImageStreamTag` in a single project, enter:
2445
+
2546
[source,terminal]
2647
----
27-
$ oc tag --source=docker registry.redhat.io/ubi7/ubi:latest ubi:latest
48+
$ oc tag --source=docker registry.redhat.io/ubi8/ubi:latest ubi:latest
49+
----
50+
+
51+
[TIP]
52+
====
53+
You can alternatively apply the following YAML to create an `ImageStreamTag` in a single project:
54+
[source,yaml]
55+
----
56+
apiVersion: image.openshift.io/v1
57+
kind: ImageStream
58+
metadata:
59+
name: ubi
60+
spec:
61+
tags:
62+
- from:
63+
kind: DockerImage
64+
name: registry.redhat.io/ubi8/ubi:latest
65+
name: latest
66+
referencePolicy:
67+
type: Source
2868
----
69+
====

modules/builds-docker-strategy.adoc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ RUN chmod 755 /input_report.sh
2626
CMD ["/bin/sh", "-c", "/input_report.sh"]
2727
----
2828

29-
[NOTE]
29+
[IMPORTANT]
3030
====
3131
Users normally remove their input secrets from the final application image so that the secrets are not present in the container running from that image. However, the secrets still exist in the image itself in the layer where they were added. This removal is part of the Dockerfile itself.
32+
33+
To prevent the contents of input secrets and config maps from appearing in the build output container images and avoid this removal process altogether, xref:../../cicd/builds/build-strategies.html#builds-using-build-volumes_build-strategies-docker[use build volumes] in your Docker build strategy instead.
3234
====

modules/builds-input-secrets-configmaps.adoc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
[id="builds-input-secrets-configmaps_{context}"]
66
= Input secrets and config maps
77

8+
[IMPORTANT]
9+
====
10+
To prevent the contents of input secrets and config maps from appearing in build output container images, use build volumes in your xref:../../cicd/builds/build-strategies.html#builds-using-build-volumes_build-strategies-docker[Docker build] and xref:../../cicd/builds/build-strategies.html#builds-using-build-volumes_build-strategies-s2i[source-to-image build] strategies.
11+
====
12+
813
In some scenarios, build operations require credentials or other configuration data to access dependent resources, but it is undesirable for that information to be placed in source control. You can define input secrets and input config maps for this purpose.
914

1015
For example, when building a Java application with Maven, you can set up a private mirror of Maven Central or JCenter that is accessed by private keys. To download libraries from that private mirror, you have to supply the

modules/builds-source-input-satellite-config.adoc

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,29 @@ Builds that use Red Hat Satellite to install content must provide appropriate co
3333
----
3434
$ oc create configmap yum-repos-d --from-file /path/to/satellite.repo
3535
----
36-
+
3736

38-
. Add the Satellite repository configuration to the `BuildConfig`:
37+
. Add the Satellite repository configuration and entitlement key as a build volumes:
3938
+
4039
[source,yaml]
4140
----
42-
source:
43-
configMaps:
44-
- configMap:
45-
name: yum-repos-d
46-
destinationDir: yum.repos.d
41+
strategy:
42+
dockerStrategy:
43+
from:
44+
kind: ImageStreamTag
45+
name: ubi:latest
46+
volumes:
47+
- name: yum-repos-d
48+
mounts:
49+
- destinationPath: /etc/yum.repos.d
50+
source:
51+
type: ConfigMap
52+
configMap:
53+
name: yum-repos-d
54+
- name: etc-pki-entitlement
55+
mounts:
56+
- destinationPath: /etc/pki/entitlement
57+
source:
58+
type: Secret
59+
secret:
60+
secretName: etc-pki-entitlement
4761
----

modules/builds-source-secrets-entitlements.adoc

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,21 @@ $ oc create secret generic etc-pki-entitlement --from-file /path/to/entitlement
2121
> --from-file /path/to/entitlement/{ID}-key.pem ...
2222
----
2323

24-
. Add the secret as a build input in the build configuration:
24+
. Add the secret as a build volume in the build configuration’s Docker strategy:
2525
+
2626
[source,yaml]
2727
----
28-
source:
29-
secrets:
30-
- secret:
31-
name: etc-pki-entitlement
32-
destinationDir: etc-pki-entitlement
28+
strategy:
29+
dockerStrategy:
30+
from:
31+
kind: ImageStreamTag
32+
name: ubi:latest
33+
volumes:
34+
- name: etc-pki-entitlement
35+
mounts:
36+
- destinationPath: /etc/pki/entitlement
37+
source:
38+
type: Secret
39+
secret:
40+
secretName: etc-pki-entitlement
3341
----

modules/builds-strategy-docker-entitled-satellite.adoc

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,33 +8,15 @@ Docker strategy builds can use Red Hat Satellite repositories to install subscri
88

99
.Prerequisites
1010

11-
* The entitlement keys and Satellite repository configurations must be added as build inputs.
11+
* You have added the entitlement keys and Satellite repository configurations as build volumes.
1212

1313
.Procedure
1414

1515
Use the following as an example Dockerfile to install content with Satellite:
1616

1717
[source,terminal]
1818
----
19-
FROM registry.redhat.io/rhel7:latest
20-
USER root
21-
# Copy entitlements
22-
COPY ./etc-pki-entitlement /etc/pki/entitlement
23-
# Copy repository configuration
24-
COPY ./yum.repos.d /etc/yum.repos.d
25-
# Delete /etc/rhsm-host to use entitlements from the build container
26-
RUN sed -i".org" -e "s#^enabled=1#enabled=0#g" /etc/yum/pluginconf.d/subscription-manager.conf <1>
27-
#RUN cat /etc/yum/pluginconf.d/subscription-manager.conf
28-
RUN yum clean all
29-
#RUN yum-config-manager
30-
RUN rm /etc/rhsm-host && \
31-
# yum repository info provided by Satellite
32-
yum -y update && \
33-
yum -y install <rpms> && \
34-
# Remove entitlements
35-
rm -rf /etc/pki/entitlement
36-
# OpenShift requires images to run as non-root by default
37-
USER 1001
38-
ENTRYPOINT ["/bin/bash"]
19+
FROM registry.redhat.io/ubi8/ubi:latest
20+
RUN dnf search kernel-devel --showduplicates && \
21+
dnf install -y kernel-devel
3922
----
40-
<1> If adding Satellite configurations to builds using `enabled=1` fails, add `RUN sed -i".org" -e "s#^enabled=1#enabled=0#g" /etc/yum/pluginconf.d/subscription-manager.conf` to the Dockerfile.

modules/builds-strategy-docker-entitled-subman.adoc

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,33 +9,15 @@ Docker strategy builds can use the Subscription Manager to install subscription
99

1010
.Prerequisites
1111

12-
The entitlement keys, subscription manager configuration, and subscription manager certificate authority must be added as build inputs.
12+
The entitlement keys must be added as build strategy volumes.
1313

1414
.Procedure
1515

1616
Use the following as an example Dockerfile to install content with the Subscription Manager:
1717

1818
[source,terminal]
1919
----
20-
FROM registry.redhat.io/rhel7:latest
21-
USER root
22-
# Copy entitlements
23-
COPY ./etc-pki-entitlement /etc/pki/entitlement
24-
# Copy subscription manager configurations
25-
COPY ./rhsm-conf /etc/rhsm
26-
COPY ./rhsm-ca /etc/rhsm/ca
27-
# Delete /etc/rhsm-host to use entitlements from the build container
28-
RUN rm /etc/rhsm-host && \
29-
# Initialize /etc/yum.repos.d/redhat.repo
30-
# See https://access.redhat.com/solutions/1443553
31-
yum repolist --disablerepo=* && \
32-
subscription-manager repos --enable <enabled-repo> && \
33-
yum -y update && \
34-
yum -y install <rpms> && \
35-
# Remove entitlements and Subscription Manager configs
36-
rm -rf /etc/pki/entitlement && \
37-
rm -rf /etc/rhsm
38-
# OpenShift requires images to run as non-root by default
39-
USER 1001
40-
ENTRYPOINT ["/bin/bash"]
20+
FROM registry.redhat.io/ubi8/ubi:latest
21+
RUN dnf search kernel-devel --showduplicates && \
22+
dnf install -y kernel-devel
4123
----

modules/builds-strategy-docker-squash-layers.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//* builds/running-entitled-builds.adoc
33

44
[id="builds-strategy-docker-squash-layers_{context}"]
5-
= Squash layers with docker builds
5+
= Squashing layers with docker builds
66

77
Docker builds normally create a layer representing each instruction in a Dockerfile. Setting the `imageOptimizationPolicy` to `SkipLayers` merges all instructions into a single layer on top of the base image.
88

0 commit comments

Comments
 (0)