Skip to content

Commit

Permalink
Undo APIFlask.
Browse files Browse the repository at this point in the history
  • Loading branch information
anybodys committed May 27, 2024
1 parent 62203d1 commit d0cdd21
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 204 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cd.infra.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
push:
paths:
- infra/**
- .github/workflows/ci.infra.yaml
- .github/workflows/cd.infra.yaml
branches:
- main

Expand Down
6 changes: 3 additions & 3 deletions infra/app/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ locals {
image_base = "${var.region}-docker.pkg.dev/${var.project}/${var.project}/"
client_tag = var.app_versions["client"]
client_image = "${local.image_base}client:${local.client_tag}"
painter_image = "${local.image_base}painter_api:${var.app_versions["painter_api"]}"
voting_tag = var.app_versions["voting_api"]
voting_image = "${local.image_base}voting_api:${local.voting_tag}"
painter_image = "${local.image_base}painterapi:${var.app_versions["painterapi"]}"
voting_tag = var.app_versions["votingapi"]
voting_image = "${local.image_base}votingapi:${local.voting_tag}"
}
4 changes: 2 additions & 2 deletions infra/app/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ variable "app_versions" {
type = map(string)
default = {
client : "0.1.0",
voting_api : "0.1.1",
painter_api : "0.1.0",
votingapi : "0.1.1",
painterapi : "0.1.0",
}

}
Expand Down
6 changes: 2 additions & 4 deletions voting_api/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
setup:
pip install --upgrade --user pipenv
pipenv install --dev

generate-openapi:
pipenv run flask --app voting.api spec
npm install -g api-spec-converter

run: run-api

Expand All @@ -19,7 +17,7 @@ testcase:
PIPENV_DOTENV_LOCATION=.env.test pipenv run pytest ${TESTS}

deploy:
gcloud run deploy --source . voting_api
gcloud run deploy --source . votingapi

clean:
find . -name '*~' -delete
Expand Down
1 change: 0 additions & 1 deletion voting_api/Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ name = "pypi"
flask = "*"
google-cloud-storage = "*"
gunicorn = "*"
apiflask = {extras = ["yaml"], version = "*"}

[dev-packages]
pytest = "*"
Expand Down
230 changes: 66 additions & 164 deletions voting_api/Pipfile.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions voting_api/service.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
name: voting-api
name: votingapi
spec:
template:
metadata:
name: ${REVISION_NAME}
name: ${IMAGE}
spec:
containers:
- image: ${IMAGE}
2 changes: 1 addition & 1 deletion voting_api/tests/test_api.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
def test_get_health(client):
response = client.get('/health')
assert b'OK' == response.data
assert 'OK' == response.json['status']
assert 200 == response.status_code
33 changes: 7 additions & 26 deletions voting_api/voting/api.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,20 @@
from pathlib import Path

from apiflask import APIFlask
from flask import jsonify, request
from flask import Flask jsonify, request

from voting.model import art
from voting.storage import art_storage


def create_app():
app = APIFlask(__name__, title='Artist 2D Voting API', spec_path='/openapi.yaml')
app = Flask(__name__)
return app


app = create_app()
app.config.update({
'AUTO_SERVERS': False,
'LOCAL_SPEC_PATH': Path(app.root_path) / 'openapi.yaml',
'OPENAPI_VERSION': '2.0',
'SPEC_FORMAT': 'yaml',
'SYNC_LOCAL_SPEC': True,
})


@app.spec_processor
def google_endpoints_spec(spec):
spec['host'] = 'gateway-c24bw3cnyq-wl.a.run.app'
spec['x-google-backend'] = {
'address': 'voting-api',
'protocol': 'h2',
}
return spec


@app.get("/health")


@app.route("/health")
def health_check():
return 'OK'
return jsonify({'status': 'OK'})


@app.get("/art")
Expand Down

0 comments on commit d0cdd21

Please sign in to comment.