-
Notifications
You must be signed in to change notification settings - Fork 382
Add LogStore to retain build logs, and a S3LogStore implementation #967
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
Draft
manics
wants to merge
12
commits into
jupyterhub:main
Choose a base branch
from
manics:s3logs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+228
−2
Draft
Changes from 1 commit
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
e2633b0
s3 logs prototype
manics fff010b
Remove ANSI terminal escapes from logs
manics 83d0f28
Move S3 log upload into a Configurable class
manics 52c732b
Remove S3LogStore.close return URL
manics d69ca94
Add mock unittest for S3LogStore
manics c3991e8
S3LogStore set charset=utf-8
manics a028dc2
S3LogStore add metadata
manics 6d54148
S3LogStore fix logname
manics 792bbe0
S3LogStore only log if non-empty, default key `repo2docker.log` (no i…
manics cd90863
logstore: remove ACL
manics 0d28357
Move all log config into S3LogStore
manics 8cadb5b
Merge remote-tracking branch 'origin/master' into s3logs
manics File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
import sys | ||
import logging | ||
import os | ||
import boto3 | ||
import getpass | ||
import shutil | ||
import tempfile | ||
|
@@ -326,6 +327,12 @@ def _user_name_default(self): | |
config=True, | ||
) | ||
|
||
s3_logs_endpoint = Unicode("", help="S3 endpoint", config=True) | ||
s3_logs_access_key = Unicode("", help="S3 access key ", config=True) | ||
s3_logs_secret_key = Unicode("", help="S3 secret key", config=True) | ||
s3_logs_bucket = Unicode("", help="S3 bucket", config=True) | ||
s3_logs_region = Unicode("", help="S3 region", config=True) | ||
|
||
all_ports = Bool( | ||
False, | ||
help=""" | ||
|
@@ -625,7 +632,7 @@ def find_image(self): | |
return True | ||
return False | ||
|
||
def build(self): | ||
def build(self, logfile=None): | ||
""" | ||
Build docker image | ||
""" | ||
|
@@ -714,6 +721,8 @@ def build(self): | |
bp.__class__.__name__, | ||
extra=dict(phase="building"), | ||
) | ||
if logfile: | ||
logfile.write("Using %s builder\n" % bp.__class__.__name__) | ||
|
||
for l in picked_buildpack.build( | ||
docker_client, | ||
|
@@ -725,8 +734,12 @@ def build(self): | |
): | ||
if "stream" in l: | ||
self.log.info(l["stream"], extra=dict(phase="building")) | ||
if logfile: | ||
logfile.write(l["stream"]) | ||
elif "error" in l: | ||
self.log.info(l["error"], extra=dict(phase="failure")) | ||
if logfile: | ||
logfile.write(l["error"]) | ||
raise docker.errors.BuildError(l["error"], build_log="") | ||
elif "status" in l: | ||
self.log.info( | ||
|
@@ -741,7 +754,35 @@ def build(self): | |
shutil.rmtree(checkout_path, ignore_errors=True) | ||
|
||
def start(self): | ||
self.build() | ||
logfile = None | ||
if ( | ||
self.s3_logs_endpoint | ||
and self.s3_logs_access_key | ||
and self.s3_logs_secret_key | ||
and self.s3_logs_bucket | ||
): | ||
logfile = tempfile.NamedTemporaryFile("w", delete=False) | ||
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. These builds logs have been useful in the past, maybe they should be kept anyway, even if not uploading to s3? |
||
try: | ||
self.build(logfile=logfile) | ||
finally: | ||
if logfile: | ||
logfile.close() | ||
if os.stat(logfile.name).st_size: | ||
dest = f"buildlogs/{self.output_image_spec}/repo2docker.log" | ||
self.log.info(f"Uploading log to {self.s3_logs_bucket}/{dest}") | ||
s3 = boto3.resource( | ||
"s3", | ||
endpoint_url=self.s3_logs_endpoint, | ||
aws_access_key_id=self.s3_logs_access_key, | ||
aws_secret_access_key=self.s3_logs_secret_key, | ||
config=boto3.session.Config(signature_version="s3v4"), | ||
region_name=self.s3_logs_region, | ||
) | ||
s3.Bucket(self.s3_logs_bucket).upload_file( | ||
logfile.name, | ||
manics marked this conversation as resolved.
Show resolved
Hide resolved
|
||
dest, | ||
ExtraArgs={"ContentType": "text/plain"}, | ||
) | ||
|
||
if self.push: | ||
self.push_image() | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.