Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 115 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
.PHONY: release update-version build-frontend build-wheel build-docker test-iris cleanup-push test-whl test-local test-gcp upload-to-gcs

# todo: add test-gcp
pre-release: update-version build-frontend build-wheel build-docker test-iris test-whl test-local upload-to-gcs

release: pre-release cleanup-push

update-version:
@echo "Updating preswald version..."
@current_version=$$(grep "version" pyproject.toml | grep -v "^#" | head -1 | sed -E 's/.*version = "([^"]+)".*/\1/'); \
if [ -z "$$current_version" ]; then \
echo "Error: Could not find version in pyproject.toml"; \
exit 1; \
fi; \
major=$$(echo $$current_version | cut -d. -f1); \
minor=$$(echo $$current_version | cut -d. -f2); \
patch=$$(echo $$current_version | cut -d. -f3); \
new_patch=$$(echo "$$patch + 1" | bc); \
new_version="$$major.$$minor.$$new_patch"; \
if [ "$$(uname)" = "Darwin" ]; then \
sed -i '' "s/version = \"$$current_version\"/version = \"$$new_version\"/" pyproject.toml; \
else \
sed -i "s/version = \"$$current_version\"/version = \"$$new_version\"/" pyproject.toml; \
fi; \
echo "Version updated from $$current_version to $$new_version"

build-frontend:
@echo "Building frontend..."
python -m preswald.build frontend

build-wheel:
@echo "Building wheel..."
python -m build
@echo "Wheel built successfully"

build-docker:
@echo "Building preswald docker image..."
@mkdir -p docker/tmp
@latest_wheel=$$(ls -t dist/preswald-*.whl | head -1); \
wheel_exists=false; \
if [ -f "$$latest_wheel" ]; then \
cp $$latest_wheel docker/wheel.whl; \
wheel_exists=true; \
fi;
@echo "wheel_exists=$$wheel_exists"
cd docker && docker buildx build --platform linux/amd64 --pull=false --no-cache \
--build-arg USE_LOCAL_WHEEL=$$wheel_exists \
-t preswald -f preswald.Dockerfile .
docker tag preswald structuredlabs/preswald-base

test-iris:
@echo "Testing iris example app..."
docker build --pull=false --no-cache -t iris_app -f ./docker/test/iris_app.Dockerfile .
@echo "Running automated test of iris app..."
docker run -d -p 8501:8501 --name iris_test_container iris_app
@echo "Waiting for app to start..."
sleep 10
@echo "Testing app endpoint..."
curl -s --fail http://localhost:8501 || (docker stop iris_test_container && docker rm iris_test_container && echo "Test failed: could not connect to app" && exit 1)
@echo "Test successful, cleaning up container..."
docker stop iris_test_container
docker rm iris_test_container

cleanup-push:
@echo "Pushing to DockerHub..."
@echo "Authenticating with DockerHub..."
@echo "$$DOCKERHUB_TOKEN" | docker login -u "$$DOCKERHUB_USERNAME" --password-stdin
docker push structuredlabs/preswald-base
@echo "Cleaning up..."
@rm -f docker/wheel.whl
docker logout

test-whl:
@echo "Testing preswald wheel..."
@latest_wheel=$$(ls -t dist/preswald-*.whl | head -1); \
conda create -n preswald_test python=3.12 -y; \
conda activate preswald_test; \
pip install $$latest_wheel; \
preswald --version; \
conda deactivate; \
conda env remove -n preswald_test -y

test-local:
@echo "Running local deployment test..."
./autotest/deployments/local/test.sh

test-gcp:
@echo "Running GCP deployment test..."
./autotest/deployments/gcp/test.sh

upload-to-gcs:
@echo "Uploading wheel to Google Cloud Storage..."
@if [ -z "$$PRESWALD_DEPLOYER_DEV_SA" ]; then \
echo "Error: PRESWALD_DEPLOYER_DEV_SA environment variable not set"; \
exit 1; \
fi; \
if ! command -v gcloud >/dev/null 2>&1; then \
echo "Error: gcloud command not found."; \
exit 1; \
fi; \
if ! command -v gsutil >/dev/null 2>&1; then \
echo "Error: gsutil command not found."; \
exit 1; \
fi; \
latest_wheel=$$(ls -t dist/preswald-*.whl | head -1); \
if [ ! -f "$$latest_wheel" ]; then \
echo "Error: No wheel file found in dist/ directory."; \
exit 1; \
fi; \
wheel_filename=$$(basename $$latest_wheel); \
echo "$$PRESWALD_DEPLOYER_DEV_SA" | base64 --decode > /tmp/service-account.json; \
gcloud auth activate-service-account --key-file=/tmp/service-account.json || { echo "Failed to authenticate with Google Cloud"; rm -f /tmp/service-account.json; exit 1; }; \
gsutil cp $$latest_wheel gs://preswald_wheels/$$wheel_filename || { echo "Failed to upload to Google Cloud Storage"; rm -f /tmp/service-account.json; exit 1; }; \
rm -f /tmp/service-account.json; \
echo "Successfully uploaded $$wheel_filename to gs://preswald_wheels/"
19 changes: 14 additions & 5 deletions docker/preswald.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,20 @@ RUN apt-get update && \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

# COPY ./preswald-0.1.52-py3-none-any.whl /app/

RUN pip install --no-cache-dir --upgrade pip && \
pip install --no-cache-dir --upgrade preswald
# pip install --no-cache-dir --upgrade ./preswald-0.1.52-py3-none-any.whl --force-reinstall
# Define an argument to check if we should use local wheel
ARG USE_LOCAL_WHEEL=false
COPY wheel.whl /app/wheel.whl

RUN pip install --no-cache-dir --upgrade pip

# Install using the appropriate method
RUN if [ "$USE_LOCAL_WHEEL" = "true" ] && [ -f /app/wheel.whl ]; then \
echo "Installing from local wheel" && \
pip install --no-cache-dir --upgrade /app/wheel.whl --force-reinstall; \
else \
echo "Installing from PyPI" && \
pip install --no-cache-dir --upgrade preswald; \
fi

FROM python:3.12-slim-bullseye

Expand Down