Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/52 create api gateway #53

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ env:
REGION: us-central1
jobs:
deploy:
name: Deploy
name: Deploy Containerized App
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -24,3 +24,7 @@ jobs:
run: docker push ${{ secrets.CONTAINER_IMAGE_URL }}
- name: Deploy Container to Google Cloud Run
run: gcloud run deploy imaginate-api --image ${{ secrets.CONTAINER_IMAGE_URL }} --region ${{ env.REGION }}
- name: Add API Url to API Spec
run: python scripts/add_api_url.py openapi.yml ${{ secrets.API_URL }}
- name: Create and Deploy API-Config
run: gcloud api-gateway api-configs create api-config --api=api --openapi-spec=openapi.yml
4 changes: 1 addition & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,4 @@ RUN pip install poetry==1.8.4
WORKDIR /api
COPY . .
RUN poetry install --without dev --sync
CMD ["poetry","run","python", "imaginate_api/app.py"]


CMD ["poetry","run","python", "imaginate_api/app.py"]
39 changes: 39 additions & 0 deletions openapi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
swagger: "2.0"
info:
title: api
version: 1.0.0
schemes:
- https
produces:
- application/json/
securityDefinitions:
BasicAuth:
type: basic
paths:
/date/{day}/images:
get:
operationId: getImagesForDay
summary: Get images for a specific date
parameters:
- name: day
in: path
description: The day as a number of days since September 1st 2024
required: true
type: string
responses:
"200":
description: Successful operation
schema:
type: object
example:
- data: Base 64 Data
date: 1234567890
filename: The Filename of the Image
real: true
status: unverified
theme: Cat
url: api/image/url
"400":
description: Empty Database
"404":
description: Invalid date
14 changes: 14 additions & 0 deletions scripts/add_api_url.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import yaml
import sys

def add_api_url(yaml_file, api_link):
with open(yaml_file, 'r+') as f:
data = yaml.safe_load(f)
data['x-google-backend'] = {'address': api_link}
with open(yaml_file, 'w') as f:
yaml.dump(data, f, default_flow_style=False, sort_keys=False)

if __name__ == '__main__':
yaml_file = sys.argv[1]
api_link = sys.argv[2]
add_api_url(yaml_file, api_link)
Loading