Skip to content

Commit f9bc700

Browse files
authored
Merge branch 'main' into feature/msavi-endpoint
2 parents 82329e5 + 1ca0be7 commit f9bc700

22 files changed

+298
-50
lines changed

.github/workflows/deploy.yml

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,16 @@ jobs:
1010
runs-on: ubuntu-latest
1111

1212
env:
13+
GOOGLE_PROJECT_ID: ${{ vars.GOOGLE_PROJECT_ID }}
14+
GOOGLE_EARTH_ENGINE_SERVICE_ACCOUNT_CREDENTIALS: ${{ secrets.GOOGLE_EARTH_ENGINE_SERVICE_ACCOUNT_CREDENTIALS }}
15+
GOOGLE_EARTH_ENGINE_SERVICE_ACCOUNT_EMAIL: ${{ secrets.GOOGLE_EARTH_ENGINE_SERVICE_ACCOUNT_EMAIL }}
16+
ENVIRONMENT: ${{ vars.ENVIRONMENT }}
1317
GOOGLE_APPLICATION_CREDENTIALS: ${{ secrets.GCP_SA_KEY }}
1418
BACKEND_IMAGE_NAME: europe-west3-docker.pkg.dev/thf-climate-cloud/thf-climate/thf-climate
1519
FRONTEND_IMAGE_NAME: europe-west3-docker.pkg.dev/thf-climate-cloud/thf-climate-frontend/thf-climate-frontend
1620

1721
steps:
18-
# Step 1: Checkout the code
19-
- name: Checkout code
20-
uses: actions/checkout@v2
22+
- uses: actions/checkout@v3
2123

2224
# Step 2: Decode and Write the Service Account Key to a file properly
2325
- name: Set up Google Cloud credentials
@@ -43,11 +45,28 @@ jobs:
4345
run: |
4446
gcloud auth configure-docker europe-west3-docker.pkg.dev
4547
46-
# Step 6: Build and Deploy the backend
47-
- name: Build Docker image (backend)
48+
# Step 6: Build and the run the backend
49+
- name: Build and Run the Docker image (backend)
4850
working-directory: ./backend
4951
run: |
5052
docker buildx build --platform linux/amd64 -t $BACKEND_IMAGE_NAME:latest .
53+
docker run -d -p 8000:8000 --name thf-climate-backend $BACKEND_IMAGE_NAME
54+
- name: Wait for the application to start
55+
working-directory: ./backend
56+
run: |
57+
timeout 30 bash -c 'until curl -s http://127.0.0.1:8000/; do sleep 1; done'
58+
59+
# Step 7: Run the tests against the local application
60+
- name: Install dependencies and Run tests (backend)
61+
working-directory: ./backend
62+
env:
63+
API_BASE_URL: "http://127.0.0.1:8000"
64+
run: |
65+
python -m pip install --upgrade pip
66+
pip install -r requirements-dev.txt
67+
pytest
68+
69+
# Step 8: Push and Deploy the backend on Google cloud
5170
- name: Push Docker image to Artifact Registry (backend)
5271
working-directory: ./backend
5372
run: |
@@ -64,7 +83,7 @@ jobs:
6483
--min-instances=1 \
6584
--max-instances=5
6685
67-
# Step 7: Build and Deploy the frontend
86+
# Step 9: Build and Deploy the frontend
6887
- name: Build Docker image (frontend)
6988
working-directory: ./frontend
7089
run: |

.github/workflows/tests-main.yaml

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,24 @@ jobs:
1616
ENVIRONMENT: ${{ vars.ENVIRONMENT }}
1717
steps:
1818
- uses: actions/checkout@v3
19-
- name: Set up Python
20-
uses: actions/setup-python@v4
21-
with:
22-
python-version: '3.11'
23-
- name: Install dependencies
19+
20+
# Build and the run the backend docker image
21+
- name: Build and Run the Docker image (backend)
22+
working-directory: ./backend
23+
run: |
24+
docker buildx build --platform linux/amd64 -t thf-climate-backend .
25+
docker run -d -p 8000:8000 --name thf-climate-backend thf-climate-backend
26+
- name: Wait for the application to start
2427
working-directory: ./backend
28+
run: |
29+
timeout 30 bash -c 'until curl -s http://127.0.0.1:8000/; do sleep 1; done'
30+
31+
# Run the tests against the local application
32+
- name: Install dependencies and Run tests
33+
working-directory: ./backend
34+
env:
35+
API_BASE_URL: "http://127.0.0.1:8000"
2536
run: |
2637
python -m pip install --upgrade pip
2738
pip install -r requirements-dev.txt
28-
- name: Run tests
29-
working-directory: ./backend
30-
run: pytest
39+
pytest

backend/src/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
app = FastAPI()
99

