Skip to content

Commit 50b5b2d

Browse files
Merge pull request #5 from Deeksha1502/test_github_actions
SBCOSS-403: Added GitHub Actions to Sunbird Echo Service
2 parents 8d85407 + cb19e22 commit 50b5b2d

File tree

6 files changed

+1979
-273
lines changed

6 files changed

+1979
-273
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/node_modules

.eslintrc.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
module.exports = {
2+
env: {
3+
node: true,
4+
es2021: true
5+
},
6+
parserOptions: {
7+
ecmaVersion: 'latest'
8+
},
9+
rules: {
10+
'no-console': 'warn',
11+
'no-debugger': 'error',
12+
'no-unused-vars': 'warn',
13+
'semi': ['error', 'always'],
14+
'quotes': ['error', 'single'],
15+
'indent': ['error', 2]
16+
17+
}
18+
};

README.md

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,71 @@ This is an echo service that will listen on 9595 and return a 200 OK
55

66
The PARALLELISM variable defaults to 2. Set an environment variable with the same name to change parallelism.
77

8-
To build the docker image, execute docker build --tag echoservice:0.0.1 .
8+
To build the docker image, execute docker build --tag echoservice:0.0.1 .
9+
10+
## Development Setup
11+
12+
### Prerequisites
13+
- Node.js v22.15
14+
15+
### Local Development
16+
To set up the project locally:
17+
18+
1. Fork the repository on GitHub
19+
20+
2. Clone your fork:
21+
```bash
22+
git clone https://github.com/your-username/sunbird-echo-service.git
23+
cd sunbird-echo-service
24+
```
25+
26+
3. Install dependencies:
27+
```bash
28+
npm i
29+
```
30+
31+
### Code Quality
32+
33+
The project maintains code quality through automated checks that run on every pull request:
34+
35+
1. **Linting**
36+
- ESLint for code style and quality
37+
- Command: `npm run lint`
38+
39+
2. **Dependencies**
40+
- Uses `npm ci` for deterministic installations
41+
- GitHub Actions cache for faster builds
42+
43+
3. **Code Formatting**
44+
- Ensures consistent code formatting
45+
- Can be automatically fixed using `npm run lint:fix`
46+
47+
These checks ensure consistent code style and secure dependency management.
48+
49+
## Container Image Publishing
50+
51+
This repository uses GitHub Actions to automatically build and publish Docker container images to GitHub Container Registry (GHCR) whenever a new tag is pushed to the repository.
52+
53+
### Build and Publish Workflow
54+
55+
The workflow is triggered on:
56+
- creation of any tag
57+
58+
Key features of the workflow:
59+
1. Automatically builds Docker images
60+
2. Tags images with a combination of:
61+
- The tag name (lowercased)
62+
- Short commit hash
63+
- GitHub run number
64+
3. Publishes images to `ghcr.io` using the repository name
65+
4. Uses GitHub Actions for secure authentication to GHCR
66+
67+
### Image Naming Convention
68+
The Docker images follow this naming convention:
69+
- Repository: `ghcr.io/${OWNER_NAME}/${REPO_NAME_LOWERCASE}`
70+
- Tag: `${TAG_NAME}_${COMMIT_HASH}_${RUN_NUMBER}`
71+
72+
For example, if you push a tag `v1.0.0` on commit `abc123`, the resulting image would be:
73+
```
74+
ghcr.io/project-sunbird/sunbird-echo-service:v1.0.0_abc123_1
75+
```

index.js

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,43 +2,43 @@ const cluster = require('cluster');
22

33
if (cluster.isMaster) {
44

5-
// Parallelism can be configured through env params
6-
var cpuCount = process.env.PARALLELISM || 2;
5+
// Parallelism can be configured through env params
6+
var cpuCount = process.env.PARALLELISM || 2;
77

8-
// Create a worker for each CPU
9-
for (var i = 0; i < cpuCount; i += 1) {
10-
cluster.fork();
11-
}
8+
// Create a worker for each CPU
9+
for (var i = 0; i < cpuCount; i += 1) {
10+
cluster.fork();
11+
}
1212
} else {
13-
const express = require("express");
14-
const app = express();
15-
const port = 9595
16-
17-
var server = app.listen(port, () => {
18-
console.log("Server running on port " + port);
19-
});
20-
21-
server.on('connection', function(socket) {
22-
//Below line has been added to check how many new connections are being made. This should be very few in a keep alive env
23-
console.log("New connection was made by client");
24-
socket.setTimeout(180 * 1000);
25-
});
26-
27-
app.get("/", (req, res, next) => {
28-
res.status(200).send('hello');
29-
});
30-
31-
app.get("/:reqpath", (req, res, next) => {
32-
let reqpath = req.params.reqpath;
33-
res.status(200).send(reqpath);
34-
});
35-
36-
app.get("/service/health", (req, res, next) => {
37-
res.status(200).send('{"healthy":true}');
38-
});
39-
40-
app.use(function (req,res,next){
41-
res.status(200).send('Unknown Path');
42-
});
13+
const express = require('express');
14+
const app = express();
15+
const port = 9595;
16+
17+
var server = app.listen(port, () => {
18+
console.log('Server running on port ' + port);
19+
});
20+
21+
server.on('connection', function(socket) {
22+
//Below line has been added to check how many new connections are being made. This should be very few in a keep alive env
23+
console.log('New connection was made by client');
24+
socket.setTimeout(180 * 1000);
25+
});
26+
27+
app.get('/', (req, res, next) => {
28+
res.status(200).send('hello');
29+
});
30+
31+
app.get('/:reqpath', (req, res, next) => {
32+
let reqpath = req.params.reqpath;
33+
res.status(200).send(reqpath);
34+
});
35+
36+
app.get('/service/health', (req, res, next) => {
37+
res.status(200).send('{"healthy":true}');
38+
});
39+
40+
app.use(function (req,res,next){
41+
res.status(200).send('Unknown Path');
42+
});
4343

4444
}

0 commit comments

Comments
 (0)