Skip to content
This repository was archived by the owner on Aug 4, 2023. It is now read-only.

Commit f529f50

Browse files
committed
Add Dockerfile versioning for build packs
1 parent 29cc528 commit f529f50

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

flamingo/models/buildpack.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
from dataclasses import dataclass, field
2+
from datetime import datetime
23
from enum import Enum
34
from pathlib import Path
45
from typing import List, TYPE_CHECKING
56

67
from gcp_pilot.datastore import Document
78
from gcp_pilot.storage import CloudStorage
9+
from google.api_core.exceptions import NotFound
810
from slugify import slugify
911

1012
import settings
@@ -49,10 +51,23 @@ def local_dockerfile(self) -> Path:
4951
return settings.PROJECT_DIR / 'engine' / self.name / 'Dockerfile'
5052

5153
async def upload_dockerfile(self):
54+
target_file_name = f'buildpack/{self.name}/Dockerfile'
55+
5256
gcs = CloudStorage()
5357

58+
# versioning
59+
try:
60+
timestamp = int(datetime.now().timestamp())
61+
await gcs.copy(
62+
source_file_name=target_file_name,
63+
target_file_name=f"{target_file_name}.{timestamp}",
64+
source_bucket_name=settings.FLAMINGO_GCS_BUCKET,
65+
target_bucket_name=settings.FLAMINGO_GCS_BUCKET,
66+
)
67+
except NotFound:
68+
pass
69+
5470
# TODO: invalidate GCS file cache?
55-
target_file_name = f'buildpack/{self.name}/Dockerfile'
5671
blob = await gcs.upload(
5772
bucket_name=settings.FLAMINGO_GCS_BUCKET,
5873
source_file=str(self.local_dockerfile),

0 commit comments

Comments
 (0)