Skip to content

Commit a07a3aa

Browse files
committed
chore: use different workflow for gateway ci
1 parent 8f0542d commit a07a3aa

File tree

6 files changed

+85
-88
lines changed

6 files changed

+85
-88
lines changed
Lines changed: 70 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,89 @@
1-
---
2-
name: API Gateway integration tests with Pytest
1+
name: test with deployed gateway
32

43
on:
54
push:
65
branches: [main]
76
pull_request:
87
branches: [main]
8+
types: [opened, synchronize, reopened, ready_for_review]
99

1010
permissions:
1111
contents: read
1212

13+
env:
14+
GATEWAY_CHECKOUT_DIR: "gateway"
15+
S3_ENDPOINT: "https://s3.fr-par.scw.cloud"
16+
S3_REGION: "fr-par"
17+
1318
jobs:
14-
integration-gateway:
15-
runs-on: self-hosted
16-
container: nikolaik/python-nodejs:python3.10-nodejs18
19+
test-deployed-gateway:
20+
runs-on: ubuntu-latest
1721
steps:
1822
- uses: actions/checkout@v3
1923

2024
- uses: ./.github/actions/setup-poetry
2125

22-
- name: Test with pytest
23-
working-directory: tests
24-
run: poetry run pytest integrations/gateway -n $(nproc --all)
26+
- uses: actions/checkout@v3
27+
with:
28+
repository: scaleway/serverless-gateway
29+
path: $GATEWAY_CHECKOUT_DIR
30+
31+
- name: Install Scaleway CLI
32+
uses: ./$GATEWAY_CHECKOUT_DIR/.github/actions/setup-scaleway-cli
33+
with:
34+
scw-version: "2.13.0"
35+
scw-access-key: ${{ secrets.SCW_ACCESS_KEY }}
36+
scw-secret-key: ${{ secrets.SCW_SECRET_KEY }}
37+
scw-default-project-id: ${{ secrets.SCW_DEFAULT_PROJECT_ID }}
38+
scw-default-organization-id: ${{ secrets.SCW_DEFAULT_ORGANIZATION_ID }}
39+
40+
- name: Create Gateway namespace
41+
working-directory: $GATEWAY_CHECKOUT_DIR
42+
run: |
43+
make create-namespace
44+
until [ $(make check-namespace -s) == ready ]; do sleep 10; done
45+
46+
- name: Create Gateway container
47+
working-directory: $GATEWAY_CHECKOUT_DIR
48+
# We need to truncate gateway.env as it will override our env vars
49+
run: |
50+
truncate -s 0 gateway.env
51+
make create-container
52+
make deploy-container
53+
until [ $(make check-container -s) == ready ]; do sleep 10; done
2554
env:
26-
SCW_DEFAULT_ORGANIZATION_ID: ${{ secrets.SCW_DEFAULT_ORGANIZATION_ID }}
55+
SCW_ACCESS_KEY: ${{ secrets.SCW_ACCESS_KEY }}
2756
SCW_SECRET_KEY: ${{ secrets.SCW_SECRET_KEY }}
57+
S3_BUCKET_NAME: ${{ secrets.S3_BUCKET_NAME }}
58+
59+
- name: Install s3cmd
60+
run: pip install s3cmd
61+
62+
- name: Create S3 bucket
63+
working-directory: $GATEWAY_CHECKOUT_DIR
64+
run: |
65+
make set-up-s3-cli
66+
make create-s3-bucket
67+
env:
68+
S3_BUCKET_NAME: ${{ secrets.S3_BUCKET_NAME }}
69+
70+
- name: Run integration tests
71+
run: |
72+
pushd $GATEWAY_CHECKOUT_DIR
73+
export GATEWAY_HOST=$(make get-gateway-host -s)
74+
popd
75+
poetry run pytest integrations/gateway -n $(nproc --all)
76+
env:
2877
SCW_ACCESS_KEY: ${{ secrets.SCW_ACCESS_KEY }}
29-
API_GATEWAY_S3_BUCKET: ${{ secrets.API_GATEWAY_S3_BUCKET }}
78+
SCW_SECRET_KEY: ${{ secrets.SCW_SECRET_KEY }}
79+
GATEWAY_S3_BUCKET_NAME: ${{ secrets.S3_BUCKET_NAME }}
80+
81+
- name: Delete S3 bucket
82+
run: make delete-bucket
83+
env:
84+
S3_BUCKET_NAME: ${{ secrets.S3_BUCKET_NAME }}
85+
if: always()
86+
87+
- name: Delete Gateway namespace and container
88+
run: make delete-namespace
89+
if: always()

