Skip to content

Commit c04f311

Browse files
committed
Containerfiles: move logic to separate shell script
The OCP builder API path isn't parsing the heredoc correctly for some reason: error: build error: EOF: unterminated heredoc This will be fixed by openshift/builder#469. Anyway, just work around this for now by moving all the logic to scripts. It does make the Containerfiles cleaner at least now that it has gotten so larger and we get syntax highlighting, ShellCheck, etc... so probably for the best.
1 parent bee6596 commit c04f311

File tree

4 files changed

+67
-64
lines changed

4 files changed

+67
-64
lines changed

Containerfile

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -29,48 +29,7 @@
2929

3030
FROM quay.io/openshift-release-dev/ocp-v4.0-art-dev:c9s-coreos as build
3131
ARG OPENSHIFT_CI=0
32-
RUN --mount=type=bind,target=/run/src --mount=type=secret,id=yumrepos,target=/etc/yum.repos.d/secret.repo <<EOF
33-
set -xeuo pipefail
34-
35-
# Avoid shipping modified .pyc files. Due to
36-
# https://github.com/ostreedev/ostree/issues/1469, any Python apps that
37-
# run (e.g. dnf) will cause pyc creation. We do this by backing them up and
38-
# restoring them at the end.
39-
find /usr -name '*.pyc' -exec mv {} {}.bak \;
40-
41-
# fetch repos from in-cluster mirrors if we're running in OpenShift CI
42-
if [ "${OPENSHIFT_CI}" != 0 ]; then
43-
/run/src/ci/get-ocp-repo.sh /etc/yum.repos.d/ocp.repo
44-
fi
45-
46-
source /etc/os-release
47-
48-
# XXX: For SCOS, only allow certain packages to come from ART; everything else
49-
# should come from CentOS. We should eventually sever this.
50-
if [ $ID = centos ]; then
51-
# this says: "if the line starts with [.*], turn off printing. if the line starts with [our-repo], turn it on."
52-
awk "/\[.*\]/{p=0} /\[rhel-9.6-server-ose-4.19\]/{p=1} p" /etc/yum.repos.d/*.repo > /etc/yum.repos.d/okd.repo.tmp
53-
sed -i -e 's,rhel-9.6-server-ose-4.19,rhel-9.6-server-ose-4.19-okd,' /etc/yum.repos.d/okd.repo.tmp
54-
echo 'includepkgs=openshift-*,ose-aws-ecr-*,ose-azure-acr-*,ose-gcp-gcr-*' >> /etc/yum.repos.d/okd.repo.tmp
55-
mv /etc/yum.repos.d/okd.repo{.tmp,}
56-
fi
57-
58-
# XXX: patch cri-o spec to use tmpfiles
59-
# https://github.com/CentOS/centos-bootc/issues/393
60-
mkdir -p /var/opt
61-
62-
# this is where all the real work happens
63-
rpm-ostree experimental compose treefile-apply \
64-
--var id=$ID /run/src/packages-openshift.yaml
65-
66-
# cleanup the repo file we injected
67-
if [ "${OPENSHIFT_CI}" != 0 ]; then
68-
rm /etc/yum.repos.d/ocp.repo
69-
fi
70-
71-
find /usr -name '*.pyc.bak' -exec sh -c 'mv $1 ${1%.bak}' _ {} \;
72-
ostree container commit
73-
EOF
32+
RUN --mount=type=bind,target=/run/src --mount=type=secret,id=yumrepos,target=/etc/yum.repos.d/secret.repo /run/src/build-node-image.sh
7433

7534
FROM build as metadata
7635
RUN --mount=type=bind,target=/run/src /run/src/scripts/generate-metadata

build-node-image.sh

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
# This script builds the OpenShift node image. It's called from `Containerfile`. set -xeuo pipefail
5+
6+
# Avoid shipping modified .pyc files. Due to
7+
# https://github.com/ostreedev/ostree/issues/1469, any Python apps that
8+
# run (e.g. dnf) will cause pyc creation. We do this by backing them up and
9+
# restoring them at the end.
10+
find /usr -name '*.pyc' -exec mv {} {}.bak \;
11+
12+
# fetch repos from in-cluster mirrors if we're running in OpenShift CI
13+
if [ "${OPENSHIFT_CI}" != 0 ]; then
14+
/run/src/ci/get-ocp-repo.sh /etc/yum.repos.d/ocp.repo
15+
fi
16+
17+
source /etc/os-release
18+
19+
# XXX: For SCOS, only allow certain packages to come from ART; everything else
20+
# should come from CentOS. We should eventually sever this.
21+
if [ $ID = centos ]; then
22+
# this says: "if the line starts with [.*], turn off printing. if the line starts with [our-repo], turn it on."
23+
awk "/\[.*\]/{p=0} /\[rhel-9.6-server-ose-4.19\]/{p=1} p" /etc/yum.repos.d/*.repo > /etc/yum.repos.d/okd.repo.tmp
24+
sed -i -e 's,rhel-9.6-server-ose-4.19,rhel-9.6-server-ose-4.19-okd,' /etc/yum.repos.d/okd.repo.tmp
25+
echo 'includepkgs=openshift-*,ose-aws-ecr-*,ose-azure-acr-*,ose-gcp-gcr-*' >> /etc/yum.repos.d/okd.repo.tmp
26+
mv /etc/yum.repos.d/okd.repo{.tmp,}
27+
fi
28+
29+
# XXX: patch cri-o spec to use tmpfiles
30+
# https://github.com/CentOS/centos-bootc/issues/393
31+
mkdir -p /var/opt
32+
33+
# this is where all the real work happens
34+
rpm-ostree experimental compose treefile-apply \
35+
--var id=$ID /run/src/packages-openshift.yaml
36+
37+
# cleanup the repo file we injected
38+
if [ "${OPENSHIFT_CI}" != 0 ]; then
39+
rm /etc/yum.repos.d/ocp.repo
40+
fi
41+
42+
find /usr -name '*.pyc.bak' -exec sh -c 'mv $1 ${1%.bak}' _ {} \;
43+
ostree container commit

extensions/Dockerfile

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,7 @@ RUN mkdir /os
77
WORKDIR /os
88
ADD . .
99
ARG OPENSHIFT_CI=0
10-
RUN --mount=type=secret,id=yumrepos,target=/os/secret.repo <<EOF
11-
set -xeuo pipefail
12-
13-
# fetch repos from in-cluster mirrors if we're running in OpenShift CI
14-
if [ "${OPENSHIFT_CI}" != 0 ]; then
15-
/run/src/ci/get-ocp-repo.sh ocp.repo
16-
fi
17-
18-
. /etc/os-release
19-
# XXX: we can drop the rhcos check once we've dropped the `ocp-rhel-9.6` variant
20-
if [ $ID = rhel ] || [ $ID = rhcos ]; then
21-
MANIFEST="manifest-rhel-9.6.yaml"
22-
EXTENSIONS="extensions-ocp-rhel-9.6.yaml"
23-
else
24-
MANIFEST="manifest-c9s.yaml"
25-
EXTENSIONS="extensions-okd-c9s.yaml"
26-
fi
27-
28-
rpm-ostree compose extensions --rootfs=/ \
29-
--output-dir=/usr/share/rpm-ostree/extensions/ \
30-
"${MANIFEST}" "${EXTENSIONS}"
31-
EOF
10+
RUN --mount=type=secret,id=yumrepos,target=/os/secret.repo extensions/build.sh
3211

3312
## Creates the repo metadata for the extensions.
3413
## This uses Fedora as a lowest-common-denominator because it will work on

extensions/build.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
set -xeuo pipefail
3+
4+
# fetch repos from in-cluster mirrors if we're running in OpenShift CI
5+
if [ "${OPENSHIFT_CI}" != 0 ]; then
6+
ci/get-ocp-repo.sh ocp.repo
7+
fi
8+
9+
. /etc/os-release
10+
# XXX: we can drop the rhcos check once we've dropped the `ocp-rhel-9.6` variant
11+
if [ $ID = rhel ] || [ $ID = rhcos ]; then
12+
MANIFEST="manifest-rhel-9.6.yaml"
13+
EXTENSIONS="extensions-ocp-rhel-9.6.yaml"
14+
else
15+
MANIFEST="manifest-c9s.yaml"
16+
EXTENSIONS="extensions-okd-c9s.yaml"
17+
fi
18+
19+
rpm-ostree compose extensions --rootfs=/ \
20+
--output-dir=/usr/share/rpm-ostree/extensions/ \
21+
"${MANIFEST}" "${EXTENSIONS}"
22+

0 commit comments

Comments
 (0)