Skip to content

Commit

Permalink
Merge pull request #74 from mgxd/maint/0.3.3-pre
Browse files Browse the repository at this point in the history
REL: 0.4.0
  • Loading branch information
mgxd authored Mar 9, 2023
2 parents cc2463c + 2acb206 commit 3336371
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 31 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,4 @@ mounts/
# Ignore generated credentials from google-github-actions/auth
gha-creds-*.json

# Autogenerated by setuptools_scm
src/server/_version.py
_version.py
5 changes: 3 additions & 2 deletions .maint/start-server-local.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
export MIGAS_REDIS_URI='redis://localhost'
export DATABASE_URL='postgres://localhost/migas'
export MIGAS_DEBUG=1
export MIGAS_MAX_REQUESTS_PER_WINDOW=50
#export MIGAS_MAX_REQUESTS_PER_WINDOW=50
export MIGAS_BYPASS_RATE_LIMIT=1
export MIGAS_MAX_REQUEST_SIZE=3000

migas-server --reload
uvicorn migas.server.app:app --host 0.0.0.0 --port 8080 --reload --proxy-headers --header X-Backend-Server:migas
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ compose-up:

freeze:
@echo "Freezing requirements"
pip-compile --extra test -o requirements.txt pyproject.toml --upgrade
pip-compile --extra test -o stable-requirements.txt pyproject.toml --upgrade

release-gcp:
@echo "Releasing on GCP"
Expand Down
2 changes: 1 addition & 1 deletion deploy/docker/run.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash
set -e

if [ ! -f /.dockerenv ]; then
if [ ! -f /.dockerenv ] && [[ -z $GCP_SQL_CONNECTION ]]; then
echo "Error: not inside a docker container!"
exit 1
fi
Expand Down
6 changes: 6 additions & 0 deletions deploy/gcp/cloudbuild.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
steps:
- name: 'gcr.io/cloud-builders/docker'
args: ['build', '-t', 'gcr.io/$PROJECT_ID/migas-server:$TAG_NAME', '--build-arg', 'BUILDTYPE=release', '.']

images:
- 'gcr.io/$PROJECT_ID/migas-server:$TAG_NAME'
20 changes: 16 additions & 4 deletions deploy/gcp/release-gcp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ set -eux
HERE=$(dirname $(realpath $0))
ROOT=$(dirname $(dirname $HERE))

VERSION=${1-"unknown"}

# These should be available, but will be account specific
# PROJECT_ID=
Expand All @@ -28,6 +27,7 @@ SQL_INSTANCE_NAME="migas-postgres"
SQL_INSTANCE_TIER="db-g1-micro"
CLOUD_RUN_SERVICE_NAME="migas-server"
CLOUD_RUN_ENV_FILE="$HERE/.env"
CLOUD_BUILD_YAML="$HERE/cloudbuild.yml"

# Step 0: Install SDK
# https://github.com/google-github-actions/setup-gcloud
Expand All @@ -49,9 +49,20 @@ if [[ -z $SQL_EXISTS ]]; then
fi

# Step 2: Build the service image
VERSION=${1-"unknown"}
set +e
VER=$(hatch version 2> /dev/null)
if [[ "$VERSION" = "unknown" ]] && [[ -n $VER ]]; then
VERSION=$VER
fi
set -e
echo "Tagging version: $VERSION"

GCR_TAG=gcr.io/$PROJECT_ID/$CLOUD_RUN_SERVICE_NAME:$VERSION
gcloud builds submit \
--tag $GCR_TAG
# gcloud builds submit \
# --tag $GCR_TAG
gcloud builds submit --config $CLOUD_BUILD_YAML --substitutions=TAG_NAME=$VERSION


# Step 3: Deploy the service
CLOUD_SQL_INSTANCE_ID="$PROJECT_ID:$GCP_REGION:$SQL_INSTANCE_NAME"
Expand All @@ -76,8 +87,9 @@ DEPLOY_CMD="gcloud run deploy $CLOUD_RUN_SERVICE_NAME \
--set-cloudsql-instances=$CLOUD_SQL_INSTANCE_ID \
--memory=512Mi \
--cpu=2 \
--args=--port,8080,--proxy-headers,--headers,X-Backend-Server:migas \
--args=--host,0.0.0.0,--port,8080,--proxy-headers,--header,X-Backend-Server:migas \
--cpu-throttling \
--no-traffic \
$ENV_VARS"

