我正在尝试编写一个 Makefile 的一部分,它下载 OPA 并构建几个 Rego 文件以 tar.gz 格式的 wasm。
以下代码出现一行意外错误:
if [ ! -r build/opa ]; then \
curl -sSL -o build/opa https://openpolicyagent.org/downloads/v0.49.0/opa_linux_amd64_static; \
chmod 755 build/opa; \
fi
build/opa build -t wasm -o policies/allow_defines.tar.gz -e allow_defines/allow policies/allow_defines.rego
build/opa: 8: Syntax error: newline unexpected
make: *** [Makefile:159: build-opa] Error 2
我不知道是什么原因造成的。
uname_S := $(shell uname -s)
uname_M := $(shell uname -m)
ifeq ($(uname_S), Linux)
OS = linux
OPA_SUFFIX = _static
else ifeq ($(uname_S), Darwin)
OS = darwin
else
OS = windows
ARCH = amd64
endif
ifeq ($(uname_M), x86_64)
ARCH = amd64
else ifeq ($(uname_M), arm)
ARCH = arm64
OPA_SUFFIX = _static
else ifeq ($(uname_M), arm64)
ARCH = arm64
OPA_SUFFIX = _static
else ifeq ($(uname_M), aarch64)
ARCH = arm64
OPA_SUFFIX = _static
endif
OPA_VERSION=v0.49.0
OPA_DOWNLOAD_URL=https://openpolicyagent.org/downloads/$(OPA_VERSION)/opa_$(OS)_$(ARCH)$(OPA_SUFFIX)
build-opa:
if [ ! -r build/opa ]; then \
curl -sSL -o build/opa $(OPA_DOWNLOAD_URL); \
chmod 755 build/opa; \
fi
build/opa build -t wasm -o policies/allow_defines.tar.gz -e allow_defines/allow policies/allow_defines.rego
build/opa build -t wasm -o policies/auth.tar.gz -e auth/is_authorized policies/auth.rego
build/opa build -t wasm -o policies/default_allow.tar.gz -e default_allow/allow policies/default_allow.rego
build/opa build -t wasm -o policies/default_deny.tar.gz -e default_deny/allow policies/default_deny.rego
我唯一的线索是,如果我忽略安装 OPA 的部分(我的笔记本电脑上安装了 OPA)并重写
build
行,以便它只显示 opa build
...,而不是 build/opa
,即编译。但我希望它最终能在容器中工作……