Skip to content

Commit

Permalink
Add Pulsar start and stop scripts with GitHub Actions integration #cl…
Browse files Browse the repository at this point in the history
…eanup
  • Loading branch information
daveads committed Sep 25, 2024
1 parent 17d5f9d commit a86e789
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 15 deletions.
22 changes: 7 additions & 15 deletions .github/workflows/test-suite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,31 +55,22 @@ jobs:
with:
python-version: "${{ matrix.python-version }}"

# Install Docker Compose if it's not available by default
- name: Set up Docker Compose
run: sudo apt-get install docker-compose -y

# Start Pulsar using Docker Compose
- name: Start Pulsar
run: docker-compose up -d pulsar
run: "scripts/start_pulsar"


- name: Wait for Pulsar
run: |
timeout 300 bash -c '
until curl -s http://localhost:8080/admin/v2/brokers/healthcheck; do
echo "Waiting for Pulsar to be ready..."
sleep 5
done
echo "pulsar is ready"
'
run: "scripts/wait_for_pulsar"

- name: "Install dependencies"
run: "scripts/install"

# - name: "Run linting checks"
# run: "scripts/check"

- name: "Build package & docs"
run: "scripts/build"

- name: "Run tests"
run: "scripts/test"

Expand All @@ -88,4 +79,5 @@ jobs:

# Stop the Pulsar container after all tests are complete
- name: Stop Pulsar
run: docker-compose down
if: always() # This ensures the step runs even if previous steps fail
run: "scripts/stop_pulsar"
16 changes: 16 additions & 0 deletions scripts/start_pulsar
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

# Install Docker Compose if it's not available
if ! command -v docker-compose &> /dev/null; then
echo "Docker Compose not found. Installing..."
sudo apt-get update
sudo apt-get install -y docker-compose
else
echo "Docker Compose is already installed."
fi

# Start Pulsar using Docker Compose
echo "Starting Pulsar..."
docker-compose up -d pulsar

echo "Pulsar startup complete."
17 changes: 17 additions & 0 deletions scripts/stop_pulsar
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash


echo "Stopping Pulsar container..."

# Stop and remove containers defined in docker-compose.yml
if docker-compose down; then
echo "Pulsar container have been stopped and removed successfully."
else
echo "Error: Failed to stop Pulsar containers. Please check Docker Compose configuration."
exit 1
fi

# Optional: Remove volumes
# docker-compose down -v

echo "Cleanup complete."
19 changes: 19 additions & 0 deletions scripts/wait_for_pulsar
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

MAX_RETRIES=60
RETRY_INTERVAL=5
HEALTH_CHECK_URL="http://localhost:8080/admin/v2/brokers/healthcheck"

echo "Waiting for Pulsar to be ready..."

for i in $(seq 1 $MAX_RETRIES); do
if curl -s "$HEALTH_CHECK_URL" > /dev/null; then
echo "Pulsar is ready!"
exit 0
fi
echo "Attempt $i/$MAX_RETRIES: Pulsar is not ready yet. Retrying in $RETRY_INTERVAL seconds..."
sleep $RETRY_INTERVAL
done

echo "Error: Pulsar did not become ready within the allocated time."
exit 1

0 comments on commit a86e789

Please sign in to comment.