-
Notifications
You must be signed in to change notification settings - Fork 324
fix: Use unique build name for build and tag #390
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
fix: Use unique build name for build and tag #390
Conversation
docker.go
Outdated
| return "", errors.New("unable to fetch digest") | ||
| } | ||
|
|
||
| func getUniqueBuildName(repo, buildName string) string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if build is triggered for a run without git clone?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved away from this approach. We now generate a temporary tag using a random string.
|
Looks good. I would recommend one minor change. I would recommend using import "crypto/rand"
// random generates a random string
func random() string {
result := make([]rune, 32)
runes := []rune("0123456789abcdef")
x := int64(len(runes))
for i := range result {
num, err := rand.Int(rand.Reader, big.NewInt(x))
if err != nil {
panic("error creating random number") // should never happen
}
result[i] = runes[num.Int64()]
}
return string(result)
}alternatively you can use a library that handles this. In other Drone projects we use the below library since it is lightweight and feature complete, with zero external dependencies: import "github.com/dchest/uniuri"
s := uniuri.New() |
|
Thanks @bradrydzewski for the review. I've used |
Bug:
Created 2 dockerfiles where we set the below environment variables and built them in parallel:
testimg:1.0:ENV GOPATH=$HOME/gotestimg2:2.0:ENV GOPATH=$HOME/go2Parallel Step 1:

Parallel Step 2:

Reproduced the bug where both testimg and testimg2 were the same (since the environment variable set was the same) after they were built. Ideally the should be different:
Commands used:
testimg:1.0:docker run --name=testcontainer1 rutvijspit/testimg:1.0docker exec testcontainer1 sh -c /usr/bin/env | grep GOPATHtestimg2:2.0:docker run --name=testcontainer2 rutvijspit/testimg2:2.0docker exec testcontainer2 sh -c /usr/bin/env | grep GOPATHAfter the fix:
Parallel Step 1:

Parallel Step 2:

Verification that different environement variable is set:
