From cbc861f55a8cf9fc3f9fd933d6e99e1a811117ba Mon Sep 17 00:00:00 2001 From: Zach Legesse Date: Tue, 29 Oct 2024 00:26:19 -0400 Subject: [PATCH 1/6] Build Open API Spec #52 --- openapi.yml | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 openapi.yml 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 From af998cc909f7ac29a6b5de70873919997dd43f2d Mon Sep 17 00:00:00 2001 From: Zach Legesse Date: Tue, 29 Oct 2024 00:27:52 -0400 Subject: [PATCH 2/6] Create pipeline to upload new api-config #52 --- .github/workflows/deploy.yml | 22 ++++++++++++++++++++-- scripts/add_api_url.py | 14 ++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 scripts/add_api_url.py diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 378c8b5..958bbae 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -7,8 +7,8 @@ on: env: REGION: us-central1 jobs: - deploy: - name: Deploy + deploy-container: + name: Deploy Containerized App runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -24,3 +24,21 @@ 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 }} + deploy-api: + name: Deploy API + runs-on: ubuntu-latest + needs: deploy-container + steps: + - uses: actions/setup-python@v5 + with: + python-version: "3.12" + cache: "pip" + - name: Add API Url to API Spec + run: python scripts/add_api_url.py openapi.yml ${{ secrets.API_URL }} + - uses: actions/checkout@v4 + - name: Authenticate to Google Cloud + uses: "google-github-actions/auth@v2" + with: + credentials_json: "${{ secrets.GOOGLE_CREDENTIALS }}" + - name: Create and Deploy API-Config + run: gcloud api-gateway api-configs create api-config --api=api --openapi-spec=openapi.yml 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 From ea2c26412a12570625caee345393b8a7a04edcde Mon Sep 17 00:00:00 2001 From: Zach Legesse Date: Tue, 29 Oct 2024 00:28:15 -0400 Subject: [PATCH 3/6] Lint Dockerfile #52 --- Dockerfile | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) 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 From 00753699a04be521b7de04aa93c8a8a05c90df82 Mon Sep 17 00:00:00 2001 From: numba19 Date: Wed, 30 Oct 2024 19:52:30 -0400 Subject: [PATCH 4/6] Remove extra python setup script #52 --- .github/workflows/deploy.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 958bbae..09ba547 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -29,10 +29,6 @@ jobs: runs-on: ubuntu-latest needs: deploy-container steps: - - uses: actions/setup-python@v5 - with: - python-version: "3.12" - cache: "pip" - name: Add API Url to API Spec run: python scripts/add_api_url.py openapi.yml ${{ secrets.API_URL }} - uses: actions/checkout@v4 From 82c11329ca5c626abb66e78a65399b02adcbf432 Mon Sep 17 00:00:00 2001 From: numba19 Date: Wed, 30 Oct 2024 20:07:07 -0400 Subject: [PATCH 5/6] temp --- .github/workflows/deploy.yml | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 09ba547..a30a305 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -7,7 +7,7 @@ on: env: REGION: us-central1 jobs: - deploy-container: + deploy: name: Deploy Containerized App runs-on: ubuntu-latest steps: @@ -24,17 +24,8 @@ 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 }} - deploy-api: - name: Deploy API - runs-on: ubuntu-latest - needs: deploy-container - steps: - name: Add API Url to API Spec run: python scripts/add_api_url.py openapi.yml ${{ secrets.API_URL }} - uses: actions/checkout@v4 - - name: Authenticate to Google Cloud - uses: "google-github-actions/auth@v2" - with: - credentials_json: "${{ secrets.GOOGLE_CREDENTIALS }}" - name: Create and Deploy API-Config run: gcloud api-gateway api-configs create api-config --api=api --openapi-spec=openapi.yml From 944ef7749141d344a44565be48350e409a154426 Mon Sep 17 00:00:00 2001 From: numba19 Date: Wed, 30 Oct 2024 20:31:21 -0400 Subject: [PATCH 6/6] temp --- .github/workflows/deploy.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index a30a305..38593c1 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -26,6 +26,5 @@ jobs: 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 }} - - uses: actions/checkout@v4 - name: Create and Deploy API-Config run: gcloud api-gateway api-configs create api-config --api=api --openapi-spec=openapi.yml