Skip to content

Commit

Permalink
Docker: add ALPINE.txt to manage alpine versions
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
Maisem Ali authored and maisem committed Jun 29, 2022
1 parent cfa484e commit 88133c3
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 0 deletions.
1 change: 1 addition & 0 deletions ALPINE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.16
5 changes: 5 additions & 0 deletions cmd/printdep/printdep.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,15 @@ import (
var (
goToolchain = flag.Bool("go", false, "print the supported Go toolchain git hash (a github.com/tailscale/go commit)")
goToolchainURL = flag.Bool("go-url", false, "print the URL to the tarball of the Tailscale Go toolchain")
alpine = flag.Bool("alpine", false, "print the tag of alpine docker image")
)

func main() {
flag.Parse()
if *alpine {
fmt.Println(strings.TrimSpace(ts.AlpineDockerTag))
return
}
if *goToolchain {
fmt.Println(strings.TrimSpace(ts.GoToolchainRev))
}
Expand Down
3 changes: 3 additions & 0 deletions version-embed.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import _ "embed"
//go:embed VERSION.txt
var Version string

//go:embed ALPINE.txt
var AlpineDockerTag string

// GoToolchainRev is the git hash from github.com/tailscale/go that this release
// should be built using. It may end in a newline.
//
Expand Down
42 changes: 42 additions & 0 deletions version/version_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright (c) 2022 Tailscale Inc & AUTHORS All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package version

import (
"bytes"
"os"
"testing"

ts "tailscale.com"
)

func TestAlpineTag(t *testing.T) {
if tag := readAlpineTag(t, "../Dockerfile.base"); tag == "" {
t.Fatal(`"FROM alpine:" not found in Dockerfile.base`)
} else if tag != ts.AlpineDockerTag {
t.Errorf("alpine version mismatch: Dockerfile.base has %q; ALPINE.txt has %q", tag, ts.AlpineDockerTag)
}
if tag := readAlpineTag(t, "../Dockerfile"); tag == "" {
t.Fatal(`"FROM alpine:" not found in Dockerfile`)
} else if tag != ts.AlpineDockerTag {
t.Errorf("alpine version mismatch: Dockerfile has %q; ALPINE.txt has %q", tag, ts.AlpineDockerTag)
}
}

func readAlpineTag(t *testing.T, file string) string {
f, err := os.ReadFile(file)
if err != nil {
t.Fatal(err)
}
for _, line := range bytes.Split(f, []byte{'\n'}) {
line = bytes.TrimSpace(line)
_, suf, ok := bytes.Cut(line, []byte("FROM alpine:"))
if !ok {
continue
}
return string(suf)
}
return ""
}

0 comments on commit 88133c3

Please sign in to comment.