-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathDockerfile
49 lines (37 loc) · 1.35 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
# Build the manager binary using CentOS Stream 9 as the base image
FROM quay.io/centos/centos:stream9 as builder
WORKDIR /workspace
# Install necessary tools and dependencies in a single RUN command to minimize image layers
RUN yum -y install epel-release && \
yum config-manager --set-enabled crb && \
yum -y install gcc glibc-devel glibc-headers libvirt-devel go && \
yum clean all
# Copy the Go Modules manifests
COPY go.mod go.mod
COPY go.sum go.sum
# cache deps before building and copying source so that we don't need to re-download as much
# and so that source changes don't invalidate our downloaded layer
RUN go mod download
# Copy the go source
COPY main.go main.go
COPY api/ api/
COPY cmd/ cmd/
COPY controllers/ controllers/
COPY pkg/ pkg/
# Build the operator
RUN CGO_ENABLED=1 go build -a -o ofcir-operator main.go
# Build the api server
RUN CGO_ENABLED=0 go build -a -o ofcir-api cmd/ofcir-api/main.go
# Cleanup
RUN yum remove -y gcc glibc-devel glibc-headers libvirt-devel go && \
yum clean all && \
rm -rf /var/cache/yum
# Final stage - create the runtime image
FROM quay.io/centos/centos:stream9 as runtime
WORKDIR /
RUN yum -y install libvirt-libs && \
yum clean all
# Copy the binaries from the builder stage
COPY --from=builder /workspace/ofcir-operator .
COPY --from=builder /workspace/ofcir-api .
ENTRYPOINT ["/ofcir-api"]