.github/workflows/pytest-integration.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ on:
55
push:
66
branches: [main]
77
pull_request:
8-
branches: [main]
8+
types: [opened, synchronize, reopened, ready_for_review]
99

1010
permissions:
1111
contents: read

.github/workflows/pytest.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ on:
66
branches: [main]
77
pull_request:
88
branches: [main]
9+
types: [opened, synchronize, reopened, ready_for_review]
910

1011
permissions:
1112
contents: read

tests/constants.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,10 @@
99

1010
COLD_START_TIMEOUT = 20
1111

12-
API_GATEWAY_IMAGE_TAG = "0.0.5"
13-
API_GATEWAY_IMAGE = (
14-
f"registry.hub.docker.com/shillakerscw/scw-sls-gw:{API_GATEWAY_IMAGE_TAG}"
15-
)
16-
API_GATEWAY_MEMORY_LIMIT = 2048
17-
API_GATEWAY_S3_REGION = REGION_FR_PAR
18-
API_GATEWAY_S3_BUCKET_ENDPOINT = f"https://s3.{REGION_FR_PAR}.scw.cloud"
19-
API_GATEWAY_S3_BUCKET = os.getenv("API_GATEWAY_S3_BUCKET")
12+
GATEWAY_HOST = os.getenv("GATEWAY_HOST")
13+
GATEWAY_S3_REGION = REGION_FR_PAR
14+
GATEWAY_S3_BUCKET_ENDPOINT = f"https://s3.{REGION_FR_PAR}.scw.cloud"
15+
GATEWAY_S3_BUCKET_NAME = os.getenv("GATEWAY_S3_BUCKET")
2016

2117
TESTS_DIR = os.path.realpath(os.path.dirname(__file__))
2218

tests/integrations/gateway/test_gateway.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,19 @@
11
# pylint: disable=unused-import,redefined-outer-name # fixture
22
import requests
3-
from scaleway.container.v1beta1 import Container
43

54
from tests import constants
65
from tests.app_fixtures.routed_functions import MESSAGES
76
from tests.integrations.deploy_wrapper import run_deploy_command
8-
from tests.integrations.gateway_fixtures import api_gateway, auth_key # noqa
7+
from tests.integrations.gateway_fixtures import auth_key # noqa
98
from tests.integrations.project_fixture import scaleway_project # noqa
109
from tests.integrations.utils import create_client
1110

1211

13-
def test_integration_gateway(
14-
scaleway_project: str, api_gateway: Container, auth_key: str # noqa
15-
):
12+
def test_integration_gateway(scaleway_project: str, auth_key: str): # noqa
1613
client = create_client()
1714
client.default_project_id = scaleway_project
1815

19-
gateway_url = f"https://{api_gateway.domain_name}"
16+
gateway_url = f"https://{constants.GATEWAY_HOST}"
2017