10-
origins = ["http://localhost:5173"]
10+
origins = ["http://localhost:5173", "https://thf-climate-frontend-run-1020174331409.europe-west3.run.app"]
1111

1212
app.add_middleware(
1313
CORSMiddleware,

backend/src/validation/utils.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,17 @@ def validate_timestamp_start_date_before_end_date(startDate, endDate):
2626
raise HTTPException(
2727
status_code=400, detail="endDate must be after startDate")
2828
return endDate
29+
30+
31+
def validate_temperature_timestamp_in_range(start, end):
32+
min_timestamp = -946771200 # 01/01/1940
33+
max_timestamp = int(time.time()) # now
34+
print(end)
35+
print(max_timestamp)
36+
if (start < min_timestamp or end > max_timestamp):
37+
raise HTTPException(
38+
status_code=400, detail=f"Timestamp must be between {min_timestamp} and {max_timestamp}")
39+
elif end <= start:
40+
raise HTTPException(
41+
status_code=400, detail="endDate must be after startDate")
42+
return end

backend/src/weather/schemas.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from src.constants import AggregationMethod, LocationName, TemporalResolution, Unit
66
from src.validation.utils import (
7-
validate_timestamp_in_range,
7+
validate_temperature_timestamp_in_range,
88
validate_timestamp_start_date_before_end_date,
99
)
1010

@@ -33,14 +33,9 @@ class WeatherDataRequest(BaseModel):
3333
)
3434
aggregation: AggregationMethod = Field(..., description="Aggregation method")
3535

36-
# Custom validator to check if timestamps are valid and in the correct order
37-
@field_validator("startDate")
38-
def validate_timestamp_in_range(cls, v):
39-
return validate_timestamp_in_range(v)
40-
4136
@field_validator("endDate")
42-
def end_date_must_be_after_start_date(cls, v, info: ValidationInfo):
43-
return validate_timestamp_start_date_before_end_date(
37+
def validate_temperature_timestamp_in_range(cls, v, info: ValidationInfo):
38+
return validate_temperature_timestamp_in_range(
4439
info.data.get("startDate"), v
4540
)
4641

backend/tests/test_api_response.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import os
2+
import requests
3+
4+
5+
def test_api_response():
6+
# Make a GET request to the API
7+
response = requests.get(os.getenv("API_BASE_URL"))
8+
9+
# Verify the response status code
10+
assert response.status_code == 200, f"Expected 200, got {response.status_code}"
11+
12+
# Verify the response body
13+
expected_response = {"Hello": "World"}
14+
assert response.json() == expected_response, f"Expected {expected_response}, got {response.json()}"

frontend/src/App.vue

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,25 @@
11
<template>
22
<h1 id="app">
3-
<NdviComparisonGraph />
4-
<NdviSelectMonthGraph />
5-
<NdviOverlayGraph />
6-
<MedianTempGraph />
7-
<MeanSoilTempGraph />
8-
<MeanSoilMoistureGraph />
9-
<AugustMeanSoilTempGraph />
10-
<SelectMonthMeanSoilTempGraph />
3+
<Header />
4+
<IntroSection />
5+
<MainSection />
6+
<Footer />
117
</h1>
128
</template>
139

1410
<script>
15-
import NdviComparisonGraph from "./components/NdviGraphs/NdviComparisonGraph.vue"
16-
import NdviSelectMonthGraph from "./components/NdviGraphs/NdviSelectMonthGraph.vue"
17-
import NdviOverlayGraph from "./components/NdviGraphs/NdviOverlayGraph.vue"
18-
import MedianTempGraph from "./components/MedianTempGraph.vue"
19-
import MeanSoilTempGraph from "./components/SoilTempGraph.vue"
20-
import MeanSoilMoistureGraph from "./components/SoilMoistureGraph.vue"
21-
import AugustMeanSoilTempGraph from "./components/AugustSoilTempGraph.vue"
22-
import SelectMonthMeanSoilTempGraph from "./components/SelectMonthSoilTempGraph.vue"
11+
import Header from "./components/Header.vue"
12+
import IntroSection from "./components/IntroSection.vue"
13+
import MainSection from "./components/MainSection.vue"
14+
import Footer from "./components/Footer.vue"
2315
2416
export default {
2517
name: 'App',
2618
components: {
27-
NdviComparisonGraph,
28-
NdviSelectMonthGraph,
29-
NdviOverlayGraph,
30-
MedianTempGraph,
31-
MeanSoilTempGraph,
32-
MeanSoilMoistureGraph,
33-
AugustMeanSoilTempGraph,
34-
SelectMonthMeanSoilTempGraph
19+
Header,
20+
IntroSection,
21+
MainSection,
22+
Footer
3523
}
3624
}
3725
</script>
7.01 MB
Loading
1010 KB
Loading
1.27 MB
Loading

0 commit comments

Comments
 (0)