diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 378c8b5..38593c1 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -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 @@ -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 diff --git a/Dockerfile b/Dockerfile index 93ecd68..1f18aed 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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"] \ No newline at end of file diff --git a/openapi.yml b/openapi.yml new file mode 100644 index 0000000..9d39085 --- /dev/null +++ b/openapi.yml @@ -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 diff --git a/scripts/add_api_url.py b/scripts/add_api_url.py new file mode 100644 index 0000000..f6a8e1a --- /dev/null +++ b/scripts/add_api_url.py @@ -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) \ No newline at end of file