Skip to content

Commit d27a005

Browse files
thepetkrm3l
andauthored
Proposal for Devfile port detection and default ports support (#33)
* Add release version to release.yaml Signed-off-by: thepetk <thepetk@gmail.com> * Add .exe extension for windows architecture Signed-off-by: thepetk <thepetk@gmail.com> * Create proposal for devfile port and default port detection Signed-off-by: thepetk <thepetk@gmail.com> * Update docs/proposals/devfile_and_default_ports_detection.md Signed-off-by: thepetk <thepetk@gmail.com> Co-authored-by: Armel Soro <armel@rm3l.org> Signed-off-by: thepetk <thepetk@gmail.com> * Clarify type of detected devfile ports Signed-off-by: thepetk <thepetk@gmail.com> * Update proposal Signed-off-by: thepetk <thepetk@gmail.com> * Update docs/proposals/devfile_and_default_ports_detection.md Signed-off-by: thepetk <thepetk@gmail.com> Co-authored-by: Armel Soro <armel@rm3l.org> Signed-off-by: thepetk <thepetk@gmail.com> --------- Signed-off-by: thepetk <thepetk@gmail.com> Co-authored-by: Armel Soro <armel@rm3l.org>
1 parent b3ac16d commit d27a005

File tree

1 file changed

+93
-0
lines changed

1 file changed

+93
-0
lines changed
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# Devfile port detection & default ports
2+
3+
## Related Github Issues
4+
5+
- https://github.com/devfile/api/issues/1154
6+
7+
## Background
8+
In order to perform port detection component-wise, `alizer` is performing different strategies of port detection per component. Currently, we support 3 different strategies:
9+
10+
* Dockerfile Port Detection
11+
* Docker Compose Port Detection
12+
* Source Code Port Detection
13+
14+
At the moment, `alizer` doesn't support port detection from `devfile.y(a)ml` files. This means that all ports defined inside a file like this will not be included in alizer's response. _As a result, the first goal of this proposal is to include the devfiles as part of the port detection algorithm_, exactly like `dockerfile` and `compose`.
15+
16+
On the other hand, right now `alizer` is not returning any default ports of detected frameworks. As a result, for every component using a framework that has default ports, alizer will not include them in its response even if we haven't detected any ports from our strategies (ports list is empty). That said, as a second goal of this proposal, we would like to add a new feature in alizer that will include default ports in alizer's response.
17+
18+
## Devfile Port Detection
19+
For devfile port detection we should follow the same flow with dockerfile:
20+
21+
1. Create a function that will:
22+
* look for a devfile inside a given component (The `utils.GetLocations` function should be updated to support devfiles too).
23+
* It will also find all ports defined in `components.kubernetes.endpoints` & `components.container.endpoints`.
24+
25+
```go
26+
// GetPortsFromDevfile returns a slice of port numbers from Devfile in the given directory.
27+
func GetPortsFromDevfile(root string) []int {
28+
locations := utils.GetLocations(root)
29+
for _, location := range locations {
30+
31+
return utils.ReadPortsFromDevfile(file)
32+
}
33+
return []int{}
34+
}
35+
```
36+
37+
2. Create a new `const` inside `model/model.go`:
38+
```go
39+
const Devfile PortDetectionAlgorithm = 3
40+
```
41+
42+
3. Add a new algorithm case to the following enricher DoEnrichComponent functions:
43+
```
44+
dotnet_enricher.go
45+
go_enricher.go
46+
java_enricher.go
47+
javascript_enricher.go
48+
php_enricher.go
49+
python_enricher.go
50+
```
51+
52+
Following those steps will add support for devfile port detection for every component that we will be able to detect.
53+
54+
## Default Ports
55+
In order to support default ports for port detection we will need to complete the following steps:
56+
57+
1. We will need to define a new flag `--add-default-ports` inside the `component` command. This way someone can set that they would like to have a response which will include default ports.
58+
59+
2. For every `framework` that we detect we should investigate if it uses any ports by default. After the investigation every `detector` should have the following function:
60+
```go
61+
func (d LaravelDetector) GetDefaultPorts() []string {
62+
return []int{8080}
63+
}
64+
```
65+
66+
3. Upon `DoPortsDetection` the default ports should be added in the end of the `ports` array in alizer's response:
67+
68+
```json
69+
// default ports = 3000, 3001
70+
71+
// Case1: Only default ports where returned
72+
[
73+
{
74+
"Name": "example-project",
75+
"Path": "/path/to/example-project/",
76+
"Languages": [...],
77+
"Ports": [3000, 3001]
78+
}
79+
]
80+
81+
// Case2: Ports 2001, 2002 are detected for example-project
82+
[
83+
{
84+
"Name": "example-project",
85+
"Path": "/path/to/example-project/",
86+
"Languages": [...],
87+
"Ports": [2001, 2002, 3000, 3001]
88+
}
89+
]
90+
91+
```
92+
93+
_In case the `--add-default-ports` is not set the default value will be `false`_

0 commit comments

Comments
 (0)