diff --git a/Makefile b/Makefile index 5f4ee74d..4cf8e62b 100644 --- a/Makefile +++ b/Makefile @@ -2,51 +2,29 @@ .DEFAULT_GOAL := help -# DOCKER TASKS -# Build the container -build: ## Build the container - @docker build -t permitio/pdp-v2 . - -build-local: ## Build the container - @docker build -t permitio/pdp-v2:local . - prepare: ifndef VERSION - $(error You must set the VERSION variable to build a release image) + $(error You must set VERSION variable to build local image) endif - echo $(VERSION) >permit_pdp_version ./build_opal_bundle.sh -build-release-vanilla: prepare - @docker buildx build --platform linux/arm64,linux/amd64 -t permitio/pdp-v2-vanilla:$(VERSION)$(BUILD_SUFFIX) --push . - -build-release-prod: prepare - @docker buildx build --platform linux/arm64,linux/amd64 -t permitio/pdp-v2:$(VERSION)$(BUILD_SUFFIX) --push . - -build-release-local-amd64: prepare - @docker buildx build --platform linux/amd64 -t permitio/pdp-v2:$(VERSION)$(BUILD_SUFFIX) . --load - -build-release-local-arm64: prepare - @docker buildx build --platform linux/arm64 -t permitio/pdp-v2:$(VERSION)$(BUILD_SUFFIX) . --load - -build-release-local: prepare - @docker build -t permitio/pdp-v2:$(VERSION)$(BUILD_SUFFIX) . --load - -run: ## Run the container locally - @docker run -it \ - -e "OPAL_SERVER_URL=http://host.docker.internal:7002" \ - -e "PDP_CONTROL_PLANE=http://host.docker.internal:8000" \ - -e "PDP_API_KEY=$(DEV_MODE_CLIENT_TOKEN)" \ - -p 7000:7000 \ - -p 8181:8181 \ - permitio/pdp - -run-against-prod: ## Run the container against prod - @docker run -it \ - -e "PDP_PRINT_CONFIG_ON_STARTUP=true" \ - -e "PDP_API_KEY=$(AUTPDP_PROD_CLIENT_TOKEN)" \ - -e "OPAL_CLIENT_TOKEN=$(OPAL_PROD_CLIENT_TOKEN)" \ - -p 7000:7000 \ - -p 8181:8181 \ - permitio/pdp +run-prepare: +ifndef API_KEY + $(error You must set API_KEY variable to run pdp locally) +endif +ifndef VERSION + $(error You must set VERSION variable to run pdp locally) +endif + +build-amd64: prepare + @docker buildx build --platform linux/amd64 -t permitio/pdp-v2:$(VERSION) . --load + +build-arm64: prepare + @docker buildx build --platform linux/arm64 -t permitio/pdp-v2:$(VERSION) . --load + +run: run-prepare + @docker run -p 7766:7000 --env PDP_API_KEY=$(API_KEY) --env PDP_DEBUG=true permitio/pdp-v2:$(VERSION) + +run-on-background: run-prepare + @docker run -d -p 7766:7000 --env PDP_API_KEY=$(API_KEY) --env PDP_DEBUG=true permitio/pdp-v2:$(VERSION) diff --git a/build_opal_bundle.sh b/build_opal_bundle.sh index d074cc93..106c5f3e 100755 --- a/build_opal_bundle.sh +++ b/build_opal_bundle.sh @@ -2,20 +2,28 @@ set -e -rm -rf custom -mkdir custom +# Check if PDP_VANILLA is set to true from command line argument +if [ "$PDP_VANILLA" == "true" ]; then + echo "Building for pdp-vanilla environment." +fi -if [ "$CUSTOM_OPAL" != "" ] -then - echo "Using custom OPAL from $CUSTOM_OPAL" - tar -czf custom/custom_opal.tar.gz -C "$CUSTOM_OPAL" --exclude opal-server --exclude '.*' packages README.md -fi; +# Check if permit-opa directory already exists +if [ ! -d "../permit-opa" ]; then + # Clone the permit-opa repository into the parent directory if it doesn't exist + git clone git@github.com:permitio/permit-opa.git ../permit-opa +else + echo "permit-opa directory already exists. Skipping clone operation." +fi -if [ "$CUSTOM_OPA" != "" ] -then - echo "Using custom OPA from $CUSTOM_OPA" +# Conditionally execute the custom OPA tarball creation section based on the value of PDP_VANILLA +if [ "$PDP_VANILLA" != "true" ]; then + # Custom OPA tarball creation section + rm -rf custom + mkdir custom build_root="$PWD" - cd "$CUSTOM_OPA" + cd "../permit-opa" find * -name '*go*' -print0 | xargs -0 tar -czf "$build_root"/custom/custom_opa.tar.gz --exclude '.*' cd "$build_root" +else + echo "Skipping custom OPA tarball creation for pdp-vanilla environment." fi