-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathDockerfile.rpm.simple
84 lines (70 loc) · 2.66 KB
/
Dockerfile.rpm.simple
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
# Copyright 2025 Carver Automation Corporation.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Stage 1: Build the Go binary
FROM --platform=linux/amd64 golang:1.24-bullseye AS builder
WORKDIR /src
COPY . .
# Build the binary (passed as build arg)
ARG COMPONENT
ARG BINARY_PATH
# Build with the correct output name
RUN if [ "${COMPONENT}" = "dusk-checker" ]; then \
GOOS=linux GOARCH=amd64 go build -o "/build-out/dusk-checker" "$BINARY_PATH"; \
else \
GOOS=linux GOARCH=amd64 go build -o "/build-out/serviceradar-${COMPONENT}" "$BINARY_PATH"; \
fi
# Stage 2: Create RPM
FROM --platform=linux/amd64 rockylinux:9 AS rpm-builder
# Update and install RPM build tools and build dependencies
# Use --nogpgcheck for build environment
RUN dnf update -y && \
dnf install -y --nogpgcheck \
rpm-build \
rpmdevtools \
systemd-devel \
libcap-devel \
gcc \
make
# Set up RPM build environment
RUN rpmdev-setuptree
# Create source directories
RUN mkdir -p /root/rpmbuild/SOURCES/systemd /root/rpmbuild/SOURCES/config/checkers
# Copy built binary and spec file
ARG COMPONENT
COPY --from=builder /build-out/* /root/rpmbuild/BUILD/
COPY packaging/specs/serviceradar-${COMPONENT}.spec /root/rpmbuild/SPECS/
# Copy configs and systemd files
COPY packaging/config/*.json /root/rpmbuild/SOURCES/config/
COPY packaging/config/checkers/*.json /root/rpmbuild/SOURCES/config/checkers/
COPY packaging/${COMPONENT}/systemd/serviceradar-${COMPONENT}.service /root/rpmbuild/SOURCES/systemd/
# Debugging: List files in directories
RUN echo "=== Files in BUILD ===" && \
ls -la /root/rpmbuild/BUILD/ && \
echo "=== Files in config ===" && \
ls -la /root/rpmbuild/SOURCES/config/ && \
echo "=== Files in checkers ===" && \
ls -la /root/rpmbuild/SOURCES/config/checkers/
# Set default version (can be overridden at build time)
ARG VERSION=1.0.20
ARG RELEASE=1
# Build the RPM
RUN rpmbuild -bb \
--define "version ${VERSION}" \
--define "release ${RELEASE}" \
/root/rpmbuild/SPECS/serviceradar-${COMPONENT}.spec
# Final stage to store RPM
FROM --platform=linux/amd64 rockylinux:9
WORKDIR /rpms
COPY --from=rpm-builder /root/rpmbuild/RPMS/*/*.rpm .
CMD ["/bin/bash"]