|
| 1 | +# Copyright 2021 IBM Corporation |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +############################################################################### |
| 16 | +# Create the develop, test, and build environment |
| 17 | +############################################################################### |
| 18 | +FROM registry.access.redhat.com/ubi8/go-toolset:1.19 |
| 19 | + |
| 20 | +# https://docs.docker.com/engine/reference/builder/#automatic-platform-args-in-the-global-scope |
| 21 | +# don't provide "default" values (e.g. 'ARG TARGETARCH=amd64') for non-buildx environments, |
| 22 | +# see https://github.com/docker/buildx/issues/510 |
| 23 | +ARG TARGETOS=linux |
| 24 | +ARG TARGETARCH=amd64 |
| 25 | + |
| 26 | +ARG OPENSHIFT_VERSION=4.12 |
| 27 | +ARG KUSTOMIZE_VERSION=4.5.2 |
| 28 | +ARG KUBEBUILDER_VERSION=v3.3.0 |
| 29 | +ARG CONTROLLER_GEN_VERSION=v0.11.4 |
| 30 | + |
| 31 | +ENV PATH=/usr/local/go/bin:$PATH:/usr/local/kubebuilder/bin: |
| 32 | + |
| 33 | +USER root |
| 34 | +ENV HOME=/go |
| 35 | + |
| 36 | +WORKDIR /go/src/github.com/opendatahub-io/modelmesh-serving/ |
| 37 | + |
| 38 | +# Install build and dev tools |
| 39 | +RUN --mount=type=cache,target=${HOME}/.cache/dnf:rw \ |
| 40 | + dnf install --setopt=cachedir=${HOME}/.cache/dnf -y --nodocs \ |
| 41 | + python3 \ |
| 42 | + python3-pip \ |
| 43 | + nodejs \ |
| 44 | + jq |
| 45 | + |
| 46 | +# Install pre-commit |
| 47 | +ENV PIP_CACHE_DIR=${HOME}/.cache/pip |
| 48 | +RUN --mount=type=cache,target=${HOME}/.cache/pip \ |
| 49 | + pip3 install pre-commit |
| 50 | + |
| 51 | +# First download and extract older dist of kubebuilder which includes required etcd, kube-apiserver and kubectl binaries |
| 52 | +# Then download and overwrite kubebuilder binary with desired/latest version |
| 53 | +RUN true \ |
| 54 | + && 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/ \ |
| 55 | + && mv /tmp/kubebuilder_*_${TARGETOS}_${TARGETARCH} /usr/local/kubebuilder \ |
| 56 | + && curl -L https://github.com/kubernetes-sigs/kubebuilder/releases/download/${KUBEBUILDER_VERSION}/kubebuilder_${TARGETOS}_${TARGETARCH} -o /usr/local/kubebuilder/bin/kubebuilder \ |
| 57 | + && true |
| 58 | + |
| 59 | +# Download openshift-cli |
| 60 | +RUN true \ |
| 61 | + && 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 \ |
| 62 | + && tar -xvf /tmp/oc_client.tar.gz -C /tmp \ |
| 63 | + && mv /tmp/oc /usr/local/bin \ |
| 64 | + && mv /tmp/kubectl /usr/local/bin \ |
| 65 | + && chmod a+x /usr/local/bin/oc /usr/local/bin/kubectl \ |
| 66 | + && rm -f /tmp/oc_client.tar.gz \ |
| 67 | + && true |
| 68 | + |
| 69 | +# Download kustomize |
| 70 | +RUN true \ |
| 71 | + && 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 \ |
| 72 | + && tar -xvf /tmp/kustomize.tar.gz -C /tmp \ |
| 73 | + && mv /tmp/kustomize /usr/local/bin \ |
| 74 | + && chmod a+x /usr/local/bin/kustomize \ |
| 75 | + && rm -v /tmp/kustomize.tar.gz \ |
| 76 | + && true |
| 77 | + |
| 78 | +# Install yq 4.x |
| 79 | +RUN true \ |
| 80 | + && curl -L https://github.com/mikefarah/yq/releases/download/v4.33.3/yq_linux_amd64.tar.gz | tar xz -C /tmp \ |
| 81 | + && mv /tmp/yq_linux_amd64 /usr/local/bin/yq \ |
| 82 | + && true |
| 83 | + |
| 84 | +# Copy the Go Modules manifests |
| 85 | +COPY .pre-commit-config.yaml go.mod go.sum ./ |
| 86 | + |
| 87 | +# Download and initialize the pre-commit environments before copying the source so they will be cached |
| 88 | +RUN true \ |
| 89 | + && git init \ |
| 90 | + && pre-commit install-hooks \ |
| 91 | + && true |
| 92 | + |
| 93 | +# Cache dependencies before copying and building sources so that source changes |
| 94 | +# won't invalidate earlier download layers |
| 95 | +RUN go mod download |
| 96 | + |
| 97 | +# Export the Go binary path for controller-gen and ginkgo CLIs |
| 98 | +ENV PATH=/go/bin:$HOME/go/bin:$PATH |
| 99 | +RUN chmod -R 777 /go |
| 100 | + |
| 101 | +# Install controller-gen to generate util code and Kubernetes YAMLs for API changes |
| 102 | +RUN true \ |
| 103 | + && go install sigs.k8s.io/controller-tools/cmd/controller-gen@${CONTROLLER_GEN_VERSION} \ |
| 104 | + && controller-gen --version \ |
| 105 | + && true |
| 106 | + |
| 107 | +# Install the Ginkgo test framework |
| 108 | +RUN true \ |
| 109 | + && go install github.com/onsi/ginkgo/v2/ginkgo \ |
| 110 | + && ginkgo version \ |
| 111 | + && true |
| 112 | + |
| 113 | +# For GitHub Action 'lint', work around error "detected dubious ownership in repository at '/workspace'" |
| 114 | +RUN git config --system --add safe.directory /go/src/github.com/opendatahub-io/modelmesh-serving |
| 115 | + |
| 116 | +# The ubi/go-toolset image doesn't define ENTRYPOINT or CMD, but we need it to run 'make develop' |
| 117 | +CMD /bin/bash |
0 commit comments