mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Chore: Add Dockerfile CI check for new modules (#92239)
This commit is contained in:
parent
a86ded2438
commit
e4953b6ffd
2
.github/workflows/pr-go-workspace-check.yml
vendored
2
.github/workflows/pr-go-workspace-check.yml
vendored
@ -31,3 +31,5 @@ jobs:
|
||||
echo "If there is a change in enterprise dependencies, please update pkg/extensions/main.go."
|
||||
exit 1
|
||||
fi
|
||||
- name: Ensure Dockerfile contains submodule COPY commands
|
||||
run: ./scripts/go-workspace/validate-dockerfile.sh
|
@ -19,6 +19,8 @@ func main() {
|
||||
switch os.Args[1] {
|
||||
case "list-submodules":
|
||||
err = listSubmodules()
|
||||
case "validate-dockerfile":
|
||||
err = validateDockerfile()
|
||||
default:
|
||||
printUsage()
|
||||
}
|
||||
@ -40,7 +42,9 @@ func listSubmodules() error {
|
||||
delimiter := fs.String("delimiter", "\n", "Delimiter to use when printing paths")
|
||||
skip := fs.String("skip", "", "Skip submodules with this comment tag")
|
||||
help := fs.Bool("help", false, "Print help message")
|
||||
fs.Parse(os.Args[2:])
|
||||
if err := fs.Parse(os.Args[2:]); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if *help {
|
||||
fs.Usage()
|
||||
@ -60,6 +64,41 @@ func listSubmodules() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func validateDockerfile() error {
|
||||
fs := flag.NewFlagSet("validate-dockerfile", flag.ExitOnError)
|
||||
workPath := fs.String("path", "go.work", "Path to go.work")
|
||||
dockerfilePath := fs.String("dockerfile-path", "Dockerfile", "Path to Dockerfile")
|
||||
skip := fs.String("skip", "", "Skip submodules with this comment tag")
|
||||
if err := fs.Parse(os.Args[2:]); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
dockerFileRaw, err := os.ReadFile(*dockerfilePath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
dockerFile := string(dockerFileRaw)
|
||||
|
||||
workfile, err := parseGoWork(*workPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
paths := getSubmodulePaths(workfile, *skip)
|
||||
for _, p := range paths {
|
||||
path := strings.TrimPrefix(p, "./")
|
||||
if path == "" || path == "." {
|
||||
continue
|
||||
}
|
||||
if !strings.Contains(dockerFile, path) {
|
||||
return fmt.Errorf("the Dockerfile is missing `COPY %s/go.* %s` for the related module. Please add it and commit the change.", path, path)
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Println("All submodules are included in the Dockerfile.")
|
||||
return nil
|
||||
}
|
||||
|
||||
func getSubmodulePaths(wf *modfile.WorkFile, skip string) []string {
|
||||
var paths []string
|
||||
for _, d := range wf.Use {
|
||||
|
8
scripts/go-workspace/validate-dockerfile.sh
Executable file
8
scripts/go-workspace/validate-dockerfile.sh
Executable file
@ -0,0 +1,8 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -o errexit
|
||||
set -o nounset
|
||||
set -o pipefail
|
||||
|
||||
REPO_ROOT=$(dirname "${BASH_SOURCE[0]}")/../..
|
||||
go run scripts/go-workspace/main.go validate-dockerfile --path "${REPO_ROOT}/go.work" --dockerfile-path "${REPO_ROOT}/Dockerfile"
|
Loading…
Reference in New Issue
Block a user