Skip to content
This repository was archived by the owner on May 6, 2020. It is now read-only.

feat(api): inject release metadata into application#1080

Merged
bacongobbler merged 1 commit intodeis:masterfrom
bacongobbler:1057-add-source-version
Sep 20, 2016
Merged

feat(api): inject release metadata into application#1080
bacongobbler merged 1 commit intodeis:masterfrom
bacongobbler:1057-add-source-version

Conversation

@bacongobbler
Copy link
Copy Markdown
Member

closes #1057

rebased off of #1078 for the _build_env_vars tests, see e88c52f for the new commit.

@deis-bot
Copy link
Copy Markdown

@helgi, @kmala and @Joshua-Anderson are potential reviewers of this pull request based on my analysis of git blame information. Thanks @bacongobbler!

@bacongobbler bacongobbler changed the title 1057 add source version feat(api): inject SOURCE_VERSION into application environment Sep 16, 2016
@helgi
Copy link
Copy Markdown
Contributor

helgi commented Sep 16, 2016

Is this what the ticket that was created asked for? Thought there was a workflow prefix and all?

@bacongobbler
Copy link
Copy Markdown
Member Author

Given deis/builder#418 and Heroku both use SOURCE_VERSION it makes sense to use that convention. I can add the other environment variables here, one sec

@helgi
Copy link
Copy Markdown
Contributor

helgi commented Sep 16, 2016

Ah is that the only one that was not prefixed? Sounds good

Comment thread rootfs/api/models/app.py
port = release.get_port()
if port:
default_env['PORT'] = port
default_env['PORT'] = port
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any specific reason for this change or just a clean up

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the rebased commit from #1078, but essentially this is cleanup from dead code. get_port used to return a NoneType if the port didn't exist; now it just raises a DeisException or a numerical value so we don't need this check any more

@bacongobbler bacongobbler force-pushed the 1057-add-source-version branch from e88c52f to ddfab9b Compare September 16, 2016 21:00
@codecov-io
Copy link
Copy Markdown

codecov-io commented Sep 16, 2016

Current coverage is 87.12% (diff: 100%)

Merging #1080 into master will increase coverage by <.01%

@@             master      #1080   diff @@
==========================================
  Files            42         42          
  Lines          3601       3603     +2   
  Methods           0          0          
  Messages          0          0          
  Branches        609        610     +1   
==========================================
+ Hits           3137       3139     +2   
  Misses          307        307          
  Partials        157        157          

Powered by Codecov. Last update ad182b2...096948f

@bacongobbler bacongobbler changed the title feat(api): inject SOURCE_VERSION into application environment feat(api): inject release metadata into application Sep 16, 2016
@bacongobbler bacongobbler force-pushed the 1057-add-source-version branch from ddfab9b to e3f4d33 Compare September 16, 2016 21:04
Comment thread rootfs/api/models/app.py
default_env['BUILDER_STORAGE'] = settings.APP_STORAGE
default_env['DEIS_MINIO_SERVICE_HOST'] = settings.MINIO_HOST
default_env['DEIS_MINIO_SERVICE_PORT'] = settings.MINIO_PORT
default_env['SOURCE_VERSION'] = release.build.sha
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we check for sha and add as environment as it is available even for dockerfile apps

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, that's not a bad idea.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI this is done now

@bacongobbler bacongobbler force-pushed the 1057-add-source-version branch 3 times, most recently from 7d8ba06 to 096948f Compare September 18, 2016 22:17
@bacongobbler bacongobbler force-pushed the 1057-add-source-version branch from 096948f to 644d3df Compare September 19, 2016 06:23
@kmala kmala added the LGTM1 label Sep 19, 2016
@ultimateboy
Copy link
Copy Markdown
Member

Seems like we should add these new vars to the test here: https://github.com/deis/controller/blob/master/rootfs/api/tests/test_app.py#L585

@bacongobbler
Copy link
Copy Markdown
Member Author

They have been added! See the changes to test_app.py in this PR. :)

Comment thread rootfs/api/models/app.py
'WORKFLOW_RELEASE': 'v{}'.format(release.version),
'WORKFLOW_RELEASE_SUMMARY': release.summary,
'WORKFLOW_RELEASE_CREATED_AT': str(release.created.strftime(
settings.DEIS_DATETIME_FORMAT))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to go through strftime? Just curious since we set the format already for DRF so I'd expect it to translate it for us when we do str() on it, but maybe not?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it does because we do it elsewhere in the codebase. DRF just handles it in the serializer, I think.

@helgi
Copy link
Copy Markdown
Contributor

helgi commented Sep 20, 2016

Did we consider the ambiguousness that was brought up in #1057 and what was the final decision? I see we only cover the SOURCE_VERSION story when sha is available

@bacongobbler
Copy link
Copy Markdown
Member Author

bacongobbler commented Sep 20, 2016

Did we consider the ambiguousness that was brought up in #1057 and what was the final decision? I see we only cover the SOURCE_VERSION story when sha is available

With this pr we now cover WORKFLOW_RELEASE_SUMMARY, WORKFLOW_RELEASE_CREATED_AT and SOURCE_VERSION which is WORKFLOW_RELEASE_HASH. I didn't bother with WORKFLOW_RELEASE_HASH because SOURCE_VERSION already has that data.

@bacongobbler bacongobbler merged commit f5d1454 into deis:master Sep 20, 2016
@bacongobbler bacongobbler deleted the 1057-add-source-version branch September 20, 2016 23:21
@felixbuenemann
Copy link
Copy Markdown
Contributor

@bacongobbler Thanks for implementing this!

So for docker image deploys I would have to set SOURCE_VERSION when building the image, right?

@bacongobbler
Copy link
Copy Markdown
Member Author

Yep!

@bacongobbler
Copy link
Copy Markdown
Member Author

Wait no. If you're using Dockerfile or buildpack deploys the environment variable will be injected into your environment.

@felixbuenemann
Copy link
Copy Markdown
Contributor

felixbuenemann commented Sep 21, 2016

@bacongobbler Docker image != Dockerfile =) So with "docker image deploys" I was talking about deis pull deploys.

@bacongobbler
Copy link
Copy Markdown
Member Author

Okay then yes if you're using deis pull you'll have to inject that into the environment yourself because we don't have any git metadata to derive the sha from in deis pull. The only information we have is the image and the release summary.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Proposal: Add Release Data to Pod Environment

7 participants