-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ERA5T Support - Cloud Run Job Migration #95
base: main
Are you sure you want to change the base?
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Copyright 2025 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# ============================================================================== | ||
|
||
FROM continuumio/miniconda3:latest | ||
|
||
# Add the mamba solver for faster builds | ||
RUN conda install -n base conda-libmamba-solver | ||
RUN conda config --set solver libmamba | ||
|
||
# Clone the weather-tools and create conda env using environment.yml of weather-tools. | ||
ARG weather_tools_git_rev=main | ||
RUN git clone https://github.com/google/weather-tools.git /weather | ||
WORKDIR /weather | ||
RUN git checkout "${weather_tools_git_rev}" | ||
RUN rm -r /weather/weather_*/test_data/ | ||
RUN conda env create -f environment.yml --debug | ||
|
||
# Activate the conda env and update the PATH | ||
ARG CONDA_ENV_NAME=weather-tools | ||
RUN echo "source activate ${CONDA_ENV_NAME}" >> ~/.bashrc | ||
ENV PATH /opt/conda/envs/${CONDA_ENV_NAME}/bin:$PATH | ||
RUN pip install -e . | ||
|
||
# (TODO): Replace branch with main before merge. | ||
ARG arco_era5_git_rev=era5t-support | ||
RUN git clone https://github.com/google-research/arco-era5.git /arco-era5 | ||
WORKDIR /arco-era5 | ||
RUN git checkout "${arco_era5_git_rev}" | ||
RUN pip install -e . |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
PROJECT = "<PROJECT_ID>" | ||
REGION = "<REGION>" | ||
BUCKET = "<BUCKET_NAME>" | ||
API_KEY_1 = "projects/PROJECT/secrets/SECRET_NAME/versions/1" | ||
API_KEY_2 = "projects/PROJECT/secrets/SECRET_NAME/versions/1" | ||
API_KEY_3 = "projects/PROJECT/secrets/SECRET_NAME/versions/1" | ||
API_KEY_4 = "projects/PROJECT/secrets/SECRET_NAME/versions/1" | ||
WEATHER_TOOLS_SDK_CONTAINER_IMAGE = "WEATHER_TOOLS_SDK_CONTAINER_IMAGE" | ||
ARCO_ERA5_SDK_CONTAINER_IMAGE = "ARCO_ERA5_SDK_CONTAINER_IMAGE" | ||
MANIFEST_LOCATION = "fs://manifest?projectId=PROJECT_ID" | ||
TEMP_PATH_FOR_RAW_DATA="<BUCKET_PATH>" | ||
ROOT_PATH = "<BUCKET_PATH>" | ||
|
||
TASK_COUNT = 1 | ||
MAX_RETRIES = 1 | ||
|
||
CONTAINER_NAME = "arco-era5-container" | ||
CLOUD_RUN_CONTAINER_IMAGE = "CLOUD_RUN_CONTAINER_IMAGE" | ||
CONTAINER_COMMAND = ["python"] | ||
CONTAINER_CPU_LIMIT = "8000m" | ||
|
||
INGESTION_JOB_ID = "arco-era5-zarr-ingestion" | ||
SANITY_JOB_ID = "arco-era5-sanity" | ||
|
||
EXECUTOR_JOB_ID = "arco-era5-executor" | ||
DAILY_EXECUTOR_JOB_ID = "arco-era5t-daily-executor" | ||
MONTHLY_EXECUTOR_JOB_ID = "arco-era5t-monthly-executor" | ||
|
||
EXECUTOR_JOB_CONTAINER_ARGS = [ | ||
"src/raw-to-zarr-to-bq.py" | ||
] | ||
DAILY_EXECUTOR_JOB_CONTAINER_ARGS = [ | ||
"src/raw-to-zarr-to-bq.py", "--mode", "daily" | ||
] | ||
MONTHLY_EXECUTOR_JOB_CONTAINER_ARGS = [ | ||
"src/raw-to-zarr-to-bq.py", "--mode", "monthly" | ||
] | ||
|
||
JOB_CONTAINER_ENV_VARIABLES = [ | ||
{"name": "PROJECT", "value": PROJECT}, | ||
{"name": "REGION", "value": REGION}, | ||
{"name": "BUCKET", "value": BUCKET}, | ||
{"name": "WEATHER_TOOLS_SDK_CONTAINER_IMAGE", "value": WEATHER_TOOLS_SDK_CONTAINER_IMAGE}, | ||
{"name": "MANIFEST_LOCATION", "value": MANIFEST_LOCATION}, | ||
{"name": "PYTHON_PATH", "value": "python"}, | ||
{"name": "TEMP_PATH_FOR_RAW_DATA", "value": TEMP_PATH_FOR_RAW_DATA}, | ||
{"name": "INGESTION_JOB_ID", "value": INGESTION_JOB_ID}, | ||
{"name": "SANITY_JOB_ID", "value": SANITY_JOB_ID}, | ||
{"name": "ROOT_PATH", "value": ROOT_PATH}, | ||
{"name": "ARCO_ERA5_SDK_CONTAINER_IMAGE", "value": ARCO_ERA5_SDK_CONTAINER_IMAGE} | ||
] | ||
|
||
ERA5_API_KEYS = [ | ||
{"name": "API_KEY_1", "value": API_KEY_3}, | ||
{"name": "API_KEY_2", "value": API_KEY_4} | ||
] | ||
|
||
ERA5T_API_KEYS = [ | ||
{"name": "API_KEY_1", "value": API_KEY_1}, | ||
{"name": "API_KEY_2", "value": API_KEY_2} | ||
] | ||
|
||
CONTAINER_MEMORY_LIMIT = "34G" | ||
|
||
# Timeout for a day | ||
TIMEOUT_SECONDS = 86400 | ||
|
||
CONTAINER_MEMORY_LIMIT = "34G" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
# Copyright 2025 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
from google.cloud import run_v2 | ||
import constants | ||
|
||
|
||
def create_job(job_id: str, template: run_v2.ExecutionTemplate): | ||
# Create a client | ||
client = run_v2.JobsClient() | ||
|
||
# Initialize request argument(s) | ||
job = run_v2.Job() | ||
job.template = template | ||
|
||
request = run_v2.CreateJobRequest( | ||
parent=f"projects/{constants.PROJECT}/locations/{constants.REGION}", | ||
job=job, | ||
job_id=job_id, | ||
) | ||
|
||
# Make the request | ||
operation = client.create_job(request=request) | ||
|
||
print("Waiting for operation to complete...") | ||
|
||
response = operation.result() | ||
|
||
# Handle the response | ||
print(response) | ||
|
||
|
||
def era5_job_creator( | ||
job_id: str, | ||
timeout_sec: int, | ||
container_args: list = None, | ||
contaner_env: list = None, | ||
container_memory_limit: str = None, | ||
max_retries: int = 0 | ||
): | ||
# Create an ExecutionTemplate | ||
template = run_v2.ExecutionTemplate() | ||
template.task_count = constants.TASK_COUNT | ||
|
||
template.template.timeout = {"seconds": timeout_sec} | ||
template.template.max_retries = max_retries | ||
|
||
# Set container details | ||
container = run_v2.Container() | ||
container.name = constants.CONTAINER_NAME | ||
container.image = constants.CLOUD_RUN_CONTAINER_IMAGE | ||
container.command = constants.CONTAINER_COMMAND | ||
container.args = container_args | ||
|
||
# Set environment variables (example) | ||
container.env = contaner_env | ||
|
||
# Set resource limits (example) | ||
container.resources.limits = { | ||
"cpu": constants.CONTAINER_CPU_LIMIT, | ||
"memory": container_memory_limit, | ||
} | ||
|
||
# Add the container to the template | ||
template.template.containers.append(container) | ||
|
||
create_job(job_id, template) | ||
|
||
|
||
if __name__ == "__main__": | ||
era5_job_creator( | ||
job_id=constants.SANITY_JOB_ID, | ||
timeout_sec=constants.TIMEOUT_SECONDS, | ||
container_memory_limit=constants.CONTAINER_MEMORY_LIMIT, | ||
) | ||
era5_job_creator( | ||
job_id=constants.INGESTION_JOB_ID, | ||
timeout_sec=constants.TIMEOUT_SECONDS, | ||
container_memory_limit=constants.CONTAINER_MEMORY_LIMIT, | ||
) | ||
era5_job_creator( | ||
job_id=constants.DAILY_EXECUTOR_JOB_ID, | ||
timeout_sec=constants.TIMEOUT_SECONDS, | ||
container_args=constants.DAILY_EXECUTOR_JOB_CONTAINER_ARGS, | ||
contaner_env=constants.JOB_CONTAINER_ENV_VARIABLES + constants.ERA5T_API_KEYS, | ||
container_memory_limit=constants.CONTAINER_MEMORY_LIMIT, | ||
) | ||
era5_job_creator( | ||
job_id=constants.MONTHLY_EXECUTOR_JOB_ID, | ||
timeout_sec=constants.TIMEOUT_SECONDS, | ||
container_args=constants.MONTHLY_EXECUTOR_JOB_CONTAINER_ARGS, | ||
contaner_env=constants.JOB_CONTAINER_ENV_VARIABLES + constants.ERA5T_API_KEYS, | ||
container_memory_limit=constants.CONTAINER_MEMORY_LIMIT, | ||
) | ||
era5_job_creator( | ||
job_id=constants.EXECUTOR_JOB_ID, | ||
timeout_sec=constants.TIMEOUT_SECONDS, | ||
container_args=constants.EXECUTOR_JOB_CONTAINER_ARGS, | ||
contaner_env=constants.JOB_CONTAINER_ENV_VARIABLES + constants.ERA5_API_KEYS, | ||
container_memory_limit=constants.CONTAINER_MEMORY_LIMIT, | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,8 +15,9 @@ name: era5 | |
channels: | ||
- conda-forge | ||
dependencies: | ||
- python=3.9.17 | ||
- python=3.8.19 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using Python 3.8 is concerning to me. Python 3.8 is very old, already at end of life. This means it no longer receives security updates: https://devguide.python.org/versions/ Even Python 3.9 will soon be at end of life. We should strive to use newer versions of Python which are actively maintained. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed @shoyer. The plan is to remove this |
||
- metview-batch==5.17.0 | ||
- pip: | ||
- cython==0.29.34 | ||
- setuptools==70.3.0 | ||
- metview |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update the branch name before merging this PR.