Skip to content

Commit 88133c3

Browse files
Maisem Alimaisem
Maisem Ali
authored andcommittedJun 29, 2022
Docker: add ALPINE.txt to manage alpine versions
The goal here is to 1. make it so that the number doesn't diverge between the various places we had it defined 2. not define the number in corp, only in oss Signed-off-by: Maisem Ali <[email protected]>
1 parent cfa484e commit 88133c3

File tree

4 files changed

+51
-0
lines changed

4 files changed

+51
-0
lines changed
 

‎ALPINE.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.16

‎cmd/printdep/printdep.go

+5
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,15 @@ import (
1919
var (
2020
goToolchain = flag.Bool("go", false, "print the supported Go toolchain git hash (a github.com/tailscale/go commit)")
2121
goToolchainURL = flag.Bool("go-url", false, "print the URL to the tarball of the Tailscale Go toolchain")
22+
alpine = flag.Bool("alpine", false, "print the tag of alpine docker image")
2223
)
2324

2425
func main() {
2526
flag.Parse()
27+
if *alpine {
28+
fmt.Println(strings.TrimSpace(ts.AlpineDockerTag))
29+
return
30+
}
2631
if *goToolchain {
2732
fmt.Println(strings.TrimSpace(ts.GoToolchainRev))
2833
}

‎version-embed.go

+3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ import _ "embed"
1010
//go:embed VERSION.txt
1111
var Version string
1212

13+
//go:embed ALPINE.txt
14+
var AlpineDockerTag string
15+
1316
// GoToolchainRev is the git hash from github.com/tailscale/go that this release
1417
// should be built using. It may end in a newline.
1518
//

‎version/version_test.go

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright (c) 2022 Tailscale Inc & AUTHORS All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package version
6+
7+
import (
8+
"bytes"
9+
"os"
10+
"testing"
11+
12+
ts "tailscale.com"
13+
)
14+
15+
func TestAlpineTag(t *testing.T) {
16+
if tag := readAlpineTag(t, "../Dockerfile.base"); tag == "" {
17+
t.Fatal(`"FROM alpine:" not found in Dockerfile.base`)
18+
} else if tag != ts.AlpineDockerTag {
19+
t.Errorf("alpine version mismatch: Dockerfile.base has %q; ALPINE.txt has %q", tag, ts.AlpineDockerTag)
20+
}
21+
if tag := readAlpineTag(t, "../Dockerfile"); tag == "" {
22+
t.Fatal(`"FROM alpine:" not found in Dockerfile`)
23+
} else if tag != ts.AlpineDockerTag {
24+
t.Errorf("alpine version mismatch: Dockerfile has %q; ALPINE.txt has %q", tag, ts.AlpineDockerTag)
25+
}
26+
}
27+
28+
func readAlpineTag(t *testing.T, file string) string {
29+
f, err := os.ReadFile(file)
30+
if err != nil {
31+
t.Fatal(err)
32+
}
33+
for _, line := range bytes.Split(f, []byte{'\n'}) {
34+
line = bytes.TrimSpace(line)
35+
_, suf, ok := bytes.Cut(line, []byte("FROM alpine:"))
36+
if !ok {
37+
continue
38+
}
39+
return string(suf)
40+
}
41+
return ""
42+
}

0 commit comments

Comments
 (0)
Please sign in to comment.