You've already forked nodejs
mirror of
https://github.com/nodejs/docker-node.git
synced 2026-10-23 16:08:56 +03:00
chore(ci): add prettier formatter (#2570)
Add prettier workflow Reformat files js, mjs, json, md & yml Remove eclint workflow Exclude auto-generated TOC contents
This commit is contained in:
9
.github/ISSUE_TEMPLATE/1-bug-report.md
vendored
9
.github/ISSUE_TEMPLATE/1-bug-report.md
vendored
@@ -11,10 +11,10 @@ Please fill in as much of the template below as you're able.
|
||||
|
||||
## Environment
|
||||
|
||||
* **Platform**:
|
||||
* **Docker Version**:
|
||||
* **Node.js Version**:
|
||||
* **Image Tag**:
|
||||
- **Platform**:
|
||||
- **Docker Version**:
|
||||
- **Node.js Version**:
|
||||
- **Image Tag**:
|
||||
|
||||
## Expected Behavior
|
||||
|
||||
@@ -45,4 +45,3 @@ Tell us about the steps you took to encounter this bug with the image.
|
||||
<!--
|
||||
Tell us anything else you think we should know.
|
||||
-->
|
||||
|
||||
|
||||
1
.github/ISSUE_TEMPLATE/2-feature-request.md
vendored
1
.github/ISSUE_TEMPLATE/2-feature-request.md
vendored
@@ -26,4 +26,3 @@ Please describe the desired behavior.
|
||||
<!--
|
||||
Please describe alternative solutions or features you have considered.
|
||||
-->
|
||||
|
||||
|
||||
1
.github/PULL_REQUEST_TEMPLATE.md
vendored
1
.github/PULL_REQUEST_TEMPLATE.md
vendored
@@ -51,4 +51,3 @@ If you're unsure about any of these, don't hesitate to ask. We're here to help!
|
||||
- [ ] I have updated the documentation accordingly.
|
||||
- [ ] I have read the **CONTRIBUTING.md** document.
|
||||
- [ ] All new and existing tests passed.
|
||||
|
||||
|
||||
10
.github/dependabot.yml
vendored
10
.github/dependabot.yml
vendored
@@ -1,7 +1,7 @@
|
||||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: github-actions
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: daily
|
||||
open-pull-requests-limit: 10
|
||||
- package-ecosystem: github-actions
|
||||
directory: '/'
|
||||
schedule:
|
||||
interval: daily
|
||||
open-pull-requests-limit: 10
|
||||
|
||||
8
.github/workflows/automatic-updates.yml
vendored
8
.github/workflows/automatic-updates.yml
vendored
@@ -3,7 +3,7 @@ name: Automatically update Docker image versions
|
||||
on:
|
||||
workflow_dispatch:
|
||||
schedule:
|
||||
- cron: "*/15 * * * *"
|
||||
- cron: '*/15 * * * *'
|
||||
|
||||
jobs:
|
||||
build:
|
||||
@@ -29,11 +29,11 @@ jobs:
|
||||
uses: peter-evans/create-pull-request@5f6978faf089d4d20b00c7766989d076bb2fc7f1 # v8.1.1
|
||||
with:
|
||||
token: ${{ secrets.GH_API_TOKEN }}
|
||||
author: "Node.js GitHub Bot <nodejs-github-bot@users.noreply.github.com>"
|
||||
author: 'Node.js GitHub Bot <nodejs-github-bot@users.noreply.github.com>'
|
||||
branch: update-branch
|
||||
base: main
|
||||
commit-message: "feat: Node.js ${{ steps.updt.outputs.result }}"
|
||||
title: "feat: Node.js ${{ steps.updt.outputs.result }}"
|
||||
commit-message: 'feat: Node.js ${{ steps.updt.outputs.result }}'
|
||||
title: 'feat: Node.js ${{ steps.updt.outputs.result }}'
|
||||
delete-branch: true
|
||||
team-reviewers: |
|
||||
nodejs/docker
|
||||
|
||||
12
.github/workflows/build-test.yml
vendored
12
.github/workflows/build-test.yml
vendored
@@ -3,17 +3,17 @@ name: build-test
|
||||
on:
|
||||
push:
|
||||
paths:
|
||||
- "**/Dockerfile"
|
||||
- "**/docker-entrypoint.sh"
|
||||
- '**/Dockerfile'
|
||||
- '**/docker-entrypoint.sh'
|
||||
- genMatrix.js
|
||||
- ".github/workflows/build-test.yml"
|
||||
- '.github/workflows/build-test.yml'
|
||||
|
||||
pull_request:
|
||||
paths:
|
||||
- "**/Dockerfile"
|
||||
- "**/docker-entrypoint.sh"
|
||||
- '**/Dockerfile'
|
||||
- '**/docker-entrypoint.sh'
|
||||
- genMatrix.js
|
||||
- ".github/workflows/build-test.yml"
|
||||
- '.github/workflows/build-test.yml'
|
||||
|
||||
jobs:
|
||||
gen-matrix:
|
||||
|
||||
6
.github/workflows/doctoc.yml
vendored
6
.github/workflows/doctoc.yml
vendored
@@ -3,9 +3,9 @@ name: Check generated TOCs
|
||||
on:
|
||||
pull_request:
|
||||
paths:
|
||||
- "README.md"
|
||||
- "docs/BestPractices.md"
|
||||
- ".github/workflows/doctoc.yml"
|
||||
- 'README.md'
|
||||
- 'docs/BestPractices.md'
|
||||
- '.github/workflows/doctoc.yml'
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
6
.github/workflows/markdown-link-check.yml
vendored
6
.github/workflows/markdown-link-check.yml
vendored
@@ -3,9 +3,9 @@ name: Check Markdown links
|
||||
on:
|
||||
pull_request:
|
||||
paths:
|
||||
- "**/*.md"
|
||||
- "markdown_link_check_config.json"
|
||||
- ".github/workflows/markdown-link-check.yml"
|
||||
- '**/*.md'
|
||||
- 'markdown_link_check_config.json'
|
||||
- '.github/workflows/markdown-link-check.yml'
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
4
.github/workflows/missing-checksum.yml
vendored
4
.github/workflows/missing-checksum.yml
vendored
@@ -3,8 +3,8 @@ name: Check Alpine CHECKSUM
|
||||
on:
|
||||
pull_request:
|
||||
paths:
|
||||
- ".github/workflows/missing-checksum.yml"
|
||||
- "**/alpine*/Dockerfile"
|
||||
- '.github/workflows/missing-checksum.yml'
|
||||
- '**/alpine*/Dockerfile'
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
14
.github/workflows/official-pr.yml
vendored
14
.github/workflows/official-pr.yml
vendored
@@ -6,11 +6,11 @@ on:
|
||||
- closed
|
||||
|
||||
paths:
|
||||
- ".github/workflows/official-pr.yml"
|
||||
- "**/Dockerfile"
|
||||
- "**/docker-entrypoint.sh"
|
||||
- "versions.json"
|
||||
- "stackbrew.js"
|
||||
- '.github/workflows/official-pr.yml'
|
||||
- '**/Dockerfile'
|
||||
- '**/docker-entrypoint.sh'
|
||||
- 'versions.json'
|
||||
- 'stackbrew.js'
|
||||
|
||||
jobs:
|
||||
pr:
|
||||
@@ -46,8 +46,8 @@ jobs:
|
||||
push-to-fork: nodejs/official-images
|
||||
path: official-images
|
||||
branch: node
|
||||
commit-message: "Node: ${{ github.event.pull_request.title }}"
|
||||
title: "Node: ${{ github.event.pull_request.title }}"
|
||||
commit-message: 'Node: ${{ github.event.pull_request.title }}'
|
||||
title: 'Node: ${{ github.event.pull_request.title }}'
|
||||
body: |
|
||||
Pull Request: ${{ github.event.pull_request.html_url }}
|
||||
@PeterDaveHello @SimenB @nschonni @rafaelgss @mcollina
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
name: Test Whitespace and line endings
|
||||
name: Check Prettier formatting
|
||||
|
||||
on: [pull_request]
|
||||
|
||||
@@ -6,12 +6,11 @@ permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
eclint:
|
||||
prettier:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||
- uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
|
||||
with:
|
||||
node-version: 'lts/*'
|
||||
- run: npm i -g eclint
|
||||
- run: eclint check
|
||||
- run: npx prettier@3.9.5 --check .
|
||||
10
.github/workflows/scorecard.yml
vendored
10
.github/workflows/scorecard.yml
vendored
@@ -12,7 +12,7 @@ on:
|
||||
schedule:
|
||||
- cron: '30 12 * * 6'
|
||||
push:
|
||||
branches: [ "main" ]
|
||||
branches: ['main']
|
||||
|
||||
# Declare default permissions as read only.
|
||||
permissions: read-all
|
||||
@@ -31,12 +31,12 @@ jobs:
|
||||
# actions: read
|
||||
|
||||
steps:
|
||||
- name: "Checkout code"
|
||||
- name: 'Checkout code'
|
||||
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
||||
with:
|
||||
persist-credentials: false
|
||||
|
||||
- name: "Run analysis"
|
||||
- name: 'Run analysis'
|
||||
uses: ossf/scorecard-action@4eaacf0543bb3f2c246792bd56e8cdeffafb205a # v2.4.3
|
||||
with:
|
||||
results_file: results.sarif
|
||||
@@ -58,7 +58,7 @@ jobs:
|
||||
|
||||
# Upload the results as artifacts (optional). Commenting out will disable uploads of run results in SARIF
|
||||
# format to the repository Actions tab.
|
||||
- name: "Upload artifact"
|
||||
- name: 'Upload artifact'
|
||||
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
||||
with:
|
||||
name: SARIF file
|
||||
@@ -67,7 +67,7 @@ jobs:
|
||||
|
||||
# Upload the results to GitHub's code scanning dashboard (optional).
|
||||
# Commenting out will disable upload of results to your repo's Code Scanning dashboard
|
||||
- name: "Upload to code-scanning"
|
||||
- name: 'Upload to code-scanning'
|
||||
uses: github/codeql-action/upload-sarif@7188fc363630916deb702c7fdcf4e481b751f97a # v4.37.1
|
||||
with:
|
||||
sarif_file: results.sarif
|
||||
|
||||
4
.github/workflows/shfmt.yml
vendored
4
.github/workflows/shfmt.yml
vendored
@@ -3,8 +3,8 @@ name: Check Shell scripts
|
||||
on:
|
||||
pull_request:
|
||||
paths:
|
||||
- "**/*.sh"
|
||||
- ".github/workflows/shfmt.yml"
|
||||
- '**/*.sh'
|
||||
- '.github/workflows/shfmt.yml'
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
11
.prettierrc.json
Normal file
11
.prettierrc.json
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"singleQuote": true,
|
||||
"overrides": [
|
||||
{
|
||||
"files": "versions.json",
|
||||
"options": {
|
||||
"printWidth": 38
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -16,6 +16,7 @@ the Node.js TSC as final arbiter.
|
||||
## Discussion Areas
|
||||
|
||||
<!-- markdown-link-check-disable -->
|
||||
|
||||
You can use Node.js channels (prefixed by `#nodejs-`) in the [OpenJSF Slack](https://slack-invite.openjsf.org/) workspace for discussions.
|
||||
<!-- markdown-link-check-enable -->
|
||||
|
||||
@@ -73,4 +74,4 @@ This task is undertaken by members of the repo team above.
|
||||
|
||||
## Adding dependencies to the base images
|
||||
|
||||
NodeJS is a big ecosystem with a variety of different use cases. The docker images for node are designed to provide the minimum for running core node. Additional dependencies (including dependencies for npm or yarn such as git) will not be included in these base images and will need to be included in descendent image.
|
||||
NodeJS is a big ecosystem with a variety of different use cases. The docker images for node are designed to provide the minimum for running core node. Additional dependencies (including dependencies for npm or yarn such as git) will not be included in these base images and will need to be included in descendent image.
|
||||
|
||||
@@ -54,7 +54,7 @@ For governance, membership, major policy, or contentious technical changes:
|
||||
1. Open an issue or PR describing the decision and proposed outcome.
|
||||
2. Allow time for async feedback (normally at least 5 days).
|
||||
3. If no unresolved objections remain, a maintainer may merge/close with a
|
||||
summary.
|
||||
summary.
|
||||
|
||||
If a final decision cannot be made using Consensus Seeking, the issue should be
|
||||
escalated to the Node.js TSC (for example by requesting `tsc-agenda`).
|
||||
|
||||
16
README.md
16
README.md
@@ -2,11 +2,12 @@
|
||||
|
||||
[**node - Docker Official Images on Docker Hub**](https://hub.docker.com/_/node)
|
||||
|
||||
[](https://github.com/nodejs/docker-node)
|
||||
[](https://github.com/nodejs/docker-node)
|
||||
[](https://github.com/nodejs/docker-node)
|
||||
[](https://github.com/nodejs/docker-node)
|
||||
|
||||
The official Node.js docker image, made with love by the node community.
|
||||
|
||||
<!-- prettier-ignore-start -->
|
||||
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
|
||||
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
|
||||
## Table of Contents
|
||||
@@ -42,6 +43,7 @@ The official Node.js docker image, made with love by the node community.
|
||||
- [Emeritus](#emeritus)
|
||||
|
||||
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
|
||||
<!-- prettier-ignore-end -->
|
||||
|
||||
## What is Node.js?
|
||||
|
||||
@@ -75,16 +77,16 @@ If you prefer Docker Compose:
|
||||
```yml
|
||||
services:
|
||||
node:
|
||||
image: "node:24"
|
||||
user: "node"
|
||||
image: 'node:24'
|
||||
user: 'node'
|
||||
working_dir: /home/node/app
|
||||
environment:
|
||||
- NODE_ENV=production
|
||||
volumes:
|
||||
- ./:/home/node/app
|
||||
ports: # use if it is necessary to expose the container to the host machine
|
||||
- "8888:8888"
|
||||
command: ["npm", "start"]
|
||||
- '8888:8888'
|
||||
command: ['npm', 'start']
|
||||
```
|
||||
|
||||
You can then run using Docker Compose:
|
||||
@@ -230,7 +232,7 @@ This image is based on version 13 of
|
||||
|
||||
This image does not contain the common packages contained in the default tag and
|
||||
only contains the minimal packages needed to run `node`. Unless you are working
|
||||
in an environment where *only* the Node.js image will be deployed and you have
|
||||
in an environment where _only_ the Node.js image will be deployed and you have
|
||||
space constraints, we highly recommend using the default image of this
|
||||
repository.
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { promisify } from "util";
|
||||
import { promisify } from 'util';
|
||||
|
||||
import child_process from "child_process";
|
||||
import child_process from 'child_process';
|
||||
|
||||
const exec = promisify(child_process.exec);
|
||||
|
||||
@@ -9,23 +9,33 @@ const exec = promisify(child_process.exec);
|
||||
// and returns whether we should update or not
|
||||
const checkIfThereAreNewVersions = async (github) => {
|
||||
try {
|
||||
const { stdout: versionsOutput } = await exec(". ./functions.sh && get_versions", { shell: "bash" });
|
||||
const { stdout: versionsOutput } = await exec(
|
||||
'. ./functions.sh && get_versions',
|
||||
{ shell: 'bash' },
|
||||
);
|
||||
|
||||
const supportedVersions = versionsOutput.trim().split(" ");
|
||||
const supportedVersions = versionsOutput.trim().split(' ');
|
||||
|
||||
let latestSupportedVersions = {};
|
||||
|
||||
for (let supportedVersion of supportedVersions) {
|
||||
const { stdout } = await exec(`ls ${supportedVersion}`);
|
||||
|
||||
const { stdout: fullVersionOutput } = await exec(`. ./functions.sh && get_full_version ./${supportedVersion}/${stdout.trim().split("\n")[0]}`, { shell: "bash" });
|
||||
const { stdout: fullVersionOutput } = await exec(
|
||||
`. ./functions.sh && get_full_version ./${supportedVersion}/${stdout.trim().split('\n')[0]}`,
|
||||
{ shell: 'bash' },
|
||||
);
|
||||
|
||||
console.log(fullVersionOutput);
|
||||
|
||||
latestSupportedVersions[supportedVersion] = { fullVersion: fullVersionOutput.trim() };
|
||||
latestSupportedVersions[supportedVersion] = {
|
||||
fullVersion: fullVersionOutput.trim(),
|
||||
};
|
||||
}
|
||||
|
||||
const { data: availableVersionsJson } = await github.request('https://nodejs.org/download/release/index.json');
|
||||
const { data: availableVersionsJson } = await github.request(
|
||||
'https://nodejs.org/download/release/index.json',
|
||||
);
|
||||
|
||||
// filter only more recent versions of availableVersionsJson for each major version in latestSupportedVersions' keys
|
||||
// e.g. if latestSupportedVersions = { "12": "12.22.10", "14": "14.19.0", "16": "16.14.0", "17": "17.5.0" }
|
||||
@@ -35,20 +45,32 @@ const checkIfThereAreNewVersions = async (github) => {
|
||||
let filteredNewerVersions = {};
|
||||
|
||||
for (let availableVersion of availableVersionsJson) {
|
||||
const [availableMajor, availableMinor, availablePatch] = availableVersion.version.split("v")[1].split(".");
|
||||
const [availableMajor, availableMinor, availablePatch] =
|
||||
availableVersion.version.split('v')[1].split('.');
|
||||
if (latestSupportedVersions[availableMajor] == null) {
|
||||
continue;
|
||||
}
|
||||
const [_latestMajor, latestMinor, latestPatch] = latestSupportedVersions[availableMajor].fullVersion.split(".");
|
||||
if (latestSupportedVersions[availableMajor] && (Number(availableMinor) > Number(latestMinor) || (availableMinor === latestMinor && Number(availablePatch) > Number(latestPatch)))) {
|
||||
filteredNewerVersions[availableMajor] = { fullVersion: `${availableMajor}.${availableMinor}.${availablePatch}` };
|
||||
const [_latestMajor, latestMinor, latestPatch] =
|
||||
latestSupportedVersions[availableMajor].fullVersion.split('.');
|
||||
if (
|
||||
latestSupportedVersions[availableMajor] &&
|
||||
(Number(availableMinor) > Number(latestMinor) ||
|
||||
(availableMinor === latestMinor &&
|
||||
Number(availablePatch) > Number(latestPatch)))
|
||||
) {
|
||||
filteredNewerVersions[availableMajor] = {
|
||||
fullVersion: `${availableMajor}.${availableMinor}.${availablePatch}`,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
shouldUpdate: Object.keys(filteredNewerVersions).length > 0 && JSON.stringify(filteredNewerVersions) !== JSON.stringify(latestSupportedVersions),
|
||||
shouldUpdate:
|
||||
Object.keys(filteredNewerVersions).length > 0 &&
|
||||
JSON.stringify(filteredNewerVersions) !==
|
||||
JSON.stringify(latestSupportedVersions),
|
||||
versions: filteredNewerVersions,
|
||||
}
|
||||
};
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
process.exit(1);
|
||||
@@ -59,12 +81,18 @@ const checkIfThereAreNewVersions = async (github) => {
|
||||
// and returns relevant information
|
||||
const checkForMuslVersionsAndSecurityReleases = async (github, versions) => {
|
||||
try {
|
||||
const { data: unofficialBuildsIndexText } = await github.request('https://unofficial-builds.nodejs.org/download/release/index.json');
|
||||
const { data: unofficialBuildsIndexText } = await github.request(
|
||||
'https://unofficial-builds.nodejs.org/download/release/index.json',
|
||||
);
|
||||
|
||||
for (let version of Object.keys(versions)) {
|
||||
const buildVersion = unofficialBuildsIndexText.find(indexVersion => indexVersion.version === `v${versions[version].fullVersion}`);
|
||||
const buildVersion = unofficialBuildsIndexText.find(
|
||||
(indexVersion) =>
|
||||
indexVersion.version === `v${versions[version].fullVersion}`,
|
||||
);
|
||||
|
||||
versions[version].muslBuildExists = buildVersion?.files.includes("linux-x64-musl") ?? false;
|
||||
versions[version].muslBuildExists =
|
||||
buildVersion?.files.includes('linux-x64-musl') ?? false;
|
||||
versions[version].isSecurityRelease = buildVersion?.security ?? false;
|
||||
}
|
||||
return versions;
|
||||
@@ -74,30 +102,37 @@ const checkForMuslVersionsAndSecurityReleases = async (github, versions) => {
|
||||
}
|
||||
};
|
||||
|
||||
export default async function(github) {
|
||||
// if there are no new versions, exit gracefully
|
||||
// if there are new versions,
|
||||
// check for musl builds
|
||||
// then run update.sh
|
||||
export default async function (github) {
|
||||
// if there are no new versions, exit gracefully
|
||||
// if there are new versions,
|
||||
// check for musl builds
|
||||
// then run update.sh
|
||||
const { shouldUpdate, versions } = await checkIfThereAreNewVersions(github);
|
||||
|
||||
if (!shouldUpdate) {
|
||||
console.log("No new versions found. No update required.");
|
||||
console.log('No new versions found. No update required.');
|
||||
process.exit(0);
|
||||
} else {
|
||||
const newVersions = await checkForMuslVersionsAndSecurityReleases(github, versions);
|
||||
const newVersions = await checkForMuslVersionsAndSecurityReleases(
|
||||
github,
|
||||
versions,
|
||||
);
|
||||
let updatedVersions = [];
|
||||
for (const [version, newVersion] of Object.entries(newVersions)) {
|
||||
if (newVersion.muslBuildExists) {
|
||||
const { stdout } = await exec(`./update.sh ${newVersion.isSecurityRelease ? "-s " : ""}${version}`);
|
||||
const { stdout } = await exec(
|
||||
`./update.sh ${newVersion.isSecurityRelease ? '-s ' : ''}${version}`,
|
||||
);
|
||||
console.log(stdout);
|
||||
updatedVersions.push(newVersion.fullVersion);
|
||||
} else {
|
||||
console.log(`There's no musl build for version ${newVersion.fullVersion} yet.`);
|
||||
console.log(
|
||||
`There's no musl build for version ${newVersion.fullVersion} yet.`,
|
||||
);
|
||||
process.exit(0);
|
||||
}
|
||||
}
|
||||
const { stdout } = (await exec(`git diff`));
|
||||
const { stdout } = await exec(`git diff`);
|
||||
console.log(stdout);
|
||||
|
||||
return updatedVersions.join(', ');
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
# Docker and Node.js Best Practices
|
||||
|
||||
<!-- prettier-ignore-start -->
|
||||
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
|
||||
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
|
||||
## Table of Contents
|
||||
@@ -16,6 +17,7 @@
|
||||
- [Smaller images without npm/yarn](#smaller-images-without-npmyarn)
|
||||
|
||||
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
|
||||
<!-- prettier-ignore-end -->
|
||||
|
||||
## Environment Variables
|
||||
|
||||
|
||||
59
genMatrix.js
59
genMatrix.js
@@ -2,36 +2,36 @@
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
|
||||
const testFiles = [
|
||||
'genMatrix.js',
|
||||
'.github/workflows/build-test.yml',
|
||||
];
|
||||
const testFiles = ['genMatrix.js', '.github/workflows/build-test.yml'];
|
||||
|
||||
const nodeDirRegex = /^\d+$/;
|
||||
|
||||
const areTestFilesChanged = (changedFiles) => changedFiles
|
||||
.some((file) => testFiles.includes(file));
|
||||
const areTestFilesChanged = (changedFiles) =>
|
||||
changedFiles.some((file) => testFiles.includes(file));
|
||||
|
||||
// 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 }) => path.resolve(parent, name));
|
||||
const getChildDirectories = (parent) =>
|
||||
fs
|
||||
.readdirSync(parent, { withFileTypes: true })
|
||||
.filter((dirent) => dirent.isDirectory())
|
||||
.map(({ name }) => path.resolve(parent, name));
|
||||
|
||||
const getNodeVersionDirs = (base) => getChildDirectories(base)
|
||||
.filter((childPath) => nodeDirRegex.test(path.basename(childPath)));
|
||||
const getNodeVersionDirs = (base) =>
|
||||
getChildDirectories(base).filter((childPath) =>
|
||||
nodeDirRegex.test(path.basename(childPath)),
|
||||
);
|
||||
|
||||
// Returns the paths of Dockerfiles that are at: base/*/Dockerfile
|
||||
const getDockerfilesInChildDirs = (base) => getChildDirectories(base)
|
||||
.map((childDir) => path.resolve(childDir, 'Dockerfile'));
|
||||
const getDockerfilesInChildDirs = (base) =>
|
||||
getChildDirectories(base).map((childDir) =>
|
||||
path.resolve(childDir, 'Dockerfile'),
|
||||
);
|
||||
|
||||
const getAllDockerfiles = (base) => getNodeVersionDirs(base).flatMap(getDockerfilesInChildDirs);
|
||||
const getAllDockerfiles = (base) =>
|
||||
getNodeVersionDirs(base).flatMap(getDockerfilesInChildDirs);
|
||||
|
||||
const getAffectedDockerfiles = (filesAdded, filesModified, filesRenamed) => {
|
||||
const files = [
|
||||
...filesAdded,
|
||||
...filesModified,
|
||||
...filesRenamed,
|
||||
];
|
||||
const files = [...filesAdded, ...filesModified, ...filesRenamed];
|
||||
|
||||
// If the test files were changed, include everything
|
||||
if (areTestFilesChanged(files)) {
|
||||
@@ -39,21 +39,20 @@ const getAffectedDockerfiles = (filesAdded, filesModified, filesRenamed) => {
|
||||
return getAllDockerfiles(__dirname);
|
||||
}
|
||||
|
||||
const modifiedDockerfiles = files.filter((file) => file.endsWith('/Dockerfile'));
|
||||
const modifiedDockerfiles = files.filter((file) =>
|
||||
file.endsWith('/Dockerfile'),
|
||||
);
|
||||
|
||||
// Get Dockerfiles affected by modified docker-entrypoint.sh files
|
||||
const entrypointAffectedDockerfiles = files
|
||||
.filter((file) => file.endsWith('/docker-entrypoint.sh'))
|
||||
.map((file) => path.resolve(path.dirname(file), 'Dockerfile'));
|
||||
|
||||
return [
|
||||
...modifiedDockerfiles,
|
||||
...entrypointAffectedDockerfiles,
|
||||
];
|
||||
return [...modifiedDockerfiles, ...entrypointAffectedDockerfiles];
|
||||
};
|
||||
|
||||
const getFullNodeVersionFromDockerfile = (file) => fs.readFileSync(file, 'utf8')
|
||||
.match(/^ENV NODE_VERSION=(\d*\.*\d*\.\d*)/m)[1];
|
||||
const getFullNodeVersionFromDockerfile = (file) =>
|
||||
fs.readFileSync(file, 'utf8').match(/^ENV NODE_VERSION=(\d*\.*\d*\.\d*)/m)[1];
|
||||
|
||||
const getDockerfileMatrixEntry = (file) => {
|
||||
const [variant] = path.dirname(file).split(path.sep).slice(-1);
|
||||
@@ -67,14 +66,14 @@ const getDockerfileMatrixEntry = (file) => {
|
||||
};
|
||||
|
||||
const generateBuildMatrix = (filesAdded, filesModified, filesRenamed) => {
|
||||
const dockerfiles = [...new Set(getAffectedDockerfiles(filesAdded, filesModified, filesRenamed))];
|
||||
const dockerfiles = [
|
||||
...new Set(getAffectedDockerfiles(filesAdded, filesModified, filesRenamed)),
|
||||
];
|
||||
|
||||
const entries = dockerfiles.map(getDockerfileMatrixEntry);
|
||||
|
||||
// Return null if there are no entries so we can skip the matrix step
|
||||
return entries.length
|
||||
? { include: entries }
|
||||
: null;
|
||||
return entries.length ? { include: entries } : null;
|
||||
};
|
||||
|
||||
module.exports = generateBuildMatrix;
|
||||
|
||||
141
stackbrew.js
141
stackbrew.js
@@ -6,8 +6,9 @@ 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()
|
||||
.execSync(`git log -1 --format=%H HEAD -- ${path}`)
|
||||
.toString()
|
||||
.trim();
|
||||
}
|
||||
|
||||
const stackbrewPath = path.basename(__filename);
|
||||
@@ -23,11 +24,11 @@ GitFetch: refs/heads/main\n`;
|
||||
|
||||
const config = require('./versions.json');
|
||||
|
||||
const versions = Object.keys(config).reverse()
|
||||
const versions = Object.keys(config).reverse();
|
||||
|
||||
let midnight = new Date()
|
||||
midnight.setHours(0, 0, 0, 0)
|
||||
const now = midnight.getTime()
|
||||
let midnight = new Date();
|
||||
midnight.setHours(0, 0, 0, 0);
|
||||
const now = midnight.getTime();
|
||||
const alpineRE = new RegExp(/alpine*/);
|
||||
const slimRE = new RegExp(/\*-slim/);
|
||||
let foundLTS = false;
|
||||
@@ -37,117 +38,135 @@ for (const version of versions) {
|
||||
let lts = new Date(`${config[version].lts}T00:00:00.00`).getTime();
|
||||
let isCurrent = foundCurrent ? false : isNaN(lts) || lts >= now;
|
||||
foundCurrent = isCurrent || foundCurrent;
|
||||
let isLTS = foundLTS ? false : (now >= lts);
|
||||
let isLTS = foundLTS ? false : now >= lts;
|
||||
foundLTS = isLTS || foundLTS;
|
||||
let codename = config[version].codename
|
||||
let defaultAlpine = config[version]['alpine-default']
|
||||
let defaultDebian = config[version]['debian-default']
|
||||
let variants = config[version].variants
|
||||
let codename = config[version].codename;
|
||||
let defaultAlpine = config[version]['alpine-default'];
|
||||
let defaultDebian = config[version]['debian-default'];
|
||||
let variants = config[version].variants;
|
||||
for (const variant in variants) {
|
||||
let dockerfilePath = path.join(version, variant, 'Dockerfile');
|
||||
let isAlpine = alpineRE.test(variant)
|
||||
let isSlim = slimRE.test(variant)
|
||||
let isDefaultSlim = new RegExp(`${defaultDebian}-slim`).test(variant)
|
||||
let isAlpine = alpineRE.test(variant);
|
||||
let isSlim = slimRE.test(variant);
|
||||
let isDefaultSlim = new RegExp(`${defaultDebian}-slim`).test(variant);
|
||||
|
||||
// Get full version from the Dockerfile
|
||||
let dockerfile = fs.readFileSync(dockerfilePath, 'utf-8')
|
||||
let fullVersion = dockerfile.match(/ENV NODE_VERSION=(?<major>\d+)\.(?<minor>\d+)\.(?<patch>\d+)/)
|
||||
let dockerfile = fs.readFileSync(dockerfilePath, 'utf-8');
|
||||
let fullVersion = dockerfile.match(
|
||||
/ENV NODE_VERSION=(?<major>\d+)\.(?<minor>\d+)\.(?<patch>\d+)/,
|
||||
);
|
||||
|
||||
let tags = [
|
||||
`${fullVersion.groups.major}.${fullVersion.groups.minor}.${fullVersion.groups.patch}-${variant}`,
|
||||
`${fullVersion.groups.major}.${fullVersion.groups.minor}-${variant}`,
|
||||
`${fullVersion.groups.major}-${variant}`,
|
||||
]
|
||||
];
|
||||
|
||||
if (codename) {
|
||||
tags.push(`${codename}-${variant}`)
|
||||
tags.push(`${codename}-${variant}`);
|
||||
}
|
||||
|
||||
if (variant === defaultAlpine) {
|
||||
tags.push(`${fullVersion.groups.major}.${fullVersion.groups.minor}.${fullVersion.groups.patch}-alpine`)
|
||||
tags.push(`${fullVersion.groups.major}.${fullVersion.groups.minor}-alpine`)
|
||||
tags.push(`${fullVersion.groups.major}-alpine`)
|
||||
tags.push(
|
||||
`${fullVersion.groups.major}.${fullVersion.groups.minor}.${fullVersion.groups.patch}-alpine`,
|
||||
);
|
||||
tags.push(
|
||||
`${fullVersion.groups.major}.${fullVersion.groups.minor}-alpine`,
|
||||
);
|
||||
tags.push(`${fullVersion.groups.major}-alpine`);
|
||||
if (codename) {
|
||||
tags.push(`${codename}-alpine`)
|
||||
tags.push(`${codename}-alpine`);
|
||||
}
|
||||
}
|
||||
|
||||
if (variant === defaultDebian) {
|
||||
tags.push(`${fullVersion.groups.major}.${fullVersion.groups.minor}.${fullVersion.groups.patch}`)
|
||||
tags.push(`${fullVersion.groups.major}.${fullVersion.groups.minor}`)
|
||||
tags.push(`${fullVersion.groups.major}`)
|
||||
tags.push(
|
||||
`${fullVersion.groups.major}.${fullVersion.groups.minor}.${fullVersion.groups.patch}`,
|
||||
);
|
||||
tags.push(`${fullVersion.groups.major}.${fullVersion.groups.minor}`);
|
||||
tags.push(`${fullVersion.groups.major}`);
|
||||
if (isSlim) {
|
||||
tags.push(`${fullVersion.groups.major}.${fullVersion.groups.minor}.${fullVersion.groups.patch}-slim`)
|
||||
tags.push(`${fullVersion.groups.major}.${fullVersion.groups.minor}-slim`)
|
||||
tags.push(`${fullVersion.groups.major}-slim`)
|
||||
tags.push(
|
||||
`${fullVersion.groups.major}.${fullVersion.groups.minor}.${fullVersion.groups.patch}-slim`,
|
||||
);
|
||||
tags.push(
|
||||
`${fullVersion.groups.major}.${fullVersion.groups.minor}-slim`,
|
||||
);
|
||||
tags.push(`${fullVersion.groups.major}-slim`);
|
||||
}
|
||||
if (codename) {
|
||||
tags.push(`${codename}`)
|
||||
tags.push(`${codename}`);
|
||||
}
|
||||
}
|
||||
if (isDefaultSlim) {
|
||||
tags.push(`${fullVersion.groups.major}.${fullVersion.groups.minor}.${fullVersion.groups.patch}-slim`)
|
||||
tags.push(`${fullVersion.groups.major}.${fullVersion.groups.minor}-slim`)
|
||||
tags.push(`${fullVersion.groups.major}-slim`)
|
||||
tags.push(
|
||||
`${fullVersion.groups.major}.${fullVersion.groups.minor}.${fullVersion.groups.patch}-slim`,
|
||||
);
|
||||
tags.push(`${fullVersion.groups.major}.${fullVersion.groups.minor}-slim`);
|
||||
tags.push(`${fullVersion.groups.major}-slim`);
|
||||
if (codename) {
|
||||
tags.push(`${codename}-slim`)
|
||||
tags.push(`${codename}-slim`);
|
||||
}
|
||||
}
|
||||
|
||||
if (isCurrent) {
|
||||
if (variant === defaultAlpine) {
|
||||
tags.push(variant)
|
||||
tags.push(`${fullVersion.groups.major}.${fullVersion.groups.minor}.${fullVersion.groups.patch}-alpine`)
|
||||
tags.push(`${fullVersion.groups.major}.${fullVersion.groups.minor}-alpine`)
|
||||
tags.push(`${fullVersion.groups.major}-alpine`)
|
||||
tags.push('alpine')
|
||||
tags.push('current-alpine')
|
||||
tags.push(variant);
|
||||
tags.push(
|
||||
`${fullVersion.groups.major}.${fullVersion.groups.minor}.${fullVersion.groups.patch}-alpine`,
|
||||
);
|
||||
tags.push(
|
||||
`${fullVersion.groups.major}.${fullVersion.groups.minor}-alpine`,
|
||||
);
|
||||
tags.push(`${fullVersion.groups.major}-alpine`);
|
||||
tags.push('alpine');
|
||||
tags.push('current-alpine');
|
||||
}
|
||||
if (variant === defaultDebian) {
|
||||
tags.push(variant)
|
||||
tags.push('latest')
|
||||
tags.push('current')
|
||||
tags.push(variant);
|
||||
tags.push('latest');
|
||||
tags.push('current');
|
||||
}
|
||||
if (isAlpine) {
|
||||
tags.push(`${variant}`)
|
||||
tags.push(`current-${variant}`)
|
||||
tags.push(`${variant}`);
|
||||
tags.push(`current-${variant}`);
|
||||
}
|
||||
if (!isAlpine) {
|
||||
tags.push(`${variant}`)
|
||||
tags.push(`current-${variant}`)
|
||||
tags.push(`${variant}`);
|
||||
tags.push(`current-${variant}`);
|
||||
}
|
||||
if (isDefaultSlim) {
|
||||
tags.push('slim')
|
||||
tags.push('current-slim')
|
||||
tags.push('slim');
|
||||
tags.push('current-slim');
|
||||
}
|
||||
}
|
||||
|
||||
if (isLTS) {
|
||||
tags.push(`lts-${variant}`)
|
||||
tags.push(`lts-${variant}`);
|
||||
if (variant === defaultDebian) {
|
||||
tags.push('lts')
|
||||
tags.push('lts');
|
||||
if (codename) {
|
||||
tags.push(`lts-${codename}`)
|
||||
tags.push(`lts-${codename}`);
|
||||
}
|
||||
}
|
||||
if (isDefaultSlim) {
|
||||
tags.push(`lts-slim`)
|
||||
tags.push(`lts-slim`);
|
||||
}
|
||||
if (variant === defaultAlpine) {
|
||||
tags.push(`lts-alpine`)
|
||||
tags.push(`lts-alpine`);
|
||||
}
|
||||
}
|
||||
|
||||
// remove duplicates
|
||||
tags = tags.filter((x, i, a) => a.indexOf(x) == i)
|
||||
tags = tags.sort()
|
||||
let directory = `${version}/${variant}`
|
||||
stackbrew += `\nTags: ${tags.join(', ')}\n`
|
||||
stackbrew += `Architectures: ${config[version].variants[variant].join(', ')}\n`
|
||||
stackbrew += `GitCommit: ${getCommitHasForPath(directory)}\n`
|
||||
stackbrew += `Directory: ${directory}\n`
|
||||
tags = tags.filter((x, i, a) => a.indexOf(x) == i);
|
||||
tags = tags.sort();
|
||||
let directory = `${version}/${variant}`;
|
||||
stackbrew += `\nTags: ${tags.join(', ')}\n`;
|
||||
stackbrew += `Architectures: ${config[version].variants[variant].join(', ')}\n`;
|
||||
stackbrew += `GitCommit: ${getCommitHasForPath(directory)}\n`;
|
||||
stackbrew += `Directory: ${directory}\n`;
|
||||
}
|
||||
}
|
||||
|
||||
// output
|
||||
console.log(stackbrew)
|
||||
console.log(stackbrew);
|
||||
|
||||
Reference in New Issue
Block a user