Skip to content

Commit

Permalink
OCPBUGS-17374: Fast specific dockerignore
Browse files Browse the repository at this point in the history
Improves container runtime detection and applies a runtime specific
dockerignore for the fast Dockerfile. The rename from Dockerfile.fast to
fast.Dockerfile is due to the conventions in the new Docker build
backend.

Signed-off-by: Antoni Segura Puimedon <antoni@redhat.com>
  • Loading branch information
celebdor committed Aug 4, 2023
1 parent 2aa885e commit 4baeb8d
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 13 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ tools/bin
/kubeconfig
vendor/**/.dockerignore
.docker
/fast.Dockerfile.dockerignore

# ignore util binaries
/contrib/cleanzones/cleanzones
Expand Down
14 changes: 11 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ IMG ?= hypershift:latest
CRD_OPTIONS ?= "crd"

# Runtime CLI to use for building and pushing images
RUNTIME ?= docker
RUNTIME ?= $(shell sh hack/utils.sh get_container_engine)

TOOLS_DIR=./hack/tools
BIN_DIR=bin
Expand Down Expand Up @@ -211,10 +211,18 @@ staticcheck: $(STATICCHECK)
docker-build:
${RUNTIME} build . -t ${IMG}

.PHONY: fast.Dockerfile.dockerignore
fast.Dockerfile.dockerignore:
sed -e '/^bin\//d' .dockerignore > fast.Dockerfile.dockerignore

# Build the docker image copying binaries from workspace
.PHONY: docker-build-fast
docker-build-fast: build
${RUNTIME} build . -t ${IMG} -f Dockerfile.fast
docker-build-fast: build fast.Dockerfile.dockerignore
ifeq ($(RUNTIME),podman)
${RUNTIME} build . -t ${IMG} -f fast.Dockerfile --ignorefile fast.Dockerfile.dockerignore
else
DOCKER_BUILDKIT=1 ${RUNTIME} build . -t ${IMG} -f fast.Dockerfile
endif

# Push the docker image
.PHONY: docker-push
Expand Down
File renamed without changes.
16 changes: 6 additions & 10 deletions hack/container-run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,15 @@

set -ex

if command -v podman > /dev/null 2>&1
then
ENGINE=podman
elif command -v docker > /dev/null 2>&1
then
ENGINE=docker
else
echo "No container runtime found"
exit 1
fi
SCRIPT_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
readonly SCRIPT_DIR

source "${SCRIPT_DIR}/utils.sh"

IMAGE=docker.io/openshift/origin-release:golang-1.16

ENGINE=$(get_container_engine)

ENGINE_CMD="${ENGINE} run --rm -v $(pwd):/go/src/github.com/openshift/hypershift:Z -w /go/src/github.com/openshift/hypershift $IMAGE"

${ENGINE_CMD} $*
17 changes: 17 additions & 0 deletions hack/utils.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/sh

get_container_engine() {
if command -v podman >/dev/null 2>&1; then
echo podman
retval=0
elif command -v docker >/dev/null 2>&1; then
echo docker
retval=0
else
echo >&2 "No container runtime found"
retval=1
fi
return $retval
}

"$@"

0 comments on commit 4baeb8d

Please sign in to comment.