Skip to content

Commit eac7a8b

Browse files
author
RM
committed
Commit squash
1 parent a66b9ff commit eac7a8b

17 files changed

Lines changed: 530 additions & 49 deletions
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: Deploy All Services
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
deploy-api:
8+
uses: ./.github/workflows/deploy-api.yml
9+
secrets: inherit
10+
11+
deploy-web:
12+
uses: ./.github/workflows/deploy-web.yml
13+
secrets: inherit
14+
15+
deploy-monitor:
16+
uses: ./.github/workflows/deploy-chipnik-monitor.yml
17+
secrets: inherit

.github/workflows/deploy-api.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Deploy API
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
paths:
8+
- "api/**"
9+
workflow_dispatch:
10+
workflow_call:
11+
12+
env:
13+
PROJECT_ID: demetereye
14+
REGION: us-central1
15+
SERVICE_NAME: demetereye-api
16+
17+
jobs:
18+
deploy:
19+
runs-on: ubuntu-latest
20+
21+
steps:
22+
- name: Checkout repository
23+
uses: actions/checkout@v4
24+
25+
- name: Authenticate to Google Cloud
26+
uses: google-github-actions/auth@v2
27+
with:
28+
credentials_json: ${{ secrets.GCP_SA_KEY }}
29+
30+
- name: Set up gcloud SDK
31+
uses: google-github-actions/setup-gcloud@v2
32+
33+
- name: Configure gcloud defaults
34+
run: |
35+
gcloud config set project "$PROJECT_ID"
36+
gcloud config set run/region "$REGION"
37+
38+
- name: Deploy API service
39+
env:
40+
MONGO_DB: demetereye
41+
PROCESSOR_URL: https://demetereye-monitor-1060536779509.us-central1.run.app
42+
working-directory: api
43+
run: |
44+
gcloud run deploy "$SERVICE_NAME" \
45+
--source . \
46+
--region "$REGION" \
47+
--allow-unauthenticated \
48+
--min-instances 0 --max-instances 2 \
49+
--memory 512Mi --cpu 1 \
50+
--port 8080 \
51+
--set-env-vars MONGO_DB=${MONGO_DB},PROCESSOR_URL=${PROCESSOR_URL} \
52+
--set-secrets MONGO_URI=MONGO_URI:latest,JWT_SECRET=JWT_SECRET:latest
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Deploy Chipnik Monitor API
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
paths:
8+
- "chipnik_monitor/**"
9+
workflow_dispatch:
10+
workflow_call:
11+
12+
env:
13+
PROJECT_ID: demetereye
14+
REGION: us-central1
15+
SERVICE_NAME: demetereye-monitor
16+
17+
jobs:
18+
deploy:
19+
runs-on: ubuntu-latest
20+
21+
steps:
22+
- name: Checkout repository
23+
uses: actions/checkout@v4
24+
25+
- name: Authenticate to Google Cloud
26+
uses: google-github-actions/auth@v2
27+
with:
28+
credentials_json: ${{ secrets.GCP_SA_KEY }}
29+
30+
- name: Set up gcloud SDK
31+
uses: google-github-actions/setup-gcloud@v2
32+
33+
- name: Configure gcloud defaults
34+
run: |
35+
gcloud config set project "$PROJECT_ID"
36+
gcloud config set run/region "$REGION"
37+
38+
- name: Deploy to Cloud Run
39+
env:
40+
EARTHDATA_BEARER_TOKEN: ${{ secrets.EARTHDATA_BEARER_TOKEN }}
41+
MONGO_URI: ${{ secrets.MONGO_URI }}
42+
MONGO_DB: ${{ secrets.MONGO_DB }}
43+
working-directory: chipnik_monitor
44+
run: |
45+
gcloud run deploy "$SERVICE_NAME" \
46+
--source . \
47+
--region "$REGION" \
48+
--allow-unauthenticated \
49+
--min-instances 0 --max-instances 2 \
50+
--memory 512Mi --cpu 1 \
51+
--no-cpu-throttling \
52+
--set-env-vars EARTHDATA_BEARER_TOKEN=${EARTHDATA_BEARER_TOKEN},MONGO_URI=${MONGO_URI},MONGO_DB=${MONGO_DB}

