Skip to content

Commit

Permalink
fix(dev): fix issues when using container tools and cargo is not in…
Browse files Browse the repository at this point in the history
…stalled locally (#18112)

* fix(dev): fix error in `make` when `cargo` is not installed

Fixes the following error when using `make environment`:

    make: cargo: No such file or directory

Signed-off-by: Hugo Hromic <[email protected]>

* fix(dev): fix `build` make target when `cargo` is not installed

Fixes the following error when using `make build ENVIRONMENT=true`:

    Makefile:212: *** "Please install Rust: https://www.rust-lang.org/tools/install".  Stop.

Also switch to using `command` (POSIX compatible) instead of `which` for detecting `cargo`.
Details in <https://mywiki.wooledge.org/BashFAQ/081>.

Signed-off-by: Hugo Hromic <[email protected]>

* fix(dev): fix detection of container tool in `make`

Fixes the following error when `ENVIRONMENT=true` and neither Docker or Podman are available:

    make: podman: No such file or directory
    make: *** [Makefile:174: build] Error 127

Podman was being used as fallback even if also not available.
A descriptive error is now reported instead in this situation.

Signed-off-by: Hugo Hromic <[email protected]>

* chore: add `ifneq` Makefile keyword to spell checker allow-list

Signed-off-by: Hugo Hromic <[email protected]>

---------

Signed-off-by: Hugo Hromic <[email protected]>
  • Loading branch information
hhromic authored Aug 1, 2023
1 parent e6f2ccc commit 36111b5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
1 change: 1 addition & 0 deletions .github/actions/spelling/allow.txt
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ https
humungus
icecream
ifeq
ifneq
imobile
influxd
ionik
Expand Down
20 changes: 17 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,13 @@ export VERBOSE ?= false
# Override the container tool. Tries docker first and then tries podman.
export CONTAINER_TOOL ?= auto
ifeq ($(CONTAINER_TOOL),auto)
override CONTAINER_TOOL = $(shell docker version >/dev/null 2>&1 && echo docker || echo podman)
ifeq ($(shell docker version >/dev/null 2>&1 && echo docker), docker)
override CONTAINER_TOOL = docker
else ifeq ($(shell podman version >/dev/null 2>&1 && echo podman), podman)
override CONTAINER_TOOL = podman
else
override CONTAINER_TOOL = unknown
endif
endif
# If we're using podman create pods else if we're using docker create networks.
export CURRENT_DIR = $(shell pwd)
Expand All @@ -54,7 +60,7 @@ export AWS_ACCESS_KEY_ID ?= "dummy"
export AWS_SECRET_ACCESS_KEY ?= "dummy"

# Set version
export VERSION ?= $(shell cargo vdev version)
export VERSION ?= $(shell command -v cargo >/dev/null && cargo vdev version || echo unknown)

# Set if you are on the CI and actually want the things to happen. (Non-CI users should never set this.)
export CI ?= false
Expand Down Expand Up @@ -128,6 +134,7 @@ define ENVIRONMENT_EXEC
endef


ifneq ($(CONTAINER_TOOL), unknown)
ifeq ($(ENVIRONMENT_AUTOBUILD), true)
define ENVIRONMENT_PREPARE
@echo "Building the environment. (ENVIRONMENT_AUTOBUILD=true) This may take a few minutes..."
Expand All @@ -142,6 +149,11 @@ define ENVIRONMENT_PREPARE
$(CONTAINER_TOOL) pull $(ENVIRONMENT_UPSTREAM)
endef
endif
else
define ENVIRONMENT_PREPARE
$(error "Please install a container tool such as Docker or Podman")
endef
endif

.PHONY: check-container-tool
check-container-tool: ## Checks what container tool is installed
Expand Down Expand Up @@ -208,9 +220,11 @@ build-graphql-schema: ## Generate the `schema.json` for Vector's GraphQL API

.PHONY: check-build-tools
check-build-tools:
ifeq (, $(shell which cargo))
ifneq ($(ENVIRONMENT), true)
ifeq (, $(shell command -v cargo))
$(error "Please install Rust: https://www.rust-lang.org/tools/install")
endif
endif

##@ Cross Compiling
.PHONY: cross-enable
Expand Down

0 comments on commit 36111b5

Please sign in to comment.