Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
7796451
initial commit
Feb 6, 2024
9f8f2f9
made on express
vitalii-codefresh Feb 9, 2024
817c4c0
gitops preparation
vitalii-codefresh Feb 15, 2024
4e84b24
changed helm chart name
vitalii-codefresh Feb 19, 2024
33eaec4
changed path
vitalii-codefresh Feb 20, 2024
5dda0de
changed ingress
vitalii-codefresh Feb 20, 2024
edb65b6
changed name of chart folder
vitalii-codefresh Feb 21, 2024
06996c6
changed image tag
vitalii-codefresh Feb 21, 2024
8d1699d
corrected path app2
vitalii-codefresh Feb 21, 2024
d5511d4
test webhook
vitalii-codefresh Mar 27, 2024
6e79c67
Revert "test webhook"
vitalii-codefresh Mar 29, 2024
6f27227
set to argo
vitalii-codefresh Apr 2, 2024
340ee8a
scaled up
vitalii-codefresh Apr 4, 2024
97a1581
Revert "scaled up"
vitalii-codefresh Apr 4, 2024
f26e3b0
scaled app1
vitalii-codefresh Apr 4, 2024
a079fa0
scaled up
vitalii-codefresh Apr 4, 2024
0304eb2
scaled up to 3
vitalii-codefresh Apr 4, 2024
3d4da53
corrected format
vitalii-codefresh Apr 4, 2024
ec5c8bb
corrected format2
vitalii-codefresh Apr 4, 2024
d8f0f58
corrected format3
vitalii-codefresh Apr 4, 2024
6e73e25
changes volumes
vitalii-codefresh Apr 8, 2024
e36d3b5
changed to another type
vitalii-codefresh Apr 8, 2024
3764fbb
changed replicas
vitalii-codefresh Apr 8, 2024
6d64068
updated
vitalii-codefresh Apr 8, 2024
42c1027
changed storage
vitalii-codefresh Apr 8, 2024
a1ef927
changed st
vitalii-codefresh Apr 8, 2024
13f6dc4
changed pv
vitalii-codefresh Apr 8, 2024
85e0335
ing correct
vitalii-codefresh Apr 8, 2024
652a289
corrected ing
vitalii-codefresh Apr 8, 2024
9f72c3b
ing v1
vitalii-codefresh Apr 8, 2024
0670394
delete ing
vitalii-codefresh Apr 8, 2024
ae3da08
added ing
vitalii-codefresh Apr 8, 2024
7de27b8
igs
vitalii-codefresh Apr 8, 2024
2b3e3bc
Added/Modified gitops/single-service/new.yaml
vitalii-codefresh Nov 14, 2024
5954ada
upd ingress
vitalii-codefresh Nov 14, 2024
1c511d9
Merge remote-tracking branch 'origin/develop' into develop
vitalii-codefresh Nov 14, 2024
f3be466
upd test
vitalii-codefresh Jul 23, 2025
fef2a2b
upd test
vitalii-codefresh Jul 23, 2025
d59aec8
Create blank.yml
vitalii-codefresh Jul 23, 2025
a95f305
upd test
vitalii-codefresh Jul 23, 2025
3602875
Update blank.yml
vitalii-codefresh Jul 23, 2025
6f96d02
Merge branch 'main' into develop
vitalii-codefresh Jul 23, 2025
453436c
upd test
vitalii-codefresh Jul 23, 2025
471a89d
empty
vitalii-codefresh Jul 23, 2025
f0587dc
Merge remote-tracking branch 'origin/develop' into develop
vitalii-codefresh Jul 23, 2025
c05c830
upd test
vitalii-codefresh Jul 23, 2025
e4302de
upd test
vitalii-codefresh Jul 23, 2025
83b356d
upd test
vitalii-codefresh Jul 23, 2025
64260b7
upd test
vitalii-codefresh Jul 23, 2025
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
4 changes: 3 additions & 1 deletion .github/workflows/blank.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,7 @@ jobs:
# Runs a set of commands using the runners shell
- name: Run a multi-line script
run: |
yarn test,
cd app1
yarn install
yarn test
echo test, and deploy your project.
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
node_modules
build
npm-debug.log
.nyc
.env
.DS_Store
.idea
configmap
app3

