Skip to content

debug docker container running #2

debug docker container running

debug docker container running #2

name: test latest docker image (dev) # TODO: change
on:
push:
branches:
- 529_add_docker_testing_action_gcroci2 # TODO: change
jobs:
test_latest_docker_image:
runs-on: ubuntu-22.04
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Pull latest Docker image
run: |
REPO_LOWERCASE=$(echo "${{ github.repository }}" | tr '[:upper:]' '[:lower:]')
docker pull ghcr.io/$REPO_LOWERCASE:latest
- name: Run tests in Docker container
run: |
REPO_LOWERCASE=$(echo "${{ github.repository }}" | tr '[:upper:]' '[:lower:]')
docker run --name test_container -d ghcr.io/$REPO_LOWERCASE:latest tail -f /dev/null
# Inspect container filesystem
echo "Container filesystem structure:"
docker exec test_container ls -R /
# Determine the appropriate directory for tests
if docker exec test_container [ -d "/app" ]; then
TEST_DIR="/app/tests"
elif docker exec test_container [ -d "/usr/src/app" ]; then
TEST_DIR="/usr/src/app/tests"
else
TEST_DIR="/tests"
fi
echo "Using test directory: $TEST_DIR"
# Copy tests to the container
docker cp tests test_container:$TEST_DIR
# Install pytest and run tests
docker exec test_container pip install pytest
docker exec -e PYTHONPATH=$TEST_DIR test_container pytest $TEST_DIR
# Clean up
docker stop test_container
docker rm test_container
- name: Output test results
if: failure()
run: |
echo "Tests failed. Please check the test output above for more details."