Skip to content
Merged

Dev #105

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
bf20008
fix: correct GCS_SERVICE_ACCOUNT_KEY echo syntax and update relations…
jirhiker Aug 25, 2025
ccfe955
fix: update staging deployment configuration for dev environment
jirhiker Aug 25, 2025
c942375
fix: correct syntax for GCS_SERVICE_ACCOUNT_KEY in staging deployment…
jirhiker Aug 25, 2025
1eca98a
fix: correct syntax for GCS_SERVICE_ACCOUNT_KEY in staging deployment…
jirhiker Aug 25, 2025
dfbf9f2
fix: correct syntax for GCS_SERVICE_ACCOUNT_KEY in staging deployment…
jirhiker Aug 25, 2025
9e11ad1
fix: correct syntax for GCS_SERVICE_ACCOUNT_KEY in staging deployment…
jirhiker Aug 25, 2025
5285228
fix: add debug prints for GCS_SERVICE_ACCOUNT_KEY in production mode
jirhiker Aug 26, 2025
062604b
fix: add debug prints for GCS_SERVICE_ACCOUNT_KEY in production mode
jirhiker Aug 26, 2025
5645a1b
fix: update debug prints for GCS_SERVICE_ACCOUNT_KEY and correct YAML…
jirhiker Aug 26, 2025
06d8d18
Formatting changes
jirhiker Aug 26, 2025
744e310
fix: escape single quotes for GCS_SERVICE_ACCOUNT_KEY in staging depl…
jirhiker Aug 26, 2025
0250504
fix: update GCS_SERVICE_ACCOUNT_KEY syntax in staging deployment conf…
jirhiker Aug 26, 2025
b7f9246
fix: decode GCS_SERVICE_ACCOUNT_KEY from base64 in production mode
jirhiker Aug 26, 2025
56b739a
fix: remove debug print for GCS_SERVICE_ACCOUNT_KEY in production mode
jirhiker Aug 26, 2025
479a3c2
feat: add dev deployment configuration for Google Cloud
jirhiker Aug 26, 2025
5bc8d03
fix: update deployment configuration name from Staging to Development
jirhiker Aug 26, 2025
2e1a852
fix: remove unnecessary git setup and tagging steps from dev deployme…
jirhiker Aug 26, 2025
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
78 changes: 78 additions & 0 deletions .github/workflows/dev_deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
name: CD (Development)

on:
push:
branches: [dev]

permissions:
contents: write

jobs:
staging-deploy:

runs-on: ubuntu-latest
environment: staging

steps:
- name: Check out source repository
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Install uv in container
uses: astral-sh/setup-uv@v6
with:
version: "latest"

- name: Generate requirements.txt
run: |
uv export -o requirements.txt

- name: Authenticate to Google Cloud
uses: 'google-github-actions/auth@v2'
with:
credentials_json: ${{ secrets.CLOUD_DEPLOY_SERVICE_ACCOUNT_KEY }}

# Uses Google Cloud Secret Manager to store secret credentials
- name: Create app.yaml
run: |
echo "service: dev-ocotillo-api" > app.yaml
echo "runtime: python313" >> app.yaml
echo "entrypoint: gunicorn -w 4 -k uvicorn.workers.UvicornWorker main:app" >> app.yaml
echo "instance_class: F4" >> app.yaml
echo "" >> app.yaml
echo "env_variables:" >> app.yaml
echo " MODE: \"production\"" >> app.yaml
echo " DB_DRIVER: \"cloudsql\"" >> app.yaml
echo " CLOUD_SQL_INSTANCE_NAME: \"${{ secrets.CLOUD_SQL_INSTANCE_NAME }}\"" >> app.yaml
echo " CLOUD_SQL_DATABASE: \"${{ secrets.CLOUD_SQL_DATABASE }}\"" >> app.yaml
echo " CLOUD_SQL_USER: \"${{ secrets.CLOUD_SQL_USER }}\"" >> app.yaml
echo " CLOUD_SQL_PASSWORD: \"${{ secrets.CLOUD_SQL_PASSWORD }}\"" >> app.yaml
echo " GCS_SERVICE_ACCOUNT_KEY: \"${{ secrets.GCS_SERVICE_ACCOUNT_KEY }}\"" >> app.yaml
echo " GCS_BUCKET_NAME: \"${{secrets.GCS_BUCKET_NAME}}\"" >> app.yaml
echo " AUTHENTIK_URL: \"${{secrets.AUTHENTIK_URL}}\"" >> app.yaml
echo " AUTHENTIK_CLIENT_ID: \"${{secrets.AUTHENTIK_CLIENT_ID}}\"" >> app.yaml
echo " AUTHENTIK_AUTHORIZE_URL: \"${{secrets.AUTHENTIK_AUTHORIZE_URL}}\"" >> app.yaml
echo " AUTHENTIK_TOKEN_URL: \"${{secrets.AUTHENTIK_TOKEN_URL}}\"" >> app.yaml


