Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Hive upstream image building #2547

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
ARG CONTAINER_SUB_MANAGER_OFF=0
ARG EL8_BUILD_IMAGE=registry.ci.openshift.org/ocp/builder:rhel-8-golang-1.22-openshift-4.17
ARG EL9_BUILD_IMAGE=registry.ci.openshift.org/ocp/builder:rhel-9-golang-1.22-openshift-4.17
ARG BASE_IMAGE=registry.ci.openshift.org/ocp/4.16:base-rhel9
ARG EL8_BUILD_IMAGE=${EL8_BUILD_IMAGE:-registry.ci.openshift.org/ocp/builder:rhel-8-golang-1.22-openshift-4.17}
ARG EL9_BUILD_IMAGE=${EL9_BUILD_IMAGE:-registry.ci.openshift.org/ocp/builder:rhel-9-golang-1.22-openshift-4.17}
ARG BASE_IMAGE=${BASE_IMAGE:-registry.ci.openshift.org/ocp/4.16:base-rhel9}

FROM ${EL8_BUILD_IMAGE} as builder_rhel8
ARG GO=${GO:-go}
RUN mkdir -p /go/src/github.com/openshift/hive
WORKDIR /go/src/github.com/openshift/hive
COPY . .


RUN if [ -e "/activation-key/org" ]; then unlink /etc/rhsm-host; subscription-manager register --org $(cat "/activation-key/org") --activationkey $(cat "/activation-key/activationkey"); fi
RUN python3 -m ensurepip
ENV GO=${GO}
RUN make build-hiveutil

FROM ${EL9_BUILD_IMAGE} as builder_rhel9
ARG GO=${GO:-go}
ARG CONTAINER_SUB_MANAGER_OFF
RUN mkdir -p /go/src/github.com/openshift/hive
WORKDIR /go/src/github.com/openshift/hive
Expand All @@ -22,6 +25,7 @@ COPY . .
ENV SMDEV_CONTAINER_OFF=${CONTAINER_SUB_MANAGER_OFF}
RUN if [ -e "/activation-key/org" ]; then unlink /etc/rhsm-host; subscription-manager register --org $(cat "/activation-key/org") --activationkey $(cat "/activation-key/activationkey"); fi
RUN python3 -m ensurepip
ENV GO=${GO}
RUN make build-hiveadmission build-manager build-operator && \
make build-hiveutil

Expand Down
13 changes: 7 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
.PHONY: all
all: vendor update test build

# These images need to be synced with the default values in the Dockerfile.
EL8_BUILD_IMAGE ?= registry.ci.openshift.org/ocp/builder:rhel-8-golang-1.22-openshift-4.17
EL9_BUILD_IMAGE ?= registry.ci.openshift.org/ocp/builder:rhel-9-golang-1.22-openshift-4.17
BASE_IMAGE ?= registry.ci.openshift.org/ocp/4.16:base-rhel9

# In openshift ci (Prow), we need to set $HOME to a writable directory else tests will fail
# because they don't have permissions to create /.local or /.cache directories
# as $HOME is set to "/" by default.
Expand Down Expand Up @@ -39,6 +44,7 @@ LOG_LEVEL ?= debug
# Image URL to use all building/pushing image targets
IMG ?= hive-controller:latest

GO ?=go
GO_PACKAGES :=./...
GO_BUILD_PACKAGES :=./cmd/...
GO_BUILD_BINDIR :=bin
Expand Down Expand Up @@ -76,9 +82,8 @@ SOURCE_GIT_TAG := $(shell export HOME=$(HOME); python3 -m ensurepip >&2; python3
BINDATA_INPUTS :=./config/sharded_controllers/... ./config/hiveadmission/... ./config/controllers/... ./config/rbac/... ./config/configmaps/...
$(call add-bindata,operator,$(BINDATA_INPUTS),,assets,pkg/operator/assets/bindata.go)

IMAGE_BUILD_EXTRA_FLAGS := --build-arg BASE_IMAGE=$(BASE_IMAGE) --build-arg EL8_BUILD_IMAGE=$(EL8_BUILD_IMAGE) --build-arg EL9_BUILD_IMAGE=$(EL9_BUILD_IMAGE)
$(call build-image,hive,$(IMG),./Dockerfile,.)
$(call build-image,hive-fedora-dev-base,hive-fedora-dev-base,./build/fedora-dev/Dockerfile.devbase,.)
$(call build-image,hive-fedora-dev,$(IMG),./build/fedora-dev/Dockerfile.dev,.)

clean:
rm -rf $(GO_BUILD_BINDIR)
Expand Down Expand Up @@ -304,10 +309,6 @@ docker-build:
docker-push:
$(DOCKER_CMD) push ${IMG}

# Build and push the dev image
.PHONY: docker-dev-push
docker-dev-push: build image-hive-fedora-dev docker-push

# Build the dev image using builah
.PHONY: buildah-dev-build
buildah-dev-build:
Expand Down
20 changes: 12 additions & 8 deletions docs/developing.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
- [Creating a Kubernetes In Docker (kind) Cluster](#creating-a-kubernetes-in-docker-kind-cluster)
- [Deploying from Source](#deploying-from-source)
- [Full Container Build](#full-container-build)
- [Fedora Development Container Build](#fedora-development-container-build)
- [Using public images](#using-public-images)
- [Running Code Locally](#running-code-locally)
- [hive-operator](#hive-operator)
- [hive-controllers](#hive-controllers)
Expand Down Expand Up @@ -157,21 +157,25 @@ NOTE: If you are running on Kubernetes or kind >= version 1.24, (not OpenShift),
./hack/create-service-account-secrets.sh
```

### Fedora Development Container Build
### Using public images

This approach is much faster than a full container build as it uses a base OS image, and binaries compiled on your host OS and then added to the container. *At present this is best suited for Fedora 33+.*
If you cannot login to registry.ci.openshift.org, a temporary solution is to use
public images during build and test. At the time of writing, the following public images
do the trick.

The base image only needs to be built once locally, though you may wish to periodically update it:

```bash
make image-hive-fedora-dev-base
```shell
export EL8_BUILD_IMAGE=registry.ci.openshift.org/openshift/release:golang-1.22
export EL9_BUILD_IMAGE=registry.ci.openshift.org/openshift/release:golang-1.22
export BASE_IMAGE=registry.ci.openshift.org/origin/4.16:base
# NOTE: This produces images which are not FIPS-compliant.
export GO="CGO_ENABLED=0 go"
abraverm marked this conversation as resolved.
Show resolved Hide resolved
```

You can now build the development image with the hiveutil binaries from your local system:

```bash
export IMG="quay.io/{username}/hive:latest}"
make build image-hive-fedora-dev docker-push deploy
make build image-hive docker-push deploy
oc delete pods -n hive --all
```

Expand Down