Use random string as temporary tag

This commit is contained in:
Rutvij Mehta
2023-05-16 01:20:10 -07:00
parent adb2b6c2c0
commit 490a50eae0
4 changed files with 44 additions and 20 deletions
+18
View File
@@ -1,8 +1,10 @@
package main
import (
"math/rand"
"os"
"runtime"
"time"
"github.com/joho/godotenv"
"github.com/sirupsen/logrus"
@@ -14,6 +16,7 @@ import (
var (
version = "unknown"
charset = []byte("abcdefghijklmnopqrstuvwxyz")
)
func main() {
@@ -318,6 +321,7 @@ func run(c *cli.Context) error {
Build: docker.Build{
Remote: c.String("remote.url"),
Name: c.String("commit.sha"),
TempTag: generateTempTag(),
Dockerfile: c.String("dockerfile"),
Context: c.String("context"),
Tags: c.StringSlice("tags"),
@@ -383,6 +387,20 @@ func run(c *cli.Context) error {
return plugin.Exec()
}
func generateTempTag() string {
tagLength := 8
return randomString(tagLength)
}
func randomString(n int) string {
rand.Seed(time.Now().UTC().UnixNano())
b := make([]byte, n)
for i := range b {
b[i] = charset[rand.Intn(len(charset))]
}
return string(b)
}
func GetExecCmd() string {
if runtime.GOOS == "windows" {
return "C:/bin/drone-docker.exe"