Skip to content

Commit

Permalink
Add --no-port-detection flag to compose command (#19)
Browse files Browse the repository at this point in the history
* Add --no-port-detection arg

Signed-off-by: thepetk <thepetk@gmail.com>

* Add test cases for no-port-detection arg

Signed-off-by: thepetk <thepetk@gmail.com>

* Update documentation

Signed-off-by: thepetk <thepetk@gmail.com>

* Add func in library for skiping port detection

Signed-off-by: thepetk <thepetk@gmail.com>

* Mock detectComponentsWithPathAndPortStartegy

Signed-off-by: thepetk <thepetk@gmail.com>

* Add simple test case for DetectComponentsWithoutPortDetection

Signed-off-by: thepetk <thepetk@gmail.com>

* Add tests for detectComponentsWithSettings

Signed-off-by: thepetk <thepetk@gmail.com>

* Add more test cases for component detection

Signed-off-by: thepetk <thepetk@gmail.com>

* Revert global var detectComponentsWithPathAndPortStartegy

Signed-off-by: thepetk <thepetk@gmail.com>

* Update tests

Signed-off-by: thepetk <thepetk@gmail.com>

* Add extra test cases

Signed-off-by: thepetk <thepetk@gmail.com>

* Add extra test cases

Signed-off-by: thepetk <thepetk@gmail.com>

---------

Signed-off-by: thepetk <thepetk@gmail.com>
  • Loading branch information
thepetk authored Aug 22, 2023
1 parent 8cd7239 commit 27607db
Show file tree
Hide file tree
Showing 6 changed files with 543 additions and 2 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ $ go build alizer.go

```sh
--log {debug|info|warning} sets the logging level of the CLI. The arg accepts only 3 values [`debug`, `info`, `warning`]. The default value is `warning` and the logging level is `ErrorLevel`.
--no-port-detection if this flag exists then no port detection is applied on the given application. If this flag doesn't exist then we are applying port detection as normal. In case we have both --no-port-detection and --port-detection the --no-port-detection overrides everything.
--port-detection {docker|compose|source} port detection strategy to use when detecting a port. Currently supported strategies are 'docker', 'compose' and 'source'. You can pass more strategies at the same time. They will be executed in order. By default Alizer will execute docker, compose and source.
```
**Deprecation Warning:** The `--port-detection` flag soon will be deprecated.
#### alizer devfile
Expand Down Expand Up @@ -84,7 +86,11 @@ It detects all components which are found in the source tree where each componen
```go
import "github.com/devfile/alizer/pkg/apis/recognizer"
// In case port detection is needed.
components, err := recognizer.DetectComponents("your/project/path")
// If there is no need for port detection
components, err := recognizer.DetectComponentsWithoutPortDetection("your/project/path")
```
For more info about name detection, see the [name detection](docs/public/name_detection.md) doc.
Expand Down
2 changes: 2 additions & 0 deletions docs/public/port_detection.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

Port detection is one of the step included during component detection and it refers to the ports used by the component that should be opened in the container. Because of the different nature of frameworks supported, Alizer tries to use customized ways to detect ports from source code, if necessary. **Only ports with value > 0 and < 65535 are valid**

**Deprecation Warning:** The port detection strategies will be removed in the future releases of alizer.

There are three detection strategies currently available:
1) Docker file - Alizer looks for a Dockerfile, or Containerfile, in the root folder and tries to extract ports from it.
2) Compose file - Alizer searches for a docker-compose file in the root folder and tries to extract port of the service from it
Expand Down
5 changes: 5 additions & 0 deletions pkg/apis/recognizer/component_recognizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ func DetectComponents(path string) ([]model.Component, error) {
return detectComponentsWithPathAndPortStartegy(path, []model.PortDetectionAlgorithm{model.DockerFile, model.Compose, model.Source}, &ctx)
}

func DetectComponentsWithoutPortDetection(path string) ([]model.Component, error) {
ctx := context.Background()
return detectComponentsWithPathAndPortStartegy(path, []model.PortDetectionAlgorithm{}, &ctx)
}

func DetectComponentsInRootWithPathAndPortStartegy(path string, portDetectionStrategy []model.PortDetectionAlgorithm) ([]model.Component, error) {
ctx := context.Background()
return detectComponentsInRootWithPathAndPortStartegy(path, portDetectionStrategy, &ctx)
Expand Down
Loading

0 comments on commit 27607db

Please sign in to comment.