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

Allow BUILD_ID to be set using generateBuildId (minor) #3873

Merged
merged 5 commits into from
Mar 31, 2018

Conversation

craigmcnamara
Copy link

@craigmcnamara craigmcnamara commented Feb 22, 2018

Fixes #786

This makes multi server deploys with Capistrano possible.

I couldn't see a place to add tests for a thing like this, but I'm happy to if you point the way.

@arunoda
Copy link
Contributor

arunoda commented Feb 23, 2018

@craigmcnamara thanks for this.
I see the validity of this.

I think it's better to get this via next.config.js. Could you modify your PR?

@craigmcnamara
Copy link
Author

I'm happy to rework this. Thanks for the feedback.

@@ -8,7 +8,7 @@ import md5File from 'md5-file/promise'

export default async function build (dir, conf = null) {
const config = getConfig(dir, conf)
const buildId = uuid.v4()
const buildId = process.env.BUILD_ID || uuid.v4()
Copy link
Member

@timneutkens timneutkens Feb 24, 2018

Choose a reason for hiding this comment

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

Lets do it like this:

let buildId
if(typeof config.generateBuildId === 'function') {
  buildId = await config.generateBuildId() // `await` so that it can be an async function
} else {
  buildId = uuid.v4()
}

This will allow the user to generate the buildId in whatever way they like, because you can do something async to get the buildId, like reading from the filesystem or fetching from some api.

Copy link
Member

Choose a reason for hiding this comment

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

Lets also add an integration test for this case.

This makes multi server deploys with Capistrano possible.
@bessey
Copy link

bessey commented Mar 2, 2018

(I work with @craigmcnamara) I have updated the PR as suggested. I couldn't find a comparable test that asserts config behaviour, so was unable to write a test that asserts this works. All I know is it doesn't crash, which isn't really enough, I admit.

That said, now that I'm more familiar with this code, it seems odd to me that the default implementation is not stable. Is it unreasonable to default to generating an ID by hashing the contents of the project directory? There seem to be some quite small existing libraries that tackle this concern.

enable customising the build id via config
@lukasz-karolewski
Copy link

it would be very much desired to get build_id based on contents of source (everything in current directory) this will make docker builds more predictable, this becomes an issue when used with CDN

@raffij
Copy link

raffij commented Mar 15, 2018

We’d like to see this completed and merged to for deployment purposes. Rather than relying on sticky sessions.

Our first thought was using build_id from the git hash.

@timneutkens
Copy link
Member

Made some improvements, going to merge when the tests pass.

@timneutkens timneutkens changed the title Allow BUILD_ID to be set in the environment Allow BUILD_ID to be set using generateBuildId (minor) Mar 31, 2018
@timneutkens timneutkens merged commit 7f335cb into vercel:canary Mar 31, 2018
@lock lock bot locked as resolved and limited conversation to collaborators Mar 31, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants