Skip to content

Commit

Permalink
chore: release new serverless gateway integration 🎉 (#117)
Browse files Browse the repository at this point in the history
* chore: update for gateway CLI changes

* docs: fix typo changelog

* chore: poetry lock

* fix(ci): update workflow for scwgw changes

* fix(test): get-endpoint deprecated

* docs: typo in variable name

* docs: link to readthedocs docs
  • Loading branch information
cyclimse authored Jul 4, 2023
1 parent c7d33cb commit ec5fd5e
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 32 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/integration-gateway.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- uses: ./.github/actions/setup-poetry

- name: Deploy Serverless Gateway
run: poetry run scwgw deploy
run: poetry run scwgw infra deploy
env:
SCW_DEFAULT_ORGANIZATION_ID: ${{ secrets.SCW_DEFAULT_ORGANIZATION_ID }}
SCW_DEFAULT_PROJECT_ID: ${{ secrets.SCW_DEFAULT_PROJECT_ID }}
Expand All @@ -41,7 +41,7 @@ jobs:
- name: Run integration tests
working-directory: tests
run: |
poetry run scwgw remote-config
poetry run scwgw infra config
poetry run pytest integrations/gateway -n $(nproc --all)
env:
SCW_DEFAULT_ORGANIZATION_ID: ${{ secrets.SCW_DEFAULT_ORGANIZATION_ID }}
Expand All @@ -64,7 +64,7 @@ jobs:
- uses: ./.github/actions/setup-poetry

- name: Delete Serverless Gateway
run: poetry run scwgw delete -y
run: poetry run scwgw infra delete -y
env:
SCW_DEFAULT_ORGANIZATION_ID: ${{ secrets.SCW_DEFAULT_ORGANIZATION_ID }}
SCW_DEFAULT_PROJECT_ID: ${{ secrets.SCW_DEFAULT_PROJECT_ID }}
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Removed

- Removed generating Terraform and Serverless Framework configuration files as those features were mostly unused. This does not break the `scw-serverless` library but it removes a command from the CLI. We think those changes will help improve the overall quality of the tool.

## [1.2.0] - 2023-07-03

### Feature

- Changed the gateway integration to work with latest release of the Serverless Gateway project
29 changes: 17 additions & 12 deletions docs/source/gateway.rst
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
API Gateway
===========

The framework provides support for routed functions via a Gateway container that can be deployed separately.
For more information, please consult the documentation on the `Serverless Gateway repository`_
The framework provides support for routed functions via the Serverless Gateway project that can be deployed separately.
For more information, please consult the `Serverless Gateway Documentation`_ or the `Serverless Gateway Repository`_.

Quickstart
^^^^^^^^^^
Expand All @@ -15,31 +15,36 @@ Quickstart
app = Serverless("example")
app.get("/hello-gateway", memory_limit= 256)
# You can use the get, post, put, and delete decorators
@app.get("/hello-gateway", memory_limit= 256)
def handler(event, context):
return {"body": "Hello from Gateway!"}
* Clone the `Serverless Gateway repository`_
* Follow the steps in README to deploy your API Gateway
* Create an API token for the Gateway. In the gateway repository, you can use a make command:
* Install the `scwgw` helper tool

.. code-block:: console
make generate-token
export TOKEN=$(make get-token)
export GATEWAY_HOST=$(make gateway-host)
pip install scw-gateway
* Finally, use `scw-serverless` to deploy your function and set up the route on your Gateway:
* Deploy your API Gateway

.. code-block:: console
scw-serverless deploy app.py --gateway-url https://${GATEWAY_HOST} --gateway-api-key ${TOKEN}
scwgw infra deploy
* Finally, use `scw-serverless` to deploy your function and set up the route on your gateway:

.. code-block:: console
scw-serverless deploy app.py
* You can now call your function via your Gateway!

.. code-block:: console
$ curl https://${GATEWAY_HOST}/hello-gateway
$ GATEWAY_ENDPOINT=$(scwgw infra endpoint)
$ curl https://${GATEWAY_ENDPOINT}/hello-gateway
> Hello from Gateway!
.. _Serverless Gateway Repository: https://github.com/scaleway/serverless-gateway
.. _Serverless Gateway Documentation: https://serverless-gateway.readthedocs.io/en/latest/
20 changes: 10 additions & 10 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "scw-serverless"
version = "1.1.0"
version = "1.2.0"
description = "Framework for writing serverless APIs in Python, using Scaleway functions and containers."
authors = ["Scaleway Serverless Team <[email protected]>"]
readme = "README.md"
Expand Down Expand Up @@ -47,7 +47,7 @@ pytest-xdist = "^3.1.0"
pylint = "^2.15.10"
pylint-per-file-ignores = "^1.1.0"
responses = ">=0.22,<0.24"
scw-gateway = "^0.3.0"
scw-gateway = "^0.4.0"

[tool.poetry.group.doc]
optional = true
Expand Down
10 changes: 6 additions & 4 deletions scw_serverless/gateway/serverless_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from scw_serverless.config.route import GatewayRoute

GATEWAY_CLI = "scwgw"
GATEWAY_PYPI = "scw-gateway"


class ServerlessGateway:
Expand All @@ -18,11 +19,12 @@ def __init__(self) -> None:

if not cli:
click.secho(
"scwgw was not found in $PATH, "
+ "you can install scwgw by running: pip install scwgw",
f"{GATEWAY_CLI} was not found in $PATH, "
+ f"you can install {GATEWAY_CLI} by running:\n"
+ f"pip install {GATEWAY_PYPI}",
fg="red",
)
raise RuntimeError("scwgw is not installed")
raise RuntimeError(f"{GATEWAY_CLI} is not installed")

self.cli = cli

Expand All @@ -41,7 +43,7 @@ def add_route(self, route: GatewayRoute) -> None:
if not route.target:
raise RuntimeError(f"route {route.relative_url} is missing upstream target")

cli_args = ["add-route", route.relative_url, route.target]
cli_args = ["route", "add", route.relative_url, route.target]
for method in route.http_methods or []:
cli_args += ["--http-methods", method.value]

Expand Down
2 changes: 1 addition & 1 deletion tests/integrations/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def get_deployed_functions_by_name(client: Client, app_instance: Serverless):

def get_gateway_endpoint() -> str:
cmd = subprocess.run(
args=["scwgw", "get-endpoint"],
args=["scwgw", "infra", "endpoint"],
check=True,
capture_output=True,
env=os.environ,
Expand Down

0 comments on commit ec5fd5e

Please sign in to comment.