Skip to content

Commit

Permalink
working now
Browse files Browse the repository at this point in the history
  • Loading branch information
VedantMahabaleshwarkar committed Jul 5, 2023
1 parent ed36559 commit d39ba2b
Showing 1 changed file with 143 additions and 29 deletions.
172 changes: 143 additions & 29 deletions Dockerfile.nightlies
Original file line number Diff line number Diff line change
Expand Up @@ -12,60 +12,174 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# Build arguments
ARG SOURCE_CODE=.
ARG CI_CONTAINER_VERSION="unknown"
###############################################################################
# Create the develop, test, and build environment
###############################################################################
FROM registry.access.redhat.com/ubi8/go-toolset:1.19 as baseimage

#@follow_tag(registry.redhat.io/ubi8/go-toolset:1.18)
FROM registry.redhat.io/ubi8/go-toolset:1.18 as builder
# https://docs.docker.com/engine/reference/builder/#automatic-platform-args-in-the-global-scope
# don't provide "default" values (e.g. 'ARG TARGETARCH=amd64') for non-buildx environments,
# see https://github.com/docker/buildx/issues/510
ARG TARGETOS=linux
ARG TARGETARCH=amd64

ARG OPENSHIFT_VERSION=4.12
ARG KUSTOMIZE_VERSION=4.5.2
ARG KUBEBUILDER_VERSION=v3.3.0
ARG CONTROLLER_GEN_VERSION=v0.11.4

## Build args to be used at this step
ARG SOURCE_CODE
## CPaaS CODE BEGIN ##
## COPY ${REMOTE_SOURCE} ${REMOTE_SOURCE_DIR}
## ENV SOURCE_CODE=${REMOTE_SOURCE}/app
## CPaaS CODE END ##
ENV PATH=/usr/local/go/bin:$PATH:/usr/local/kubebuilder/bin:

WORKDIR /workspace
USER root
ENV HOME=/go

# ## Build args to be used at this step
# ARG SOURCE_CODE
# ## CPaaS CODE BEGIN ##
# COPY ${REMOTE_SOURCE} ${REMOTE_SOURCE_DIR}
# ENV SOURCE_CODE=${REMOTE_SOURCE}/app
# ## CPaaS CODE END ##

COPY ${SOURCE_CODE} /go/src/github.com/opendatahub-io/modelmesh-serving/

WORKDIR /go/src/github.com/opendatahub-io/modelmesh-serving/

# Install build and dev tools
RUN --mount=type=cache,target=${HOME}/.cache/dnf:rw \
dnf install --setopt=cachedir=${HOME}/.cache/dnf -y --nodocs \
python3 \
python3-pip \
nodejs \
jq

# Install pre-commit
ENV PIP_CACHE_DIR=${HOME}/.cache/pip
RUN --mount=type=cache,target=${HOME}/.cache/pip \
pip3 install pre-commit

# First download and extract older dist of kubebuilder which includes required etcd, kube-apiserver and kubectl binaries
# Then download and overwrite kubebuilder binary with desired/latest version
RUN true \
&& curl -L https://github.com/kubernetes-sigs/kubebuilder/releases/download/v2.3.2/kubebuilder_2.3.2_${TARGETOS}_${TARGETARCH}.tar.gz | tar -xz -C /tmp/ \
&& mv /tmp/kubebuilder_*_${TARGETOS}_${TARGETARCH} /usr/local/kubebuilder \
&& curl -L https://github.com/kubernetes-sigs/kubebuilder/releases/download/${KUBEBUILDER_VERSION}/kubebuilder_${TARGETOS}_${TARGETARCH} -o /usr/local/kubebuilder/bin/kubebuilder \
&& true

# Download openshift-cli
RUN true \
&& curl -sSLf --output /tmp/oc_client.tar.gz https://mirror.openshift.com/pub/openshift-v4/${TARGETARCH}/clients/ocp/latest-${OPENSHIFT_VERSION}/openshift-client-${TARGETOS}.tar.gz \
&& tar -xvf /tmp/oc_client.tar.gz -C /tmp \
&& mv /tmp/oc /usr/local/bin \
&& mv /tmp/kubectl /usr/local/bin \
&& chmod a+x /usr/local/bin/oc /usr/local/bin/kubectl \
&& rm -f /tmp/oc_client.tar.gz \
&& true

# Download kustomize
RUN true \
&& curl -sSLf --output /tmp/kustomize.tar.gz https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize%2Fv${KUSTOMIZE_VERSION}/kustomize_v${KUSTOMIZE_VERSION}_${TARGETOS}_${TARGETARCH}.tar.gz \
&& tar -xvf /tmp/kustomize.tar.gz -C /tmp \
&& mv /tmp/kustomize /usr/local/bin \
&& chmod a+x /usr/local/bin/kustomize \
&& rm -v /tmp/kustomize.tar.gz \
&& true

