|
| 1 | +# This workflow will run the integration tests for the project |
| 2 | +name: Tests - Integration |
| 3 | + |
| 4 | +on: |
| 5 | + workflow_call: |
| 6 | + inputs: |
| 7 | + artifact-name: |
| 8 | + description: 'The name of the artifact to download' |
| 9 | + required: true |
| 10 | + type: string |
| 11 | + secrets: |
| 12 | + copilot-key: |
| 13 | + description: 'The Copilot key to use for integration tests' |
| 14 | + required: true |
| 15 | + |
| 16 | +jobs: |
| 17 | + integration-tests: |
| 18 | + name: Run |
| 19 | + runs-on: ubuntu-latest |
| 20 | + strategy: |
| 21 | + matrix: |
| 22 | + python-version: [ "3.12" ] |
| 23 | + env: |
| 24 | + CONTAINER_NAME: "codegate" |
| 25 | + CERT_FILE: "/app/codegate_volume/certs/ca.crt" |
| 26 | + steps: |
| 27 | + - name: Checkout |
| 28 | + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 |
| 29 | + with: |
| 30 | + lfs: true |
| 31 | + |
| 32 | + - name: Ensure file permissions for mounted volume |
| 33 | + run: | |
| 34 | + mkdir -p ./codegate_volume/certs ./codegate_volume/models ./codegate_volume/db |
| 35 | + chmod -R 777 ./codegate_volume |
| 36 | +
|
| 37 | + - name: Download Docker image artifact |
| 38 | + uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4 |
| 39 | + with: |
| 40 | + name: ${{ inputs.artifact-name }} |
| 41 | + |
| 42 | + - name: Load Docker image |
| 43 | + run: | |
| 44 | + docker load -i image.tar |
| 45 | + echo "Loaded image:" |
| 46 | + docker images |
| 47 | +
|
| 48 | + - name: Run container from the loaded image |
| 49 | + run: | |
| 50 | + # Get the image name |
| 51 | + DOCKER_IMAGE=$(docker images --format "{{.Repository}}:{{.Tag}}" | head -n 1) |
| 52 | + echo "Running container from image: $DOCKER_IMAGE" |
| 53 | +
|
| 54 | + # Run the container |
| 55 | + docker run --name $CONTAINER_NAME -d -p 8989:8989 -p 9090:9090 \ |
| 56 | + -p 8990:8990 \ |
| 57 | + -v "$(pwd)"/codegate_volume:/app/codegate_volume \ |
| 58 | + -e CODEGATE_APP_LOG_LEVEL=DEBUG \ |
| 59 | + --restart unless-stopped $DOCKER_IMAGE |
| 60 | +
|
| 61 | + # Confirm the container started |
| 62 | + echo "Container started:" |
| 63 | + docker ps |
| 64 | +
|
| 65 | + # Verify container is running with correct ports |
| 66 | + docker ps -f name=$CONTAINER_NAME |
| 67 | +
|
| 68 | + # Check mount configuration |
| 69 | + docker inspect $CONTAINER_NAME -f '{{ json .Mounts }}' | jq |
| 70 | +
|
| 71 | + - name: Ensure certificates are available in the container |
| 72 | + timeout-minutes: 4 |
| 73 | + run: | |
| 74 | + # Wait for the cert file to be available in the container |
| 75 | + while true; do |
| 76 | + echo "Checking for $CERT_FILE in container $CONTAINER_NAME..." |
| 77 | +
|
| 78 | + if docker exec "$CONTAINER_NAME" test -f "$CERT_FILE"; then |
| 79 | + echo "Cert file found: $CERT_FILE" |
| 80 | + break |
| 81 | + else |
| 82 | + echo "Cert file not found. Retrying in 5 seconds..." |
| 83 | + sleep 5 |
| 84 | + fi |
| 85 | + done |
| 86 | +
|
| 87 | + # Verify volume contents are accessible |
| 88 | + docker exec $CONTAINER_NAME ls -la /app/codegate_volume |
| 89 | +
|
| 90 | + # Print the container logs we got so far |
| 91 | + docker logs $CONTAINER_NAME |
| 92 | +
|
| 93 | + - name: Install the CodeGate certificate |
| 94 | + run: | |
| 95 | + docker cp codegate:/app/codegate_volume/certs/ca.crt ./codegate.crt |
| 96 | + sudo cp ./codegate.crt /usr/local/share/ca-certificates/codegate.crt |
| 97 | + sudo update-ca-certificates |
| 98 | +
|
| 99 | + - name: Set up Python ${{ matrix.python-version }} |
| 100 | + uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5 |
| 101 | + with: |
| 102 | + python-version: ${{ matrix.python-version }} |
| 103 | + |
| 104 | + - name: Install Poetry |
| 105 | + uses: snok/install-poetry@76e04a911780d5b312d89783f7b1cd627778900a # v1 |
| 106 | + with: |
| 107 | + version: 2.0.1 |
| 108 | + virtualenvs-create: true |
| 109 | + virtualenvs-in-project: true |
| 110 | + |
| 111 | + - name: Load cached venv |
| 112 | + id: cached-poetry-dependencies |
| 113 | + uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 # v4 |
| 114 | + with: |
| 115 | + path: .venv |
| 116 | + key: venv-${{ runner.os }}-${{ matrix.python-version }}-${{ hashFiles('**/poetry.lock') }} |
| 117 | + |
| 118 | + - name: Install dependencies |
| 119 | + run: poetry install --with dev |
| 120 | + |
| 121 | + - name: Run integration tests - Copilot |
| 122 | + env: |
| 123 | + CODEGATE_PROVIDERS: "copilot" |
| 124 | + CA_CERT_FILE: "/home/runner/work/codegate/codegate/codegate_volume/certs/ca.crt" |
| 125 | + ENV_COPILOT_KEY: ${{ secrets.copilot-key }} |
| 126 | + run: | |
| 127 | + poetry run python tests/integration/integration_tests.py |
| 128 | +
|
| 129 | + - name: Print the container logs (useful for debugging) |
| 130 | + if: always() |
| 131 | + run: | |
| 132 | + docker logs $CONTAINER_NAME |
| 133 | + echo "Models contents:" |
| 134 | + ls -la codegate_volume/models |
| 135 | + docker exec $CONTAINER_NAME ls -la /app/codegate_volume/models |
| 136 | + echo "Certs contents:" |
| 137 | + ls -la codegate_volume/certs |
| 138 | + docker exec $CONTAINER_NAME ls -la /app/codegate_volume/certs |
| 139 | + echo "DB contents:" |
| 140 | + ls -la codegate_volume/db |
| 141 | + docker exec $CONTAINER_NAME ls -la /app/codegate_volume/db |
0 commit comments