- name: Deploy to Google Cloud
run: |
gcloud app deploy app.yaml --quiet --project ${{ secrets.GCP_PROJECT_ID }}

# Clean up old versions - delete only the oldest version, one created and one destroyed
- name: Clean up oldest version
run: |
OLDEST_VERSION=$(gcloud app versions list --service=dev-ocotillo-api --project=${{ secrets.GCP_PROJECT_ID}} --format="value(id)" --sort-by="version.createTime" | head -n 1)
if [ ! -z "$OLDEST_VERSION" ]; then
echo "Deleting oldest version: $OLDEST_VERSION"
gcloud app versions delete $OLDEST_VERSION --service=dev-ocotillo-api --project=${{ secrets.GCP_PROJECT_ID }} --quiet
echo "Deleted oldest version: $OLDEST_VERSION"
else
echo "No versions to delete"
fi

- name: Remove app.yaml
run: |
rm app.yaml

4 changes: 2 additions & 2 deletions .github/workflows/staging_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
echo " CLOUD_SQL_DATABASE: \"${{ secrets.CLOUD_SQL_DATABASE }}\"" >> app.yaml
echo " CLOUD_SQL_USER: \"${{ secrets.CLOUD_SQL_USER }}\"" >> app.yaml
echo " CLOUD_SQL_PASSWORD: \"${{ secrets.CLOUD_SQL_PASSWORD }}\"" >> app.yaml
echo " GCS_SERVICE_ACCOUNT_KEY: \"${{ secrets.GCS_SERVICE_ACCOUNT_KEY}}\"" >> app.yaml
echo " GCS_SERVICE_ACCOUNT_KEY: \"${{ secrets.GCS_SERVICE_ACCOUNT_KEY }}\"" >> app.yaml
echo " GCS_BUCKET_NAME: \"${{secrets.GCS_BUCKET_NAME}}\"" >> app.yaml
echo " AUTHENTIK_URL: \"${{secrets.AUTHENTIK_URL}}\"" >> app.yaml
echo " AUTHENTIK_CLIENT_ID: \"${{secrets.AUTHENTIK_CLIENT_ID}}\"" >> app.yaml
Expand All @@ -63,7 +63,7 @@ jobs:
# Clean up old versions - delete only the oldest version, one created and one destroyed
- name: Clean up oldest version
run: |
OLDEST_VERSION=$(gcloud app versions list --service=ocotillo-api --project=${{ secrets.GCP_PROJECT_ID }} --format="value(id)" --sort-by="version.createTime" | head -n 1)
OLDEST_VERSION=$(gcloud app versions list --service=ocotillo-api --project=${{ secrets.GCP_PROJECT_ID}} --format="value(id)" --sort-by="version.createTime" | head -n 1)
if [ ! -z "$OLDEST_VERSION" ]; then
echo "Deleting oldest version: $OLDEST_VERSION"
gcloud app versions delete $OLDEST_VERSION --service=ocotillo-api --project=${{ secrets.GCP_PROJECT_ID }} --quiet
Expand Down
2 changes: 1 addition & 1 deletion db/thing.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class WellScreen(Base, AutoBaseMixin):
String(1000), nullable=True, info={"unit": "description of the screen"}
)
# Define a relationship to well if needed
# well = relationship("Well")
thing = relationship("Thing")


# ============= EOF =============================================
1 change: 1 addition & 0 deletions schemas/thing.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ class WellScreenResponse(ORMBaseModel):
"""

thing_id: int
thing: WellResponse
screen_depth_bottom: float
screen_depth_top: float
screen_type: str | None = None
Expand Down
7 changes: 5 additions & 2 deletions services/gcs_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# ===============================================================================
import base64
import json
import os
import datetime
Expand All @@ -32,10 +33,12 @@
def get_storage_bucket() -> storage.Bucket:

if settings.mode == "production":
key_json = os.environ.get("GCS_SERVICE_ACCOUNT_KEY")
key_base64 = os.environ.get("GCS_SERVICE_ACCOUNT_KEY")
decoded = base64.b64decode(key_base64).decode("utf-8")

# Load service account credentials
creds = service_account.Credentials.from_service_account_info(
json.loads(key_json)
json.loads(decoded)
)

# Create storage client
Expand Down
Loading