forked from redhat-best-practices-for-k8s/certsuite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
128 lines (109 loc) · 3.88 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
FROM registry.access.redhat.com/ubi9/ubi:9.4-1181@sha256:1ee4d8c50d14d9c9e9229d9a039d793fcbc9aa803806d194c957a397cf1d2b17 AS build
ENV CERTSUITE_DIR=/usr/certsuite
ENV \
CERTSUITE_SRC_DIR=${CERTSUITE_DIR}/src \
TEMP_DIR=/tmp
# Install dependencies
# hadolint ignore=DL3041
RUN \
mkdir ${CERTSUITE_DIR} \
&& dnf update --assumeyes --disableplugin=subscription-manager \
&& dnf install --assumeyes --disableplugin=subscription-manager \
gcc \
git \
jq \
cmake \
wget \
&& dnf clean all --assumeyes --disableplugin=subscription-manager \
&& rm -rf /var/cache/yum
# Set environment specific variables
ENV \
OPERATOR_SDK_X86_FILENAME=operator-sdk_linux_amd64 \
OPERATOR_SDK_ARM_FILENAME=operator-sdk_linux_arm64
# Install Go binary and set the PATH
ENV \
GO_DL_URL=https://golang.org/dl \
GOPATH=/root/go
ENV GO_BIN_URL_x86_64=${GO_DL_URL}/go1.22.5.linux-amd64.tar.gz
ENV GO_BIN_URL_aarch64=${GO_DL_URL}/go1.22.5.linux-arm64.tar.gz
# Determine the CPU architecture and download the appropriate Go binary
RUN \
if [ "$(uname -m)" = x86_64 ]; then \
wget --directory-prefix=${TEMP_DIR} ${GO_BIN_URL_x86_64} --quiet \
&& rm -rf /usr/local/go \
&& tar -C /usr/local -xzf ${TEMP_DIR}/go1.22.5.linux-amd64.tar.gz; \
elif [ "$(uname -m)" = aarch64 ]; then \
wget --directory-prefix=${TEMP_DIR} ${GO_BIN_URL_aarch64} --quiet \
&& rm -rf /usr/local/go \
&& tar -C /usr/local -xzf ${TEMP_DIR}/go1.22.5.linux-arm64.tar.gz; \
else \
echo "CPU architecture is not supported." && exit 1; \
fi
ENV PATH=${PATH}:"/usr/local/go/bin":${GOPATH}/"bin"
# Download operator-sdk binary
ENV \
OPERATOR_SDK_DL_URL=https://github.com/operator-framework/operator-sdk/releases/download/v1.36.0 \
OSDK_BIN=/usr/local/osdk/bin
RUN \
mkdir -p ${OSDK_BIN}
# hadolint ignore=DL4001
RUN \
if [ "$(uname -m)" = x86_64 ]; then \
curl \
--location \
--remote-name \
${OPERATOR_SDK_DL_URL}/${OPERATOR_SDK_X86_FILENAME} \
&& mv ${OPERATOR_SDK_X86_FILENAME} ${OSDK_BIN}/operator-sdk \
&& chmod +x ${OSDK_BIN}/operator-sdk; \
elif [ "$(uname -m)" = aarch64 ]; then \
curl \
--location \
--remote-name \
${OPERATOR_SDK_DL_URL}/${OPERATOR_SDK_ARM_FILENAME} \
&& mv ${OPERATOR_SDK_ARM_FILENAME} ${OSDK_BIN}/operator-sdk \
&& chmod +x ${OSDK_BIN}/operator-sdk; \
else \
echo "CPU architecture is not supported." && exit 1; \
fi
# Copy all of the files into the source directory and then switch contexts
COPY . ${CERTSUITE_SRC_DIR}
WORKDIR ${CERTSUITE_SRC_DIR}
# Build the certsuite binary
RUN make build-certsuite-tool \
&& cp certsuite ${CERTSUITE_DIR}
# Switch contexts back to the root CERTSUITE directory
WORKDIR ${CERTSUITE_DIR}
# Remove most of the build artefacts
RUN \
dnf remove --assumeyes --disableplugin=subscription-manager gcc git wget \
&& dnf clean all --assumeyes --disableplugin=subscription-manager \
&& rm -rf ${CERTSUITE_SRC_DIR} \
&& rm -rf ${TEMP_DIR} \
&& rm -rf /root/.cache \
&& rm -rf /root/go/pkg \
&& rm -rf /root/go/src \
&& rm -rf /usr/lib/golang/pkg \
&& rm -rf /usr/lib/golang/src
# Using latest is prone to errors.
# hadolint ignore=DL3007
FROM quay.io/testnetworkfunction/oct:latest AS db
# Copy the state into a new flattened image to reduce size.
# TODO run as non-root
FROM registry.access.redhat.com/ubi9/ubi-minimal:9.4-1194@sha256:104cf11d890aeb7dd5728b7d7732e175a0e4018f1bb00d2faebcc8f6bf29bd52
ENV \
CERTSUITE_DIR=/usr/certsuite \
OSDK_BIN=/usr/local/osdk/bin
# Install the certsuite binary
COPY --from=build ${CERTSUITE_DIR} ${CERTSUITE_DIR}
RUN cp ${CERTSUITE_DIR}/certsuite /usr/local/bin
# Add operatorsdk binary to image
COPY --from=build ${OSDK_BIN} ${OSDK_BIN}
# Update the CNF containers, helm charts and operators DB
ENV \
CERTSUITE_OFFLINE_DB=/usr/offline-db \
OCT_DB_PATH=/usr/oct/cmd/tnf/fetch
COPY --from=db ${OCT_DB_PATH} ${CERTSUITE_OFFLINE_DB}
ENV PATH="${OSDK_BIN}:${PATH}"
WORKDIR ${CERTSUITE_DIR}
ENV SHELL=/bin/bash
CMD ["certsuite", "-h"]