$DEPLOY_CMD
Expand Down
4 changes: 2 additions & 2 deletions migas/server/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from fastapi import Request, Response
from graphql import ExecutionResult as GraphQLExecutionResult
from graphql import GraphQLError
from strawberry.extensions import Extension
from strawberry.extensions import SchemaExtension
from strawberry.scalars import JSON
from strawberry.schema.config import StrawberryConfig
from strawberry.types import Info
Expand Down Expand Up @@ -143,7 +143,7 @@ async def add_project(self, p: ProjectInput, info: Info) -> JSON:
}


class RateLimiter(Extension):
class RateLimiter(SchemaExtension):
"""
A GraphQL schema extension to implement sliding window rate limiting.
Expand Down
33 changes: 14 additions & 19 deletions stable-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
# This file is autogenerated by pip-compile with Python 3.10
# by the following command:
#
# pip-compile --extra=test --output-file=requirements.txt pyproject.toml
# pip-compile --extra=test --output-file=stable-requirements.txt pyproject.toml
#
aiohttp==3.8.4
# via migas_server (pyproject.toml)
# via migas-server (pyproject.toml)
aiosignal==1.3.1
# via aiohttp
anyio==3.6.2
Expand All @@ -18,7 +18,7 @@ async-timeout==4.0.2
# aiohttp
# redis
asyncpg==0.27.0
# via migas_server (pyproject.toml)
# via migas-server (pyproject.toml)
attrs==22.2.0
# via
# aiohttp
Expand All @@ -27,7 +27,7 @@ certifi==2022.12.7
# via
# httpcore
# httpx
charset-normalizer==3.0.1
charset-normalizer==3.1.0
# via aiohttp
click==8.1.3
# via uvicorn
Expand All @@ -37,9 +37,9 @@ email-validator==1.3.1
# via fastapi
exceptiongroup==1.1.0
# via pytest
fastapi[all]==0.92.0
fastapi[all]==0.93.0
# via
# migas_server (pyproject.toml)
# migas-server (pyproject.toml)
# strawberry-graphql
frozenlist==1.3.3
# via
Expand All @@ -49,8 +49,6 @@ graphql-core==3.2.3
# via strawberry-graphql
greenlet==2.0.2
# via sqlalchemy
gunicorn==20.1.0
# via migas_server (pyproject.toml)
h11==0.14.0
# via
# httpcore
Expand Down Expand Up @@ -83,14 +81,14 @@ orjson==3.8.7
# via fastapi
packaging==23.0
# via
# migas_server (pyproject.toml)
# migas-server (pyproject.toml)
# pytest
pluggy==1.0.0
# via pytest
pydantic==1.10.5
pydantic==1.10.6
# via fastapi
pytest==7.2.2
# via migas_server (pyproject.toml)
# via migas-server (pyproject.toml)
python-dateutil==2.8.2
# via strawberry-graphql
python-dotenv==1.0.0
Expand All @@ -104,7 +102,7 @@ pyyaml==6.0
# fastapi
# uvicorn
redis==4.5.1
# via migas_server (pyproject.toml)
# via migas-server (pyproject.toml)
rfc3986[idna2008]==1.5.0
# via httpx
six==1.16.0
Expand All @@ -116,12 +114,12 @@ sniffio==1.3.0
# anyio
# httpcore
# httpx
sqlalchemy[asyncio]==2.0.4
# via migas_server (pyproject.toml)
sqlalchemy[asyncio]==2.0.5.post1
# via migas-server (pyproject.toml)
starlette==0.25.0
# via fastapi
strawberry-graphql[fastapi]==0.159.0
# via migas_server (pyproject.toml)
strawberry-graphql[fastapi]==0.161.1
# via migas-server (pyproject.toml)
tomli==2.0.1
# via pytest
typing-extensions==4.5.0
Expand All @@ -141,6 +139,3 @@ websockets==10.4
# via uvicorn
yarl==1.8.2
# via aiohttp

# The following packages are considered to be unsafe in a requirements file:
# setuptools

0 comments on commit 3336371

Please sign in to comment.