Skip to content
This repository has been archived by the owner on Oct 10, 2023. It is now read-only.

feat: add support for Containerfile #134

Merged
merged 1 commit into from
Jan 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go/docs/port_detection.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Because of the different nature of frameworks supported, Alizer tries to use cus
Only ports with value > 0 and < 65535 are valid.

There are three detection strategies currently available:
1) Docker file - Alizer looks for a Dockerfile in the root folder and tries to extract ports from it.
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
3) Source - If a framework has been detected during component detection, a customized detection is performed. Below a detailed overview of the different strategies for each supported framework.

Expand Down
11 changes: 7 additions & 4 deletions go/pkg/apis/enricher/enricher.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,13 @@ func GetDefaultProjectName(path string) string {
}

func GetPortsFromDockerFile(root string) []int {
file, err := os.Open(filepath.Join(root, "Dockerfile"))
if err == nil {
defer file.Close()
return getPortsFromReader(file)
locations := []string{"Dockerfile", "Containerfile"}
for _, location := range locations {
file, err := os.Open(filepath.Join(root, location))
if err == nil {
defer file.Close()
return getPortsFromReader(file)
}
}
return []int{}
}
Expand Down
4 changes: 4 additions & 0 deletions go/test/apis/component_recognizer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,10 @@ func TestPortDetectionWithDockerFile(t *testing.T) {
testPortDetectionInProject(t, "projectDockerFile", []int{8085})
}

func TestPortDetectionWithContainerFile(t *testing.T) {
testPortDetectionInProject(t, "projectContainerFile", []int{8085})
}

func TestPortDetectionJavaMicronaut(t *testing.T) {
testPortDetectionInProject(t, "projectMicronaut", []int{4444})
}
Expand Down
16 changes: 16 additions & 0 deletions resources/projectPortTesting/projectContainerFile/Containerfile
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" ]
17 changes: 17 additions & 0 deletions resources/projectPortTesting/projectContainerFile/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "nodejs-starter",
"version": "1.0.0",
"description": "Simple Node.js application",
"license": "EPL-2.0",
"scripts": {
"start": "node server.js",
"debug": "node --inspect-brk=${DEBUG_PORT} server.js",
"test": "node test/test.js"
},
"dependencies": {
"express": "^4.17.1",
"pino": "^6.2.1",
"pino-http": "^5.1.0",
"prom-client": "^12.0.0"
}
}
21 changes: 21 additions & 0 deletions resources/projectPortTesting/projectContainerFile/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const express = require('express');
const http = require('http');

const app = express();
const server = http.createServer(app)

app.get('/', (req, res) => {
// Use req.log (a `pino` instance) to log JSON:
req.log.info({message: 'Hello from my Node.js App!'});
res.send('Hello from my Node.js App!');
});

app.get('*', (req, res) => {
res.status(404).send("Not Found");
});

// Listen and serve.
const PORT = process.env.PORT || 3000;
server.listen(PORT, () => {
console.log(`App started on PORT ${PORT}`);
});