diff --git a/assets/docker/Dockerfile.go.tmpl b/assets/docker/Dockerfile.go.tmpl index 115fd18..9b0c2e4 100644 --- a/assets/docker/Dockerfile.go.tmpl +++ b/assets/docker/Dockerfile.go.tmpl @@ -3,7 +3,7 @@ FROM golang:{{ or .RuntimeVersion .DefaultRuntimeVersion }} as build WORKDIR /go/src/app COPY . . -RUN go mod download +RUN {{ .InstallCommand }} RUN go vet -v ./... RUN go test -v ./... diff --git a/assets/docker/Dockerfile.node.tmpl b/assets/docker/Dockerfile.node.tmpl index db8fd67..f645ccb 100644 --- a/assets/docker/Dockerfile.node.tmpl +++ b/assets/docker/Dockerfile.node.tmpl @@ -1,7 +1,7 @@ FROM node:{{ or .RuntimeVersion .DefaultRuntimeVersion }} AS build-env COPY . /src WORKDIR /src -RUN npm i +RUN {{ .InstallCommand }} RUN npm run build --if-present RUN npm test diff --git a/src/services/project/project.go b/src/services/project/project.go index 373f94a..9ee79c6 100644 --- a/src/services/project/project.go +++ b/src/services/project/project.go @@ -4,6 +4,7 @@ import ( "bytes" "fmt" "github.com/nearform/k8s-kurated-addons-cli/src/utils/defaults" + "github.com/nearform/k8s-kurated-addons-cli/src/utils/logger" "io/fs" "os" "path" @@ -112,3 +113,25 @@ func ProjectInit(options InitOptions, resources fs.FS) ([]string, error) { return append(returnData, destinationFile), nil } + +func (proj Project) InstallCommand() string { + projectType, err := proj.detectType() + if err != nil { + logger.PrintError("Type not found", err) + } + + installCommand := "npm i" + + switch projectType { + case NodeProject: + if _, err := os.Stat(path.Join(proj.Directory, "package-lock.json")); err == nil { + installCommand = "npm cli" + } + case GoProject: + installCommand = "go mod download" + default: + logger.PrintError("Unable to determine install command", nil) + } + + return installCommand +}