Created
December 3, 2017 17:04
-
-
Save cdpb/ac2c14b02302fbe91f042ba4cc2039b5 to your computer and use it in GitHub Desktop.
Generate useless random docker names and make it available via http
This file contains 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
FROM alpine | |
COPY names-generator / | |
EXPOSE 8080 | |
CMD ["/names-generator"] |
This file contains 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_names-generator.go 2017-12-03 20:28:56.062210047 +0400 | |
+++ names-generator.go 2017-12-03 20:53:53.961410371 +0400 | |
@@ -1,8 +1,10 @@ | |
-package namesgenerator | |
+package main | |
import ( | |
"fmt" | |
"math/rand" | |
+ "time" | |
+ "net/http" | |
) | |
var ( | |
@@ -606,7 +608,9 @@ | |
// integer between 0 and 10 will be added to the end of the name, e.g `focused_turing3` | |
func GetRandomName(retry int) string { | |
begin: | |
- name := fmt.Sprintf("%s_%s", left[rand.Intn(len(left))], right[rand.Intn(len(right))]) | |
+ s1 := rand.NewSource(time.Now().UnixNano()) | |
+ r1 := rand.New(s1) | |
+ name := fmt.Sprintf("%s_%s", left[r1.Intn(len(left))], right[r1.Intn(len(right))]) | |
if name == "boring_wozniak" /* Steve Wozniak is not boring */ { | |
goto begin | |
} | |
@@ -616,3 +620,22 @@ | |
} | |
return name | |
} | |
+ | |
+func rootHandler(w http.ResponseWriter, r *http.Request) { | |
+ w.Header().Set("Content-Type", "text/html") | |
+ w.WriteHeader(http.StatusOK) | |
+ fmt.Fprintln(w, string("<ul>")) | |
+ i := 1 | |
+ for i <= 5 { | |
+ data := GetRandomName(0) | |
+ fmt.Fprintln(w, string(fmt.Sprintf(" <li> %s </li>", data))) | |
+ i = i +1 | |
+ } | |
+ fmt.Fprintln(w, string("</ul>")) | |
+} | |
+ | |
+ | |
+func main() { | |
+ http.HandleFunc("/", rootHandler) | |
+ http.ListenAndServe(":8080", nil) | |
+} |
This file contains 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
#!/bin/bash | |
pushd /mnt/docker/name_generate/code | |
curl -o original_names-generator.go -s https://raw.githubusercontent.com/moby/moby/master/pkg/namesgenerator/names-generator.go | |
patch original_names-generator.go patch | |
mv original_names-generator.go names-generator.go | |
docker run -it -v "$PWD":/usr/src/names-generator -w /usr/src/names-generator golang:alpine go build -v | |
popd |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment