Skip to content

Commit

Permalink
refactor: Refactored make & related files.
Browse files Browse the repository at this point in the history
- Removed nested/recursive make calls in targets.
- Made docker conditonal, w/ podman as an alternative tool.
  • Loading branch information
ShreyBana committed Jan 14, 2025
1 parent a1db40d commit 84005ef
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 55 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci_check_pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,6 @@ jobs:
- name: run tests
shell: bash
run: |
make ci-test
make test CI=1
env:
APP_ENV: "TEST"
2 changes: 0 additions & 2 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: "3.4"

services:
postgres:
build: ./docker-compose/postgres/
Expand Down
122 changes: 70 additions & 52 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,19 @@ DOCKER_DNS ?= localhost
TENANT ?= dev
SHELL := /usr/bin/env bash
FEATURES ?= ssr
HAS_DOCKER := $(shell command -v docker > /dev/null; echo $$?)
HAS_PODMAN := $(shell command -v podman > /dev/null; echo $$?)
CARGO_FLAGS := --color always --no-default-features

ifeq ($(HAS_DOCKER),0)
DOCKER := docker
else ifeq ($(HAS_PODMAN),0)
DOCKER := podman
else
$(error "Neither docker nor podman found, please install one of them.")
endif

COMPOSE := $(DOCKER) compose

.PHONY:
db-init
Expand All @@ -14,22 +27,36 @@ FEATURES ?= ssr
validate-psql-connection
cac

db:
ifndef CI
$(COMPOSE) up -d postgres
else
@echo "Skipping postgres container-setup in CI."
endif
@echo "Verifying postgres readiness..."
@while ! pg_isready -h $(DOCKER_DNS) -p 5432; do sleep 0.5; done

localstack:
ifndef CI
$(COMPOSE) up -d localstack
else
@echo "Skipping localstack container-setup in CI."
endif
@echo "Verifying localstack readiness..."
@while ! aws --no-cli-pager --endpoint-url=http://$(DOCKER_DNS):4566 --region=ap-south-1 sts get-caller-identity; do \
sleep 0.5; \
done

db-init:
diesel migration run --locked-schema --config-file=crates/superposition_types/src/database/diesel.toml

cleanup:
-docker rm -f $$(docker container ls --filter name=^context-aware-config -a -q)
-docker rmi -f $$(docker images | grep context-aware-config-postgres | cut -f 10 -d " ")

migration: cleanup
docker-compose up -d postgres
cp .env.example .env
while ! make validate-psql-connection; \
do echo "waiting for postgres bootup"; \
sleep 0.5; \
done
-$(DOCKER) rm -f $$($(DOCKER) container ls --filter name=^context-aware-config -a -q)
-$(DOCKER) rmi -f $$($(DOCKER) images | grep context-aware-config-postgres | cut -f 10 -d " ")

migration: cleanup db
diesel migration run --locked-schema --config-file=crates/superposition_types/src/database/diesel.toml
docker-compose down
$(COMPOSE) down

legacy_db_setup:
grep 'DATABASE_URL=' .env | sed -e 's/DATABASE_URL=//' | xargs ./scripts/legacy-db-setup.sh
Expand All @@ -44,52 +71,47 @@ validate-psql-connection:
pg_isready -h $(DOCKER_DNS) -p 5432


env-setup:
npm ci
-docker-compose up -d postgres localstack
cp .env.example .env
while ! make validate-psql-connection validate-aws-connection; \
do echo "waiting for postgres, localstack bootup"; \
sleep 0.5; \
done

test-tenant:
make tenant TENANT='test'

dev-tenant:
make tenant TENANT='dev'
test-tenant: TENANT = 'test'
test-tenant: tenant

ci-setup: env-setup test-tenant
npm ci --loglevel=error
make run -e DOCKER_DNS=$(DOCKER_DNS) 2>&1 | tee test_logs &
while ! grep -q "starting in Actix" test_logs; \
do echo "ci-test: waiting for bootup..." && sleep 4; \
done
# NOTE: `make db-init` finally starts a postgres container and runs all the migrations with locked-schema option
# to prevent update of schema.rs for both cac and experimentation.
# NOTE: The container spinned-up here is the actual container being used in development
echo setup completed successfully!!!
dev-tenant: TENANT = 'dev'
dev-tenant: tenant

setup: env-setup
SETUP_DEPS = db localstack
ifdef CI
SETUP_DEPS += test-tenant
endif
setup: $(SETUP_DEPS)
ifeq ($(shell test -f .env; echo $$?),1)
@echo ".env not present, copying .env.example as .env"
@cp .env.example .env
endif
npm ci

kill:
-pkill -f target/debug/superposition &

get-password:
export DB_PASSWORD=`./docker-compose/localstack/get_db_password.sh` && echo $$DB_PASSWORD

superposition: CARGO_FLAGS += --features=$(FEATURES)
superposition:
cargo run --color always --bin superposition --no-default-features --features=$(FEATURES)
cargo build $(CARGO_FLAGS) --bin superposition

superposition-example:
cargo run --bin cac-demo-app

superposition_legacy: CARGO_FLAGS += --features='ssr superposition_types/disable_db_data_validation
superposition_legacy: CARGO_FLAGS += superposition_types/disable_db_data_validation
superposition_legacy: CARGO_FLAGS += context_aware_config/disable_db_data_validation
superposition_legacy: CARGO_FLAGS += experimentation_platform/disable_db_data_validation'
superposition_legacy:
cargo run --color always --bin superposition --no-default-features --features='ssr superposition_types/disable_db_data_validation context_aware_config/disable_db_data_validation experimentation_platform/disable_db_data_validation'
cargo run $(CARGO_FLAGS) --bin superposition

superposition_dev: CARGO_FLAGS += --features=$(FEATURES)
superposition_dev:
# export DB_PASSWORD=`./docker-compose/localstack/get_db_password.sh`
cargo watch -x 'run --color always --bin superposition --no-default-features --features=$(FEATURES)'
cargo watch -x 'run $(CARGO_FLAGS) --bin superposition'


frontend:
Expand All @@ -110,22 +132,18 @@ backend:

build: frontend backend

run: kill frontend
while ! make validate-psql-connection validate-aws-connection; \
do echo "waiting for postgres, localstack bootup"; \
sleep 0.5; \
done
make superposition -e DOCKER_DNS=$(DOCKER_DNS)
run: kill db localstack frontend superposition
@./target/debug/superposition

run_legacy: kill build
while ! make validate-psql-connection validate-aws-connection; \
do echo "waiting for postgres, localstack bootup"; \
sleep 0.5; \
done
make superposition_legacy -e DOCKER_DNS=$(DOCKER_DNS)
run_legacy: kill build db localstack superposition_legacy

ci-test: ci-setup
test: setup frontend superposition
cargo test
@echo "Running superposition"
@./target/debug/superposition &
@echo "Awaiting superposition boot..."
@timeout 200s bash -c \
"while ! curl --silent 'http://localhost:8080/health' 2>&1 > /dev/null; do sleep 0.5; done"
npm run test

tailwind:
Expand Down

0 comments on commit 84005ef

Please sign in to comment.