Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: unable to build multigroup projects #1507

Merged
merged 1 commit into from
May 29, 2020
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
39 changes: 38 additions & 1 deletion pkg/scaffold/edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ limitations under the License.
package scaffold

import (
"fmt"
"io/ioutil"
"strings"

"sigs.k8s.io/kubebuilder/pkg/model/config"
)

Expand All @@ -38,5 +42,38 @@ func NewEditScaffolder(config *config.Config, multigroup bool) Scaffolder {
// Scaffold implements Scaffolder
func (s *editScaffolder) Scaffold() error {
s.config.MultiGroup = s.multigroup
return nil
filename := "Dockerfile"
bs, err := ioutil.ReadFile(filename)
if err != nil {
return err
}
str := string(bs)

// update dockerfile
if s.multigroup {
str, err = ensureExistAndReplace(
str,
"COPY api/ api/",
`COPY apis/ apis/`)
if err != nil {
return err
}
} else {
str, err = ensureExistAndReplace(
str,
"COPY apis/ apis/",
`COPY api/ api/`)
if err != nil {
return err
}
}

return ioutil.WriteFile(filename, []byte(str), 0644)
}

func ensureExistAndReplace(input, match, replace string) (string, error) {
if !strings.Contains(input, match) {
return "", fmt.Errorf("can't find %q", match)
}
return strings.Replace(input, match, replace, -1), nil
}
2 changes: 1 addition & 1 deletion testdata/project-v2-multigroup/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ RUN go mod download

# Copy the go source
COPY main.go main.go
COPY api/ api/
COPY apis/ apis/
COPY controllers/ controllers/

# Build
Expand Down
2 changes: 1 addition & 1 deletion testdata/project-v3-multigroup/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ RUN go mod download

# Copy the go source
COPY main.go main.go
COPY api/ api/
COPY apis/ apis/
COPY controllers/ controllers/

# Build
Expand Down