Skip to content
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

Clean up docker containers #55

Merged
merged 4 commits into from
Jan 11, 2024
Merged
Changes from all commits
Commits
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
24 changes: 16 additions & 8 deletions buildstockbatch/gcp/gcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,11 +570,11 @@ def start_batch_job(self, batch_info):

client = batch_v1.BatchServiceClient()

runnable = batch_v1.Runnable()
runnable.container = batch_v1.Runnable.Container()
runnable.container.image_uri = self.repository_uri + ":" + self.job_identifier
runnable.container.entrypoint = "/bin/sh"
runnable.labels = labels
bsb_runnable = batch_v1.Runnable()
bsb_runnable.container = batch_v1.Runnable.Container()
bsb_runnable.container.image_uri = self.repository_uri + ":" + self.job_identifier
bsb_runnable.container.entrypoint = "/bin/sh"
bsb_runnable.labels = labels

# Pass environment variables to each task
environment = batch_v1.Environment()
Expand All @@ -584,9 +584,17 @@ def start_batch_job(self, batch_info):
"GCS_PREFIX": self.gcs_prefix,
"GCS_BUCKET": self.gcs_bucket,
}
runnable.environment = environment
bsb_runnable.environment = environment

runnable.container.commands = ["-c", "python3 -m buildstockbatch.gcp.gcp"]
bsb_runnable.container.commands = ["-c", "python3 -m buildstockbatch.gcp.gcp"]

# Prune old docker containers after we're done using them, so they don't use up all the disk space.
cleanup_runnable = batch_v1.Runnable()
cleanup_runnable.script = batch_v1.Runnable.Script()
# "until=2m" - Ignore containers that were just created and aren't active yet.
# "|| true" - This can fail if another task is pruning at the same time, but these failures are safe to ignore.
cleanup_runnable.script.text = 'docker system prune -f --filter "until=2m" || true'
cleanup_runnable.labels = labels

gcp_cfg = self.cfg["gcp"]
job_env_cfg = gcp_cfg.get("job_environment", {})
Expand All @@ -598,7 +606,7 @@ def start_batch_job(self, batch_info):
# Give three minutes per simulation, plus ten minutes for job overhead
task_duration_secs = 60 * (10 + batch_info.n_sims_per_job * 3)
task = batch_v1.TaskSpec(
runnables=[runnable],
runnables=[bsb_runnable, cleanup_runnable],
compute_resource=resources,
# Allow retries, but only when the machine is preempted.
max_retry_count=3,
Expand Down