From a922cf340f877a8a219f0df447252524a735a9d4 Mon Sep 17 00:00:00 2001 From: Dan Manor Date: Mon, 5 Aug 2024 14:45:08 +0300 Subject: [PATCH] MGMT-18313: Replace golang base image as it is based on Centos Linux 7 (#6637) --- .golangci.yml | 2 +- Dockerfile.assisted-service | 24 +++++++++++++----------- Dockerfile.assisted-service-build | 27 +++++++++++++-------------- Dockerfile.assisted-service-debug | 23 ++++++++++++++++++----- ci-images/Dockerfile.base | 24 ++++++++++++------------ ci-images/Dockerfile.code-generation | 1 - subsystem/kubeapi_test.go | 2 +- 7 files changed, 58 insertions(+), 45 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index ad1eb84e6079..2953b19ce0f8 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -61,7 +61,7 @@ linters: - unconvert - gci - goimports - - scopelint + - exportloopref linters-settings: govet: diff --git a/Dockerfile.assisted-service b/Dockerfile.assisted-service index bc6d209941c1..33543dfd75e4 100644 --- a/Dockerfile.assisted-service +++ b/Dockerfile.assisted-service @@ -1,14 +1,19 @@ +FROM registry.access.redhat.com/ubi9/go-toolset:1.20 AS golang + # Build binaries -FROM quay.io/centos/centos:stream8 as builder +FROM quay.io/centos/centos:stream9 as builder + +RUN dnf install --enablerepo=crb -y gcc git nmstate-devel openssl-devel && dnf clean all -RUN sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-* && \ - sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-* +ENV GOROOT=/usr/lib/golang +ENV GOPATH=/opt/app-root/src/go +ENV PATH=$PATH:$GOROOT/bin:$GOPATH/bin -RUN dnf install --enablerepo=powertools -y gcc git nmstate-devel && dnf clean all -COPY --from=registry.ci.openshift.org/openshift/release:golang-1.20 /usr/local/go /usr/local/go +RUN mkdir -p $GOROOT && mkdir -p $GOPATH -ENV GOROOT=/usr/local/go -ENV PATH=$PATH:$GOROOT/bin +COPY --from=golang $GOROOT $GOROOT + +RUN chmod 775 -R $GOPATH && chmod 775 -R $GOROOT WORKDIR /assisted-service/ @@ -28,10 +33,7 @@ RUN cd ./cmd/webadmission && CGO_ENABLED=1 GOFLAGS="" GO111MODULE=on go build -o RUN cd ./cmd/agentbasedinstaller/client && CGO_ENABLED=1 GOFLAGS="" GO111MODULE=on go build -o /build/agent-installer-client # Create final image -FROM quay.io/centos/centos:stream8 - -RUN sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-* && \ - sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-* +FROM quay.io/centos/centos:stream9 # multiarch images need it till WRKLDS-222 and https://bugzilla.redhat.com/show_bug.cgi?id=2111537 are fixed RUN dnf install -y --setopt=install_weak_deps=False skopeo diff --git a/Dockerfile.assisted-service-build b/Dockerfile.assisted-service-build index 6d991863106d..e669f1751609 100644 --- a/Dockerfile.assisted-service-build +++ b/Dockerfile.assisted-service-build @@ -1,19 +1,22 @@ -FROM registry.ci.openshift.org/openshift/release:golang-1.20 AS golang -RUN chmod g+xw -R /usr/local/go +FROM registry.access.redhat.com/ubi9/go-toolset:1.20 AS golang -FROM quay.io/centos/centos:stream8 +RUN curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.53.2 +RUN go install gotest.tools/gotestsum@latest -RUN sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-* && \ - sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-* +FROM quay.io/centos/centos:stream9 -ENV GOPATH=/go -ENV GOROOT=/usr/local/go +ENV GOROOT=/usr/lib/golang +ENV GOPATH=/opt/app-root/src/go ENV VIRTUAL_ENV=/opt/venv # A directory in the path with write permission even for non-root users ENV TOOLS=/tools/ ENV PATH="$VIRTUAL_ENV/bin:$GOROOT/bin:$GOPATH/bin:$TOOLS:$PATH" -RUN curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b /usr/bin v1.53.2 +COPY --from=golang $GOPATH $GOPATH +COPY --from=golang $GOROOT $GOROOT + +RUN chmod 775 -R $GOPATH && chmod 775 -R $GOROOT + # TODO: Replace with version 0.30.4 once it is released. # # We need version 5d0a00d of go-swagger because it is the first that contains @@ -30,17 +33,13 @@ RUN curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/i COPY --from=quay.io/goswagger/swagger:sha-5d0a00d /usr/bin/swagger /usr/bin/goswagger COPY --from=quay.io/edge-infrastructure/swagger-codegen-cli:2.4.18 /opt/swagger-codegen-cli /opt/swagger-codegen-cli -COPY --from=golang /usr/bin/gotestsum /usr/bin/make /usr/bin/ -COPY --from=golang /usr/local/go /usr/local/go COPY --from=quay.io/openshift/origin-cli:latest /usr/bin/oc /usr/bin COPY --from=quay.io/operator-framework/upstream-opm-builder:v1.16.1 /bin/opm /bin COPY --from=registry.k8s.io/kustomize/kustomize:v4.3.0 /app/kustomize /usr/bin/ COPY --from=quay.io/coreos/shellcheck-alpine:v0.5.0 /bin/shellcheck /usr/bin/shellcheck -RUN dnf install -y 'dnf-command(config-manager)' && \ - dnf config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo && \ - dnf install -y --enablerepo=powertools \ - openssl postgresql nmstate-devel sqlite gcc genisoimage git docker-ce-cli libvirt-client libvirt-devel java && \ +RUN dnf install -y --enablerepo=crb \ + openssl openssl-devel postgresql nmstate-devel sqlite gcc genisoimage git libvirt-client libvirt-devel java make && \ dnf clean all # Git checks if the user that owns the files on the filesystem match the diff --git a/Dockerfile.assisted-service-debug b/Dockerfile.assisted-service-debug index ba04d91e61c4..822b64b8252e 100644 --- a/Dockerfile.assisted-service-debug +++ b/Dockerfile.assisted-service-debug @@ -1,11 +1,24 @@ -ARG SERVICE=quay.io/edge-infrastructure/assisted-service:latest -FROM registry.ci.openshift.org/openshift/release:golang-1.18 AS download_dlv +FROM registry.access.redhat.com/ubi9/go-toolset:1.20 AS golang + RUN GOFLAGS=-mod=mod go install github.com/go-delve/delve/cmd/dlv@v1.9.1 -FROM $SERVICE +FROM quay.io/centos/centos:stream9 + +RUN dnf install --enablerepo=crb -y gcc git nmstate-devel openssl-devel && dnf clean all + +ENV GOROOT=/usr/lib/golang +ENV GOPATH=/opt/app-root/src/go +ENV PATH=$PATH:$GOROOT/bin:$GOPATH/bin + +COPY --from=golang $GOPATH $GOPATH +COPY --from=golang $GOROOT $GOROOT + +RUN chmod 775 -R $GOPATH && chmod 775 -R $GOROOT + ARG DEBUG_SERVICE_PORT=40000 -COPY --from=download_dlv /go/bin/dlv / EXPOSE 8090 $DEBUG_SERVICE_PORT + COPY assisted-service /assisted-service COPY assisted-service-operator /assisted-service-operator -CMD ["/dlv", "--listen=:40000", "--headless=true", "--continue", "--api-version=2", "--accept-multiclient", "exec", "/assisted-service"] + +CMD ["dlv", "--listen=:40000", "--headless=true", "--continue", "--api-version=2", "--accept-multiclient", "exec", "/assisted-service"] diff --git a/ci-images/Dockerfile.base b/ci-images/Dockerfile.base index b024e48113a3..c86de6936b51 100644 --- a/ci-images/Dockerfile.base +++ b/ci-images/Dockerfile.base @@ -1,28 +1,28 @@ -FROM quay.io/centos/centos:stream8 +FROM registry.access.redhat.com/ubi9/go-toolset:1.20 AS golang -RUN sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-* && \ - sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-* +RUN go install gotest.tools/gotestsum@latest -RUN dnf install -y 'dnf-command(config-manager)' && \ - dnf config-manager --set-enabled powertools && \ - dnf install -y git unzip make gcc which nmstate-devel python3 +FROM quay.io/centos/centos:stream9 + +RUN dnf install --enablerepo=crb -y \ + git unzip make gcc which nmstate-devel python3 openssl-devel # Git checks if the user that owns the files on the filesystem match the # current user. We need to disable this check because tests in Prow are # running with a random user. RUN git config --system --add safe.directory '*' -COPY --from=registry.ci.openshift.org/openshift/release:golang-1.20 /usr/local/go /usr/local/go -COPY --from=registry.ci.openshift.org/openshift/release:golang-1.20 /usr/bin/gotestsum /usr/bin/make /usr/bin/ - -ENV GOPATH=/go -ENV GOROOT=/usr/local/go +ENV GOROOT=/usr/lib/golang +ENV GOPATH=/opt/app-root/src/go ENV PATH=$PATH:$GOROOT/bin:$GOPATH/bin +COPY --from=golang $GOPATH $GOPATH +COPY --from=golang $GOROOT $GOROOT + COPY . /assisted-service/ WORKDIR /assisted-service/ RUN go mod vendor -RUN chmod 775 -R $GOPATH && chmod 775 -R $(go env GOROOT) && chmod 775 -R /assisted-service/ && \ +RUN chmod 775 -R $GOPATH && chmod 775 -R $GOROOT && chmod 775 -R /assisted-service/ && \ mkdir /.cache && chmod 775 -R /.cache diff --git a/ci-images/Dockerfile.code-generation b/ci-images/Dockerfile.code-generation index c8b6060c3587..2ec9a95a130c 100644 --- a/ci-images/Dockerfile.code-generation +++ b/ci-images/Dockerfile.code-generation @@ -17,7 +17,6 @@ ENV PATH="$VIRTUAL_ENV/bin:$PATH" # # https://issues.redhat.com/browse/MGMT-12697 COPY --from=quay.io/goswagger/swagger:sha-5d0a00d /usr/bin/swagger /usr/bin/goswagger - COPY --from=registry.k8s.io/kustomize/kustomize:v4.3.0 /app/kustomize /usr/bin/ RUN cd / && /assisted-service/hack/setup_env.sh spectral && \ diff --git a/subsystem/kubeapi_test.go b/subsystem/kubeapi_test.go index a7748af67217..467108be3c96 100644 --- a/subsystem/kubeapi_test.go +++ b/subsystem/kubeapi_test.go @@ -3286,7 +3286,7 @@ var _ = Describe("[kube-api]cluster installation", func() { Name: infraNsName.Name, } // InfraEnv Reconcile takes longer, since it needs to generate the image. - checkInfraEnvCondition(ctx, infraEnvKubeName, v1beta1.ImageCreatedCondition, "Unsupported keys found") + checkInfraEnvCondition(ctx, infraEnvKubeName, v1beta1.ImageCreatedCondition, "Invalid YAML") }) It("ensure StaticNetworkConfig is empty after NMStateConfig deletion", func() {