|
| 1 | +name: Scapyd-k8s CI |
| 2 | +on: |
| 3 | + push: |
| 4 | + branches: |
| 5 | + - main |
| 6 | + pull_request: |
| 7 | + |
| 8 | +jobs: |
| 9 | + test-unit: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + steps: |
| 12 | + - name: Checkout |
| 13 | + uses: actions/checkout@v4 |
| 14 | + |
| 15 | + - name: Set up Python |
| 16 | + uses: actions/setup-python@v4 |
| 17 | + with: |
| 18 | + python-version: 3.11 |
| 19 | + cache: 'pip' |
| 20 | + |
| 21 | + - name: Install dependencies |
| 22 | + run: | |
| 23 | + pip install -r requirements.txt |
| 24 | + pip install -r requirements-test.txt |
| 25 | + |
| 26 | + - name: Run tests |
| 27 | + run: pytest -vv --color=yes scrapyd_k8s/tests/unit/ |
| 28 | + |
| 29 | + test-docker: |
| 30 | + runs-on: ubuntu-latest |
| 31 | + steps: |
| 32 | + - name: Checkout |
| 33 | + uses: actions/checkout@v4 |
| 34 | + |
| 35 | + - name: Set up Python |
| 36 | + uses: actions/setup-python@v4 |
| 37 | + with: |
| 38 | + python-version: 3.11 |
| 39 | + cache: 'pip' |
| 40 | + |
| 41 | + - name: Install dependencies |
| 42 | + run: | |
| 43 | + pip install -r requirements.txt |
| 44 | + pip install -r requirements-test.txt |
| 45 | +
|
| 46 | + - name: Pull example spider |
| 47 | + run: docker pull ghcr.io/q-m/scrapyd-k8s-spider-example |
| 48 | + |
| 49 | + - name: Run scrapyd-k8s |
| 50 | + run: | |
| 51 | + cp scrapyd_k8s.sample-docker.conf scrapyd_k8s.conf |
| 52 | + python -m scrapyd_k8s & |
| 53 | + while ! nc -q 1 localhost 6800 </dev/null; do sleep 1; done |
| 54 | + curl http://localhost:6800/daemonstatus.json |
| 55 | +
|
| 56 | + - name: Run tests |
| 57 | + run: pytest -vv --color=yes scrapyd_k8s/tests/integration/ |
| 58 | + |
| 59 | + test-manifest: |
| 60 | + container: |
| 61 | + runs-on: ubuntu-latest |
| 62 | + steps: |
| 63 | + - name: Checkout |
| 64 | + uses: actions/checkout@v4 |
| 65 | + |
| 66 | + - name: Set up Python |
| 67 | + uses: actions/setup-python@v4 |
| 68 | + with: |
| 69 | + python-version: 3.11 |
| 70 | + cache: 'pip' |
| 71 | + |
| 72 | + - name: Install dependencies |
| 73 | + run: | |
| 74 | + pip install -r requirements.txt |
| 75 | + pip install -r requirements-test.txt |
| 76 | +
|
| 77 | + - name: Set up Docker Buildx |
| 78 | + uses: docker/setup-buildx-action@v3 |
| 79 | + |
| 80 | + - name: Build container |
| 81 | + uses: docker/build-push-action@v5 |
| 82 | + with: |
| 83 | + context: . |
| 84 | + push: false |
| 85 | + load: true |
| 86 | + tags: test:latest |
| 87 | + cache-from: type=gha |
| 88 | + cache-to: type=gha,mode=max |
| 89 | + |
| 90 | + - name: Start minikube |
| 91 | + uses: medyagh/setup-minikube@master |
| 92 | + |
| 93 | + - name: Deploy to minikube |
| 94 | + run: | |
| 95 | + minikube image load test:latest |
| 96 | + # already pull image so we don't have to wait for it later |
| 97 | + minikube image pull ghcr.io/q-m/scrapyd-k8s-spider-example:latest |
| 98 | + # load manifest |
| 99 | + sed -i 's/\(imagePullPolicy:\s*\)\w\+/\1Never/' kubernetes.yaml |
| 100 | + sed -i 's/\(image:\s*\)ghcr\.io\/q-m\/scrapyd-k8s:/\1test:/' kubernetes.yaml |
| 101 | + sed -i 's/\(type:\s*\)ClusterIP/\1NodePort/' kubernetes.yaml |
| 102 | + kubectl create -f kubernetes.yaml |
| 103 | + # and wait for scrapyd-k8s to become ready |
| 104 | + kubectl wait --for=condition=Available deploy/scrapyd-k8s --timeout=60s |
| 105 | + curl --retry 10 --retry-delay 2 --retry-all-errors `minikube service scrapyd-k8s --url`/daemonstatus.json |
| 106 | +
|
| 107 | + - name: Run tests |
| 108 | + run: | |
| 109 | + TEST_WITH_K8S=1 \ |
| 110 | + TEST_BASE_URL=`minikube service scrapyd-k8s --url` \ |
| 111 | + TEST_MAX_WAIT=60 \ |
| 112 | + TEST_AVAILABLE_VERSIONS=latest,`skopeo list-tags docker://ghcr.io/q-m/scrapyd-k8s-spider-example | jq -r '.Tags | map(select(. != "latest" and (startswith("sha-") | not))) | join(",")'` \ |
| 113 | + pytest -vv --color=yes scrapyd_k8s/tests/integration/ |
| 114 | + test-k8s: |
| 115 | + container: |
| 116 | + runs-on: ubuntu-latest |
| 117 | + steps: |
| 118 | + - name: Checkout |
| 119 | + uses: actions/checkout@v4 |
| 120 | + |
| 121 | + - name: Set up Python |
| 122 | + uses: actions/setup-python@v4 |
| 123 | + with: |
| 124 | + python-version: 3.11 |
| 125 | + cache: 'pip' |
| 126 | + |
| 127 | + - name: Install dependencies |
| 128 | + run: | |
| 129 | + pip install -r requirements.txt |
| 130 | + pip install -r requirements-test.txt |
| 131 | +
|
| 132 | + - name: Start minikube |
| 133 | + uses: medyagh/setup-minikube@master |
| 134 | + |
| 135 | + - name: Prepare Kubernetes environment |
| 136 | + run: | |
| 137 | + kubectl create secret generic example-env-secret --from-literal=FOO_1=bar |
| 138 | + kubectl create configmap example-env-configmap --from-literal=FOO_2=baz |
| 139 | + # already pull image so we don't have to wait for it later |
| 140 | + minikube image pull ghcr.io/q-m/scrapyd-k8s-spider-example:latest |
| 141 | +
|
| 142 | + - name: Run scrapyd-k8s |
| 143 | + run: | |
| 144 | + cp scrapyd_k8s.sample-k8s.conf scrapyd_k8s.conf |
| 145 | + python -m scrapyd_k8s & |
| 146 | + while ! nc -q 1 localhost 6800 </dev/null; do sleep 1; done |
| 147 | + curl http://localhost:6800/daemonstatus.json |
| 148 | +
|
| 149 | + - name: Run tests |
| 150 | + run: | |
| 151 | + TEST_WITH_K8S=1 \ |
| 152 | + TEST_MAX_WAIT=60 \ |
| 153 | + TEST_AVAILABLE_VERSIONS=latest,`skopeo list-tags docker://ghcr.io/q-m/scrapyd-k8s-spider-example | jq -r '.Tags | map(select(. != "latest" and (startswith("sha-") | not))) | join(",")'` \ |
| 154 | + pytest -vv --color=yes scrapyd_k8s/tests/integration/ |
0 commit comments