# Install yq 4.x
RUN true \
&& curl -L https://github.com/mikefarah/yq/releases/download/v4.33.3/yq_linux_amd64.tar.gz | tar xz -C /tmp \
&& mv /tmp/yq_linux_amd64 /usr/local/bin/yq \
&& true

# Copy the Go Modules manifests
COPY .pre-commit-config.yaml go.mod go.sum ./

# Download and initialize the pre-commit environments before copying the source so they will be cached
RUN true \
&& git init \
&& pre-commit install-hooks \
&& true

# Cache dependencies before copying and building sources so that source changes
# won't invalidate earlier download layers
RUN go mod download

# Export the Go binary path for controller-gen and ginkgo CLIs
ENV PATH=/go/bin:$HOME/go/bin:$PATH
RUN chmod -R 777 /go

# Install controller-gen to generate util code and Kubernetes YAMLs for API changes
RUN true \
&& go install sigs.k8s.io/controller-tools/cmd/controller-gen@${CONTROLLER_GEN_VERSION} \
&& controller-gen --version \
&& true

# Install the Ginkgo test framework
RUN true \
&& go install github.com/onsi/ginkgo/v2/ginkgo \
&& ginkgo version \
&& true

# For GitHub Action 'lint', work around error "detected dubious ownership in repository at '/workspace'"
RUN git config --system --add safe.directory /go/src/github.com/opendatahub-io/modelmesh-serving

# The ubi/go-toolset image doesn't define ENTRYPOINT or CMD, but we need it to run 'make develop'
CMD /bin/bash

###############################################################################
# Stage 1: Run the go build with go compiler native to the build platform
# https://www.docker.com/blog/faster-multi-platform-builds-dockerfile-cross-compilation-guide/
###############################################################################
FROM baseimage AS build

# https://docs.docker.com/engine/reference/builder/#automatic-platform-args-in-the-global-scope
# don't provide "default" values (e.g. 'ARG TARGETARCH=amd64') for non-buildx environments,
# see https://github.com/docker/buildx/issues/510
ARG TARGETOS=linux
ARG TARGETARCH=amd64

LABEL image="build"

# Copy the go sources
COPY main.go main.go
COPY apis/ apis/
COPY controllers/ controllers/
COPY generated/ generated/
COPY pkg/ pkg/
COPY version /etc/modelmesh-version

USER root

# Build
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -o manager main.go
# Build using native go compiler from BUILDPLATFORM but compiled output for TARGETPLATFORM
RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg \
GOOS=${TARGETOS:-linux} \
GOARCH=${TARGETARCH:-amd64} \
CGO_ENABLED=0 \
GO111MODULE=on \
go build -a -o /workspace/manager main.go

#@follow_tag(registry.redhat.io/ubi8/ubi-minimal:8.7)
FROM registry.redhat.io/ubi8/ubi-minimal:8.7 AS runtime
###############################################################################
# Stage 2: Copy build assets to create the smallest final runtime image
###############################################################################
FROM registry.access.redhat.com/ubi8/ubi-minimal:8.7 AS runtime

## Build args to be used at this step
ARG CI_CONTAINER_VERSION
ARG USER=2000
ARG IMAGE_VERSION
ARG COMMIT_SHA

LABEL com.redhat.component="odh-modelmesh-serving-controller-container" \
name="managed-open-data-hub/odh-modelmesh-serving-controller-rhel8" \
version="" \
version="${CI_CONTAINER_VERSION}" \
summary="odh-modelmesh-serving-controller" \
io.openshift.expose-services="" \
io.k8s.display-name="modelmesh-serving-controller" \
maintainer="['managed-open-data-hub@redhat.com']" \
description="Manages lifecycle of ModelMesh Serving Custom Resources and associated Kubernetes resources" \
com.redhat.license_terms="https://www.redhat.com/licenses/Red_Hat_Standard_EULA_20191108.pdf"

## Install additional packages
RUN microdnf install -y shadow-utils &&\
microdnf clean all

## Create a non-root user with UID 2000 and switch to it
USER 2000
USER ${USER}

WORKDIR /
COPY --from=builder /workspace/manager .
COPY --from=builder /workspace/config/internal ./config/internal
COPY --from=build /workspace/manager .

COPY config/internal config/internal

ENTRYPOINT ["/manager"]

0 comments on commit d39ba2b

Please sign in to comment.