Skip to content

Commit

Permalink
Add Installation Command
Browse files Browse the repository at this point in the history
  • Loading branch information
amanvr committed May 24, 2023
1 parent 04e43fe commit 2bb9cf2
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion assets/docker/Dockerfile.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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 ./...

Expand Down
2 changes: 1 addition & 1 deletion assets/docker/Dockerfile.node.tmpl
Original file line number Diff line number Diff line change
@@ -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

Expand Down
23 changes: 23 additions & 0 deletions src/services/project/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -77,3 +78,25 @@ func (proj Project) Dockerfile() ([]byte, error) {

return content, 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
}

0 comments on commit 2bb9cf2

Please sign in to comment.