Skip to content

Commit

Permalink
new stackbrew in js
Browse files Browse the repository at this point in the history
  • Loading branch information
sampaiodiego committed Nov 27, 2024
1 parent de2e3d9 commit 74a3ba0
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 94 deletions.
4 changes: 2 additions & 2 deletions UPDATE.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Instuctions to update
# Instructions to update

```
./update.sh
./generate-stackbrew-library.sh > ../official-images/library/rocket.chat
node stackbrew.js > ../official-images/library/rocket.chat
cd ../official-images
#git commit && git push && PR
```
92 changes: 0 additions & 92 deletions generate-stackbrew-library.sh

This file was deleted.

82 changes: 82 additions & 0 deletions stackbrew.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#!/usr/bin/env node

const fs = require('fs');
const path = require('path');

// Grab last git commit
function getCommitHasForPath(path) {
return require('child_process')
.execSync(`git log -1 --format=%H HEAD -- ${path}`)
.toString().trim()
}

const stackbrewPath = path.basename(__filename);

const url = 'https://github.com/RocketChat/Docker.Official.Image';

// Header
let stackbrew = `# this file is generated via ${url}/blob/${getCommitHasForPath(stackbrewPath)}/${stackbrewPath}
Maintainers: Rocket.Chat Image Team <buildmaster@rocket.chat> (@RocketChat)
GitRepo: ${url}.git
GitFetch: refs/heads/main\n`;

// Loop versions
const rcDirRegex = /^\d+\.\d+$/;

// Returns a list of the child directories in the given path
const getChildDirectories = (parent) => fs.readdirSync(parent, { withFileTypes: true })
.filter((dirent) => dirent.isDirectory())
.map(({ name }) => name);

const getRocketChatVersionDirs = (base) => getChildDirectories(base)
.filter((childPath) => rcDirRegex.test(path.basename(childPath)));

// versions need to be in order from most recent to older
const versions = getRocketChatVersionDirs(__dirname)
.sort((a,b) => b.localeCompare(a, undefined, { numeric: true, sensitivity: 'base' }));

let foundCurrent = false;

const latestMajor = [];

for (version of versions) {
const isCurrent = !foundCurrent;
foundCurrent = true;

let fullversion;

// Get full version from the first Dockerfile
if (!fullversion) {
const dockerfile = fs.readFileSync(path.join(version, 'Dockerfile'), 'utf-8');
fullversion = dockerfile.match(/ENV RC_VERSION (?<major>\d+)\.(?<minor>\d+)\.(?<patch>\d+)/)
}
let tags = [
`${fullversion.groups.major}.${fullversion.groups.minor}.${fullversion.groups.patch}`,
`${fullversion.groups.major}.${fullversion.groups.minor}`,
];

const isLatestMajor = !latestMajor.includes(fullversion.groups.major);

if (isLatestMajor) {
tags.push(fullversion.groups.major);

latestMajor.push(fullversion.groups.major);
}

if (isCurrent) {
tags.push('latest');
}

// remove duplicates
tags = tags.filter((x, i, a) => a.indexOf(x) == i);
tags = tags.sort((a, b) => b - a);

stackbrew += `\nTags: ${tags.join(', ')}\n`;
// stackbrew += `Architectures: ${tbd.join(', ')}\n`
stackbrew += `GitCommit: ${getCommitHasForPath(version)}\n`;
stackbrew += `Directory: ${version}\n`;
}

// output
console.log(stackbrew)

0 comments on commit 74a3ba0

Please sign in to comment.