/gitops/single-service/other/
4 changes: 4 additions & 0 deletions app1/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.env
node_modules
build
data/*
10 changes: 10 additions & 0 deletions app1/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
ARG BUILD_VAR="buildVar"
FROM node:20.18.0-alpine3.20
LABEL authors="vitalii-codefresh"
WORKDIR app/
COPY . .
EXPOSE 8002
VOLUME /myvol
RUN yarn install && npm -g uninstall npm

ENTRYPOINT ["node", "index.js"]
76 changes: 76 additions & 0 deletions app1/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
const { log } = require('console');
const express = require('express');
const crypto = require(`crypto`);
const { appendFile, readFile } = require("fs/promises");
const { readdirSync } = require("fs");
const { resolve } = require("path");
require('dotenv').config();

const router = express.Router();
const port = process.env.PORT || 8000;
const serviceId = crypto.randomBytes(5).toString("hex");
const resultFile = "./data/results.csv";

const app = express(); // Експортуємо цей екземпляр


router.get('/', (req, res) => {
res.statusCode = 200;
res.header("Content-Type", "application/json");
res.json({ result: "hello", serviceId });
});

router.get('/add', express.json(), async (req, res) => {
const body = req.body;
if (!body || typeof body.firstValue === 'undefined' || typeof body.secondValue === 'undefined') {
res.statusCode = 400;
res.send("body is required");
return;
}
const firstValue = body.firstValue;
const secondValue = body.secondValue;
const result = firstValue + secondValue;
await writeResult(result, serviceId);
res.send({ result, serviceId });
});

router.get('/getResults', async (req, res) => {
try {
const results = await readResults();
res.json({ results, serviceId });
} catch (e) {
res.statusCode = 500;
res.send("internal error");
}
});

router.get('/getDir', async (req, res) => {
try {
const myPath = resolve();
const files = readdirSync("./");
const dataContent = readdirSync("./data");
res.json({ files, dataContent, myPath, serviceId });
} catch (e) {
res.statusCode = 500;
res.send("internal error");
}
});

app.use("/app1", router);

module.exports = { app };

if (require.main === module) {
app.listen(port, () => {
log(`server starts at port ${port}`, `id is - ${serviceId}`);
});
}


async function writeResult(result, serviceId) {
await appendFile(resultFile, `${result};SERVICE_ID-${serviceId};` + "\n");
}

async function readResults() {
return readFile(resultFile, { encoding: "utf-8" });
}
22 changes: 22 additions & 0 deletions app1/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "simple-server",
"version": "1.0.0",
"description": "To make it easy for you to get started with GitLab, here's a list of recommended next steps.",
"main": "app1/index.js",
"scripts": {
"test": "npx jest "
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"dotenv": "^16.4.1",
"express": "^4.18.2",
"jest": "27.5.1",
"ip": "2.0.1"
},
"devDependencies": {
"supertest": "^7.1.4"
},
"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
}
85 changes: 85 additions & 0 deletions app1/test/app1.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
const request = require('supertest');
const { app } = require('../index');

jest.mock('fs/promises', () => ({
appendFile: jest.fn(() => Promise.resolve()),
readFile: jest.fn(() => Promise.resolve('10;SERVICE_ID-abcde;\n20;SERVICE_ID-fghij;\n')),
}));

jest.mock('fs', () => ({
readdirSync: jest.fn((path) => {
if (path === './') return ['app.js', 'package.json', 'data'];
if (path === './data') return ['results.csv'];
return [];
}),
}));

describe('Express App Tests', () => {
let server;

beforeAll((done) => {
server = app.listen(0, done);
});
afterAll((done) =>{
server.close(done);
});

test('GET /app1/ should return hello and serviceId', async () => {
const res = await request(server).get('/app1/');
expect(res.statusCode).toEqual(200);
expect(res.headers['content-type']).toMatch(/application\/json/);
expect(res.body.result).toEqual('hello');
expect(res.body).toHaveProperty('serviceId');
});

test('GET /app1/add with valid body should return sum and serviceId', async () => {
const res = await request(server)
.get('/app1/add')
.send({ firstValue: 5, secondValue: 3 })
.set('Content-Type', 'application/json');

expect(res.statusCode).toEqual(200);
expect(res.body.result).toEqual(8);
expect(res.body).toHaveProperty('serviceId');
expect(require('fs/promises').appendFile).toHaveBeenCalledWith(
'./data/results.csv',
expect.stringContaining('8;SERVICE_ID-'),
);
});

test('GET /app1/add without body should return 400', async () => {
const res = await request(server).get('/app1/add'); // Без .send()
expect(res.statusCode).toEqual(400);
expect(res.text).toEqual('body is required');
});

test('GET /app1/add with missing firstValue should return 400', async () => {
const res = await request(server)
.get('/app1/add')
.send({ secondValue: 3 })
.set('Content-Type', 'application/json');
expect(res.statusCode).toEqual(400);
expect(res.text).toEqual('body is required');
});

test('GET /app1/getResults should return results from file', async () => {
const res = await request(server).get('/app1/getResults');
expect(res.statusCode).toEqual(200);
expect(res.body.results).toEqual('10;SERVICE_ID-abcde;\n20;SERVICE_ID-fghij;\n');
expect(res.body).toHaveProperty('serviceId');
// Перевіряємо, що readFile був викликаний
expect(require('fs/promises').readFile).toHaveBeenCalledWith(
'./data/results.csv',
{ encoding: 'utf-8' }
);
});

test('GET /app1/getDir should return directory contents and path', async () => {
const res = await request(server).get('/app1/getDir');
expect(res.statusCode).toEqual(200);
expect(res.body.files).toEqual(['app.js', 'package.json', 'data']);
expect(res.body.dataContent).toEqual(['results.csv']);
expect(res.body).toHaveProperty('myPath');
expect(res.body).toHaveProperty('serviceId');
});
});
3 changes: 3 additions & 0 deletions app2/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.env
node_modules
build
10 changes: 10 additions & 0 deletions app2/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
ARG BUILD_VAR="buildVar"
FROM node:20.11-alpine3.18
LABEL authors="vitalii-codefresh"
WORKDIR app/
COPY . .
EXPOSE 8010
VOLUME /myvol
RUN ["npm", "i"]

ENTRYPOINT ["node", "index2.js"]
38 changes: 38 additions & 0 deletions app2/index2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const {log} = require('console');
const express = require('express')
const crypto = require(`crypto`);
require('dotenv').config();
const app1Host = process.env.APP1_HOST;
const router = express.Router();
const port = 8010;
const serviceId = crypto.randomBytes(5).toString("hex");
const app = express();

router.get('/', (req, res) => {
res.statusCode = 200;
res.header("Content-Type", "application/json");
res.json({result: "hello", serviceId});
})

router.get('/getRes', express.json(), async (req, res) => {
if (!app1Host) {
res.statusCode = 500;
res.send("APP1_HOST - variable was not set");
return;
}
try {
const results = await (await fetch(`${app1Host}/getResults`)).json();
res.send({results, serviceId});
} catch (e) {
console.error(e)
res.statusCode = 500;
res.send("Internal error");
}
});

app.use("/app2", router);

app.listen(port, () => {
log(`server starts at port ${port}`, `id is - ${serviceId}`);
console.log("app1Host is :"+ app1Host);
})
Loading