Merge pull request #6 from KemingHe/docs/credit-jalen/KemingHe #24
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build Test | |
on: | |
push: | |
pull_request: | |
workflow_dispatch: | |
schedule: | |
- cron: '0 7 * * 0' | |
env: | |
IMAGE_NAME: strain-seer | |
IMAGE_TAG: ${{ github.sha }} | |
CONTAINER_PORT: 8501 | |
# AMD64 (Intel) architecture settings | |
AMD64_PLATFORM: linux/amd64 | |
AMD64_CONTAINER: strain-seer-test-amd64 | |
AMD64_IMAGE: strain-seer-test-amd64 | |
AMD64_HEALTH_CHECK_TIMEOUT: 60 | |
# ARM64 (Apple Silicon) architecture settings | |
ARM64_PLATFORM: linux/arm64 | |
ARM64_CONTAINER: strain-seer-test-arm64 | |
ARM64_IMAGE: strain-seer-test-arm64 | |
ARM64_HEALTH_CHECK_TIMEOUT: 60 | |
jobs: | |
build-test-amd64: | |
if: github.repository == 'KemingHe/strain-seer' | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ github.ref }} | |
# Enable advanced build features | |
- name: Set up Docker Buildx | |
# Pinned 3rd party action to commit hash of release v3.10.0 on 02/26/2025 to prevent supply chain attacks | |
uses: docker/setup-buildx-action@b5ca514318bd6ebac0fb2aedd5d36ec1b5c232a2 | |
- name: Build Docker image | |
run: | | |
docker buildx build \ | |
--platform ${{ env.AMD64_PLATFORM }} \ | |
--build-arg BUILD_DATE=${{ github.event.head_commit.timestamp }} \ | |
--build-arg VCS_REF=${{ github.sha }} \ | |
--load \ | |
-t ${{ env.AMD64_IMAGE }}:${{ env.IMAGE_TAG }} \ | |
. | |
- name: Run E2E test | |
run: | | |
# Start the container in detached mode with additional logging | |
docker run -d \ | |
-p ${{ env.CONTAINER_PORT }}:${{ env.CONTAINER_PORT }} \ | |
--name ${{ env.AMD64_CONTAINER }} \ | |
${{ env.AMD64_IMAGE }}:${{ env.IMAGE_TAG }} || { | |
echo "Failed to start AMD64 container." | |
exit 1 | |
} | |
# Wait for the container to be healthy | |
echo "Waiting for container to be healthy..." | |
for i in $(seq 1 ${{ env.AMD64_HEALTH_CHECK_TIMEOUT }}); do | |
if docker ps --filter "name=${{ env.AMD64_CONTAINER }}" --filter "health=healthy" | grep -q "${{ env.AMD64_CONTAINER }}"; then | |
echo "Container is healthy!" | |
break | |
fi | |
if [ $i -eq ${{ env.AMD64_HEALTH_CHECK_TIMEOUT }} ]; then | |
echo "Container failed to become healthy within ${{ env.AMD64_HEALTH_CHECK_TIMEOUT }} seconds" | |
echo "Container logs:" | |
docker logs ${{ env.AMD64_CONTAINER }} | |
echo "Container inspect:" | |
docker inspect ${{ env.AMD64_CONTAINER }} | |
exit 1 | |
fi | |
echo "Waiting for container to be healthy... ($i/${{ env.AMD64_HEALTH_CHECK_TIMEOUT }})" | |
sleep 1 | |
done | |
# Test the Streamlit health endpoint with retries | |
echo "Testing Streamlit health endpoint..." | |
for i in $(seq 1 3); do | |
if curl -f http://localhost:${{ env.CONTAINER_PORT }}/_stcore/health; then | |
break | |
fi | |
if [ $i -eq 3 ]; then | |
echo "Health check failed after 3 attempts" | |
docker logs ${{ env.AMD64_CONTAINER }} | |
exit 1 | |
fi | |
echo "Health check attempt $i failed, retrying..." | |
sleep 5 | |
done | |
# Test the main Streamlit endpoint with retries | |
echo "Testing main Streamlit endpoint..." | |
for i in $(seq 1 3); do | |
if curl -f http://localhost:${{ env.CONTAINER_PORT }}; then | |
break | |
fi | |
if [ $i -eq 3 ]; then | |
echo "Main endpoint check failed after 3 attempts" | |
docker logs ${{ env.AMD64_CONTAINER }} | |
exit 1 | |
fi | |
echo "Main endpoint check attempt $i failed, retrying..." | |
sleep 5 | |
done | |
# Clean up | |
docker stop ${{ env.AMD64_CONTAINER }} || true | |
docker rm ${{ env.AMD64_CONTAINER }} || true | |
build-test-arm64: | |
if: github.repository == 'KemingHe/strain-seer' | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ github.ref }} | |
# Add support for ARM64 with QEMU | |
- name: Set up QEMU | |
# Pinned 3rd party action to commit hash of release v3.6.0 on 02/28/2025 to prevent supply chain attacks | |
uses: docker/setup-qemu-action@29109295f81e9208d7d86ff1c6c12d2833863392 | |
# Enable advanced build features | |
- name: Set up Docker Buildx | |
# Pinned 3rd party action to commit hash of release v3.10.0 on 02/26/2025 to prevent supply chain attacks | |
uses: docker/setup-buildx-action@b5ca514318bd6ebac0fb2aedd5d36ec1b5c232a2 | |
- name: Build Docker image | |
run: | | |
# Check if QEMU is properly set up | |
if ! docker buildx inspect default | grep -q "linux/arm64"; then | |
echo "Error: QEMU ARM64 support not properly configured" | |
exit 1 | |
fi | |
docker buildx build \ | |
--platform ${{ env.ARM64_PLATFORM }} \ | |
--build-arg BUILD_DATE=${{ github.event.head_commit.timestamp }} \ | |
--build-arg VCS_REF=${{ github.sha }} \ | |
--load \ | |
-t ${{ env.ARM64_IMAGE }}:${{ env.IMAGE_TAG }} \ | |
. || { | |
echo "Failed to build ARM64 image. This might be due to QEMU emulation issues." | |
exit 1 | |
} | |
- name: Run E2E test | |
run: | | |
# Start the container in detached mode with additional logging | |
docker run -d \ | |
-p ${{ env.CONTAINER_PORT }}:${{ env.CONTAINER_PORT }} \ | |
--name ${{ env.ARM64_CONTAINER }} \ | |
--platform ${{ env.ARM64_PLATFORM }} \ | |
${{ env.ARM64_IMAGE }}:${{ env.IMAGE_TAG }} || { | |
echo "Failed to start ARM64 container. This might be due to QEMU emulation issues." | |
exit 1 | |
} | |
# Wait for the container to be healthy with increased timeout | |
echo "Waiting for container to be healthy (ARM64 emulation may be slow)..." | |
for i in $(seq 1 ${{ env.ARM64_HEALTH_CHECK_TIMEOUT }}); do | |
if docker ps --filter "name=${{ env.ARM64_CONTAINER }}" --filter "health=healthy" | grep -q "${{ env.ARM64_CONTAINER }}"; then | |
echo "Container is healthy!" | |
break | |
fi | |
if [ $i -eq ${{ env.ARM64_HEALTH_CHECK_TIMEOUT }} ]; then | |
echo "Container failed to become healthy within ${{ env.ARM64_HEALTH_CHECK_TIMEOUT }} seconds" | |
echo "Container logs:" | |
docker logs ${{ env.ARM64_CONTAINER }} | |
echo "Container inspect:" | |
docker inspect ${{ env.ARM64_CONTAINER }} | |
exit 1 | |
fi | |
echo "Waiting for container to be healthy... ($i/${{ env.ARM64_HEALTH_CHECK_TIMEOUT }})" | |
sleep 1 | |
done | |
# Test the Streamlit health endpoint with retries | |
echo "Testing Streamlit health endpoint..." | |
for i in $(seq 1 3); do | |
if curl -f http://localhost:${{ env.CONTAINER_PORT }}/_stcore/health; then | |
break | |
fi | |
if [ $i -eq 3 ]; then | |
echo "Health check failed after 3 attempts" | |
docker logs ${{ env.ARM64_CONTAINER }} | |
exit 1 | |
fi | |
echo "Health check attempt $i failed, retrying..." | |
sleep 5 | |
done | |
# Test the main Streamlit endpoint with retries | |
echo "Testing main Streamlit endpoint..." | |
for i in $(seq 1 3); do | |
if curl -f http://localhost:${{ env.CONTAINER_PORT }}; then | |
break | |
fi | |
if [ $i -eq 3 ]; then | |
echo "Main endpoint check failed after 3 attempts" | |
docker logs ${{ env.ARM64_CONTAINER }} | |
exit 1 | |
fi | |
echo "Main endpoint check attempt $i failed, retrying..." | |
sleep 5 | |
done | |
# Clean up | |
docker stop ${{ env.ARM64_CONTAINER }} || true | |
docker rm ${{ env.ARM64_CONTAINER }} || true |