2118
run_deploy_command(
2219
client,
Lines changed: 6 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,93 +1,36 @@
1-
import typing as t
2-
31
import boto3
42
import pytest
53
import requests
6-
import scaleway.container.v1beta1 as sdk
7-
from scaleway import Client
84

95
from tests import constants
106

117
from .utils import create_client
128

139

1410
@pytest.fixture()
15-
def api_gateway(scaleway_project: str) -> t.Iterator[sdk.Container]:
16-
client = create_client()
17-
container = None
18-
try:
19-
container = _deploy_gateway(scaleway_project, client)
20-
yield container
21-
finally:
22-
if container:
23-
_cleanup_gateway(client, container)
24-
11+
def auth_key() -> str:
12+
assert constants.GATEWAY_HOST, "Gateway needs to be configured."
2513

26-
@pytest.fixture()
27-
def auth_key(
28-
api_gateway: sdk.Container, # pylint: disable=redefined-outer-name
29-
) -> str:
3014
client = create_client()
3115

3216
response = requests.post(
33-
"https://" + api_gateway.domain_name + "/token",
17+
"https://" + constants.GATEWAY_HOST + "/token",
3418
timeout=constants.COLD_START_TIMEOUT,
3519
)
3620
response.raise_for_status()
3721

3822
s3 = boto3.resource(
3923
"s3",
40-
region_name=constants.API_GATEWAY_S3_BUCKET,
41-
endpoint_url=constants.API_GATEWAY_S3_BUCKET_ENDPOINT,
24+
region_name=constants.GATEWAY_S3_BUCKET_NAME,
25+
endpoint_url=constants.GATEWAY_S3_BUCKET_ENDPOINT,
4226
aws_access_key_id=client.access_key,
4327
aws_secret_access_key=client.secret_key,
4428
)
4529

4630
objects = sorted(
47-
s3.Bucket(constants.API_GATEWAY_S3_BUCKET).objects.all(), # type: ignore
31+
s3.Bucket(constants.GATEWAY_S3_BUCKET_NAME).objects.all(), # type: ignore
4832
key=lambda obj: obj.last_modified,
4933
reverse=True,
5034
)
5135
key = objects[0].key
5236
return key
53-
54-
55-
def _deploy_gateway(project_id: str, client: Client) -> sdk.Container:
56-
assert (
57-
constants.API_GATEWAY_S3_BUCKET
58-
), "S3 bucket needs to be configured to deploy Gateway"
59-
60-
api = sdk.ContainerV1Beta1API(client)
61-
namespace = api.create_namespace(name="gateway", project_id=project_id)
62-
api.wait_for_namespace(namespace_id=namespace.id)
63-
64-
container = api.create_container(
65-
namespace_id=namespace.id,
66-
min_scale=1,
67-
max_scale=1,
68-
protocol=sdk.ContainerProtocol.HTTP1,
69-
registry_image=constants.API_GATEWAY_IMAGE,
70-
privacy=sdk.ContainerPrivacy.PUBLIC,
71-
http_option=sdk.ContainerHttpOption.REDIRECTED,
72-
memory_limit=constants.API_GATEWAY_MEMORY_LIMIT,
73-
secret_environment_variables=[
74-
sdk.Secret("SCW_ACCESS_KEY", client.access_key),
75-
sdk.Secret("SCW_SECRET_KEY", client.secret_key),
76-
],
77-
environment_variables={
78-
"S3_REGION": constants.API_GATEWAY_S3_REGION,
79-
"S3_ENDPOINT": constants.API_GATEWAY_S3_BUCKET_ENDPOINT,
80-
"S3_BUCKET_NAME": constants.API_GATEWAY_S3_BUCKET,
81-
},
82-
)
83-
api.deploy_container(container_id=container.id)
84-
container = api.wait_for_container(container_id=container.id)
85-
86-
return container
87-
88-
89-
def _cleanup_gateway(client: Client, container: sdk.Container):
90-
"""Delete all Scaleway resources created in the temporary project."""
91-
api = sdk.ContainerV1Beta1API(client)
92-
api.delete_container(container_id=container.id)
93-
api.delete_namespace(namespace_id=container.namespace_id)

0 commit comments

Comments
 (0)