forked from devfile/alizer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding support for dockerfile components (#14)
Signed-off-by: Michael Hoang <[email protected]> Signed-off-by: thepetk <[email protected]>
- Loading branch information
1 parent
f2b97bf
commit 24b52f5
Showing
43 changed files
with
1,032 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// | ||
// Copyright 2023 Red Hat, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package enricher | ||
|
||
import ( | ||
"context" | ||
"github.com/devfile/alizer/pkg/apis/model" | ||
) | ||
|
||
type DockerEnricher struct{} | ||
|
||
type DockerFrameworkDetector interface { | ||
DoPortsDetection(component *model.Component, ctx *context.Context) | ||
} | ||
|
||
func (d DockerEnricher) GetSupportedLanguages() []string { | ||
return []string{"dockerfile"} | ||
} | ||
|
||
func (d DockerEnricher) DoEnrichLanguage(language *model.Language, _ *[]string) { | ||
// The Dockerfile language does not contain frameworks | ||
return | ||
} | ||
|
||
func (d DockerEnricher) DoEnrichComponent(component *model.Component, _ model.DetectionSettings, _ *context.Context) { | ||
projectName := GetDefaultProjectName(component.Path) | ||
component.Name = projectName | ||
|
||
var ports []int | ||
ports = GetPortsFromDockerFile(component.Path) | ||
if len(ports) > 0 { | ||
component.Ports = ports | ||
} | ||
return | ||
} | ||
|
||
func (d DockerEnricher) IsConfigValidForComponentDetection(language string, config string) bool { | ||
return IsConfigurationValidForLanguage(language, config) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package recognizer | ||
|
||
import ( | ||
"github.com/devfile/alizer/pkg/apis/model" | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func Test_isAnyComponentInDirectPath(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
path string | ||
components []model.Component | ||
want bool | ||
}{ | ||
{ | ||
name: "Case 1: path should match", | ||
path: "/alizer/resources/projects/ocparcade/arkanoid/", | ||
components: []model.Component{{ | ||
Name: "", | ||
Path: "/alizer/resources/projects/ocparcade/arkanoid/", | ||
Languages: nil, | ||
Ports: nil, | ||
}}, | ||
want: true, | ||
}, | ||
{ | ||
name: "Case 2: path should match", | ||
path: "/alizer/resources/projects/ocparcade/arkanoid/arkanoid/", | ||
components: []model.Component{{ | ||
Name: "", | ||
Path: "/alizer/resources/projects/ocparcade/arkanoid/arkanoid/", | ||
Languages: nil, | ||
Ports: nil, | ||
}}, | ||
want: true, | ||
}, | ||
{ | ||
name: "Case 3: path should not match", | ||
path: "/alizer/resources/projects/ocparcade/arkanoid/", | ||
components: []model.Component{{ | ||
Name: "", | ||
Path: "/alizer/resources/projects/ocparcade/arkanoid/arkanoid/", | ||
Languages: nil, | ||
Ports: nil, | ||
}}, | ||
want: false, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
result := isAnyComponentInDirectPath(tt.path, tt.components) | ||
if !reflect.DeepEqual(result, tt.want) { | ||
t.Errorf("Got: %t, want: %t", result, tt.want) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
FROM node:16 | ||
|
||
# Create app directory | ||
WORKDIR /usr/src/app | ||
|
||
# Install app dependencies | ||
# A wildcard is used to ensure both package.json AND package-lock.json are copied | ||
COPY package*.json ./ | ||
|
||
RUN npm install | ||
|
||
# Bundle app source | ||
COPY . . | ||
|
||
EXPOSE 8090 | ||
CMD [ "node", "server.js" ] |
16 changes: 16 additions & 0 deletions
16
resources/projects/dockerfile-double-components/Dockerfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
FROM node:16 | ||
|
||
# Create app directory | ||
WORKDIR /usr/src/app | ||
|
||
# Install app dependencies | ||
# A wildcard is used to ensure both package.json AND package-lock.json are copied | ||
COPY package*.json ./ | ||
|
||
RUN npm install | ||
|
||
# Bundle app source | ||
COPY .. . | ||
|
||
EXPOSE 8085 | ||
CMD [ "node", "server.js" ] |
12 changes: 12 additions & 0 deletions
12
resources/projects/dockerfile-double-components/python/manage.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/usr/bin/env python | ||
import os | ||
import sys | ||
|
||
if __name__ == "__main__": | ||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings") | ||
|
||
from django.core.management import execute_from_command_line | ||
|
||
execute_from_command_line(sys.argv) | ||
from django.core.management.commands.runserver import Command as runserver | ||
runserver.default_port = "3543" |
Empty file.
Oops, something went wrong.