Skip to content

Commit

Permalink
build locally pdp (#142)
Browse files Browse the repository at this point in the history
* build locally pdp

* little fix

* pre commit fix

* fix PDP_VANILLA var to bool

* fix1
  • Loading branch information
EliMoshkovich authored Apr 17, 2024
1 parent f7a59cf commit 107f438
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 53 deletions.
62 changes: 20 additions & 42 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
30 changes: 19 additions & 11 deletions build_opal_bundle.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 [email protected]: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

0 comments on commit 107f438

Please sign in to comment.