Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ updates:
- "*"
# plugin base images
- package-ecosystem: "docker"
directory: "/.github/docker"
directory: "/baseimages"
schedule:
interval: "daily"
registries:
Expand Down
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,9 @@ If the `fetcher` command opens a PR for a new version of an existing plugin, mos

### Updating Docker Base Images

Docker base images are tracked in [.github/docker](.github/docker) and kept updated with Dependabot.
Docker base images are tracked in [baseimages](baseimages) and kept updated with Dependabot.
When new versions of a plugin are detected, they'll automatically be built with the latest base images.
When creating a new plugin, ensure that it starts with the latest version of the base image in the `.github/docker` directory.
When creating a new plugin, ensure that it starts with the latest version of the base image in the `baseimages` directory.

## Local Testing

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions internal/cmd/fetcher/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,12 +309,12 @@ func (m *mockFetcher) Fetch(_ context.Context, config *source.Config) (string, e
// setupTestRepository creates a complete test repository structure with:
// - plugins/ directory with base-plugin and consumer-plugin
// - source.yaml files for version detection
// - .github/docker/ directory with base images.
// - baseimages/ directory with base images.
func setupTestRepository(t *testing.T, tmpDir string) {
t.Helper()

// Create base Docker images directory (required by run())
baseImageDir := filepath.Join(tmpDir, ".github", "docker")
baseImageDir := filepath.Join(tmpDir, "baseimages")
require.NoError(t, os.MkdirAll(baseImageDir, 0755))

// Create required docker/dockerfile base image
Expand Down
20 changes: 10 additions & 10 deletions internal/docker/baseimage.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ var (
distrolessNamePrefix = "gcr.io/distroless/"
)

// BaseImages contains state about the latest versions of base images in the .github/docker directory.
// BaseImages contains state about the latest versions of base images in the baseimages directory.
// These are automatically kept up to date by dependabot.
type BaseImages struct {
latestVersions map[string]string
latestDistrolessImageNames map[string]string
}

// ImageNameAndVersion returns the latest image name and version (if tracked in the .github/docker directory).
// ImageNameAndVersion returns the latest image name and version (if tracked in the baseimages directory).
// For example, passing "debian" will return "debian:bookworm-yyyyMMdd" (where "yyyyMMdd" is the latest image date).
// If the image is not tracked in the .github/docker directory, returns an empty string.
// If the image is not tracked in the baseimages directory, returns an empty string.
// This is used to automate updating Dockerfile base image versions when fetching new versions of plugins.
func (b *BaseImages) ImageNameAndVersion(imageName string) string {
latestImageName := imageName
Expand All @@ -37,9 +37,9 @@ func (b *BaseImages) ImageNameAndVersion(imageName string) string {
return latestImageName + ":" + latestVersion
}

// ImageVersion returns the latest version for the image name (if tracked in the .github/docker directory).
// ImageVersion returns the latest version for the image name (if tracked in the baseimages directory).
// For example, passing "debian" will return "bookworm-yyyyMMdd" (where "yyyyMMdd" is the latest image date).
// If the image is not tracked in the .github/docker directory, returns an empty string.
// If the image is not tracked in the baseimages directory, returns an empty string.
func (b *BaseImages) ImageVersion(imageName string) string {
latestImageName := imageName
if nameWithoutVersions := distrolessImageNameWithoutVersions(imageName); nameWithoutVersions != "" {
Expand All @@ -48,30 +48,30 @@ func (b *BaseImages) ImageVersion(imageName string) string {
return b.latestVersions[latestImageName]
}

// FindBaseImageDir looks for the .github/docker folder starting from basedir.
// FindBaseImageDir looks for the baseimages folder starting from basedir.
// It continues to search through parent directories till found (or at the root).
func FindBaseImageDir(basedir string) (string, error) {
// Walk up from plugins dir to find .github dir
// Walk up from plugins dir to find the baseimages dir
rootDir, err := filepath.Abs(basedir)
if err != nil {
return "", err
}
var dockerDir string
for {
dockerDir = filepath.Join(rootDir, ".github", "docker")
dockerDir = filepath.Join(rootDir, "baseimages")
if st, err := os.Stat(dockerDir); err == nil && st.IsDir() {
break
}
newRootDir := filepath.Dir(rootDir)
if newRootDir == rootDir {
return "", fmt.Errorf("failed to find .github directory from %s", basedir)
return "", fmt.Errorf("failed to find baseimages directory from %s", basedir)
}
rootDir = newRootDir
}
return dockerDir, nil
}

// LoadLatestBaseImages returns the latest base image information from images found in the .github/docker directory.
// LoadLatestBaseImages returns the latest base image information from images found in the baseimages directory.
func LoadLatestBaseImages(baseImageDir string) (_ *BaseImages, retErr error) {
d, err := os.Open(baseImageDir)
if err != nil {
Expand Down
5 changes: 2 additions & 3 deletions internal/docker/baseimage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@ func TestFindBaseImageDir(t *testing.T) {
require.NoError(t, err)
assert.Equal(t, expectedAbs, baseImageDir)
}
expected := "../../.github/docker"
expected := "../../baseimages"
verifyDir(".", expected)
verifyDir("..", expected)
verifyDir("../..", expected)
verifyDir("../../.github", expected)
verifyDir("../../.github/docker", expected)
verifyDir("../../baseimages", expected)
}

func TestBaseImages(t *testing.T) {
Expand Down
Loading