.github/workflows/deploy-web.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Deploy Web
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
paths:
8+
- "web/**"
9+
workflow_dispatch:
10+
workflow_call:
11+
12+
env:
13+
PROJECT_ID: demetereye
14+
REGION: us-central1
15+
SERVICE_NAME: demetereye-web
16+
17+
jobs:
18+
deploy:
19+
runs-on: ubuntu-latest
20+
21+
steps:
22+
- name: Checkout repository
23+
uses: actions/checkout@v4
24+
25+
- name: Authenticate to Google Cloud
26+
uses: google-github-actions/auth@v2
27+
with:
28+
credentials_json: ${{ secrets.GCP_SA_KEY }}
29+
30+
- name: Set up gcloud SDK
31+
uses: google-github-actions/setup-gcloud@v2
32+
33+
- name: Configure gcloud defaults
34+
run: |
35+
gcloud config set project "$PROJECT_ID"
36+
gcloud config set run/region "$REGION"
37+
38+
- name: Deploy Web service
39+
working-directory: web
40+
run: |
41+
gcloud run deploy "$SERVICE_NAME" \
42+
--source . \
43+
--region "$REGION" \
44+
--allow-unauthenticated \
45+
--min-instances 0 --max-instances 2 \
46+
--memory 256Mi --cpu 1 \
47+
--port 8080

api/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@ gcloud run deploy demetereye-api \
1111
--set-env-vars MONGO_DB=demetereye \
1212
--set-secrets MONGO_URI=MONGO_URI:latest,JWT_SECRET=JWT_SECRET:latest \
1313
--set-env-vars PROCESSOR_URL=https://demetereye-monitor-1060536779509.us-central1.run.app
14+
15+

api/handlers_fields.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ func (a *App) handleCreateField(w http.ResponseWriter, r *http.Request) {
7777
if err == nil {
7878
// send update to processor
7979
a.PostProcessorReports(ctx, processorReportReq{
80+
FieldID: f.ID.Hex(),
8081
GeoJSON: req.Geometry,
8182
YieldType: req.Crop,
8283
Yields: req.Yields,
@@ -186,6 +187,7 @@ func (a *App) handleUpdateField(w http.ResponseWriter, r *http.Request) {
186187
if err == nil {
187188
// send update to processor
188189
a.PostProcessorReports(ctx, processorReportReq{
190+
FieldID: out.ID.Hex(),
189191
GeoJSON: req.Geometry,
190192
YieldType: req.Crop,
191193
Yields: req.Yields,

api/types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ type ingestFieldReq struct {
5151

5252
// Payload we send to Processor /reports
5353
type processorReportReq struct {
54+
FieldID string `json:"fieldId"` // field id
5455
GeoJSON json.RawMessage `json:"geojson"` // entire Feature or Geometry
5556
YieldType string `json:"yieldType,omitempty"` // e.g., "Potato"
5657
Yields []YieldEntry `json:"yields,omitempty"`

chipnik_monitor/.env_example

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
EARTHDATA_BEARER_TOKEN=""
22
MONGO_URI=""
3-
MONGO_DB=""
3+
MONGO_DB=""
4+
DAYS_BACK_LIMIT=""

chipnik_monitor/.gcloudignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Ignore Python virtual env
2+
venv/
3+
4+
# Ignore cache
5+
__pycache__/
6+
*.pyc
7+
8+
# Ignore IDE configs
9+
.vscode/
10+
.idea/

chipnik_monitor/Dockerfile

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# syntax=docker/dockerfile:1
2+
3+
FROM python:3.11-slim AS base
4+
5+
ENV PYTHONDONTWRITEBYTECODE=1 \
6+
PYTHONUNBUFFERED=1 \
7+
PIP_NO_CACHE_DIR=1
8+
9+
RUN apt-get update \
10+
&& apt-get install -y --no-install-recommends \
11+
build-essential \
12+
gdal-bin \
13+
libgdal-dev \
14+
proj-bin \
15+
libproj-dev \
16+
&& rm -rf /var/lib/apt/lists/*
17+
18+
WORKDIR /app
19+
20+
# Copy only requirements first
21+
COPY requirements.txt ./requirements.txt
22+
RUN pip install --no-cache-dir -r requirements.txt
23+
24+
# Copy only required files and folders
25+
# COPY .env ./
26+
COPY api.py ./
27+
COPY chipnik_monitor.py ./
28+
COPY geojsons ./geojsons
29+
COPY media ./media
30+
31+
ENV GDAL_DATA=/usr/share/gdal \
32+
PROJ_LIB=/usr/share/proj
33+
34+
RUN useradd --create-home appuser \
35+
&& chown -R appuser:appuser /app
36+
37+
USER appuser
38+
39+
EXPOSE 8080
40+
41+
CMD ["uvicorn", "api:app", "--host", "0.0.0.0", "--port", "8080"]

0 commit comments

Comments
 (0)