Skip to content

Commit

Permalink
no more concurrency. breaks computer
Browse files Browse the repository at this point in the history
  • Loading branch information
Ethan-Arrowood committed Dec 2, 2024
1 parent ce61a75 commit 4270782
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 58 deletions.
3 changes: 3 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## How publishing this module works

HarperDB Components require the `config.yaml` to be in the root of the project; however, in order for the Docker
34 changes: 24 additions & 10 deletions util/base.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,36 @@ RUN apt-get update && apt-get install -y \
curl \
&& rm -rf /var/lib/apt/lists/*

RUN mkdir -p /@harperdb/nextjs

COPY --exclude=.github --exclude=fixtures --exclude=test --exclude=util --exclude=node_modules --exclude=.node-version --exclude=.git \
. /@harperdb/nextjs

RUN npm install -C /@harperdb/nextjs

# Install HarperDB Globally
RUN npm install -g harperdb

RUN mkdir -p /hdb/components

# Set HarperDB Environment Variables
ENV TC_AGREEMENT=yes
ENV HDB_ADMIN_USERNAME=hdb_admin
ENV HDB_ADMIN_PASSWORD=password
ENV ROOTPATH=/hdb
ENV OPERATIONSAPI_NETWORK_PORT=9925
ENV HTTP_PORT=9926
ENV THREADS_COUNT=1
ENV LOG_TO_STDSTREAMS=true
ENV LOG_TO_FILE=true

# Create components directory
RUN mkdir -p /hdb/components

# Add base component
COPY /fixtures/harperdb-base-component /hdb/components/harperdb-base-component

# Create the @harperdb/nextjs module directory so it can be linked locally
RUN mkdir -p /@harperdb/nextjs

# Cache Bust copying project files
ARG CACHE_BUST
RUN echo "${CACHE_BUST}"
COPY config.yaml extension.js cli.js schema.graphql package.json /@harperdb/nextjs/

# Install dependencies for the @harperdb/nextjs module
RUN npm install -C /@harperdb/nextjs

COPY /fixtures/harperdb-base-component /hdb/components/harperdb-base-component
# Create link to the @harperdb/nextjs module
RUN npm link -C /@harperdb/nextjs
15 changes: 15 additions & 0 deletions util/cache-bust.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { spawn } from 'child_process';
import { createHash } from 'crypto';
import { join } from 'path';
import { pipeline } from 'stream/promises';

export function getCacheBustValue() {
return new Promise((resolve, reject) => {
const proc = spawn('git', ['status', '--porcelain'], { cwd: join(import.meta.dirname, '..') })
proc.on('error', reject);
const hash = createHash('sha1');
pipeline(proc.stdout, hash).then(() => resolve(hash.digest('hex'))).catch(reject);
});
}

export const CACHE_BUST = getCacheBustValue();
93 changes: 45 additions & 48 deletions util/pretest.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,29 @@ import { join } from 'node:path';
import { containerEngine } from './get-container-engine.js';
import { getNextImageName } from './get-next-image-name.js';
import { CollectedTransform } from './collected-transform.js';
import { CACHE_BUST } from './cache-bust.js';

const DEBUG = process.env.DEBUG === '1';

const NODE_MAJORS = ['18', '20', '22'];
const NEXT_MAJORS = ['13', '14', '15'];

const getNodeBaseImageName = (nodeMajor) => `harperdb-nextjs/node-base-${nodeMajor}`;

function validateResult(result) {
const success = result.code === 0;

if (DEBUG || !success) {
console.log(`Image \x1b[94m${result.name}\x1b[0m build process exited with: \x1b[35m${result.code}\x1b[0m\n`);
result.stdout !== '' && console.log('\x1b[32mstdout\x1b[0m:\n' + result.stdout + '\n');
result.stderr !== '' && console.log('\x1b[31mstderr\x1b[0m:\n' + result.stderr + '\n');
}

if (!success) {
process.exit(1);
}
}

function build(name, args, options = {}) {
return new Promise((resolve, reject) => {
const buildProcess = spawn(containerEngine, args, { stdio: ['ignore', 'pipe', 'pipe'], ...options });
Expand All @@ -30,59 +46,40 @@ function build(name, args, options = {}) {
}

// Build Node Base Images
const nodeImagesBuildResults = await Promise.all(
NODE_MAJORS.map((nodeMajor) =>
build(getNodeBaseImageName(nodeMajor), [
for (const nodeMajor of NODE_MAJORS) {
const buildResult = await build(getNodeBaseImageName(nodeMajor), [
'build',
'--build-arg',
`NODE_MAJOR=${nodeMajor}`,
'--build-arg',
`CACHE_BUST=${CACHE_BUST}`,
'-t',
getNodeBaseImageName(nodeMajor),
'-f',
join(import.meta.dirname, 'base.dockerfile'),
join(import.meta.dirname, '..'),
]);

validateResult(buildResult);
}

// Build Next.js Images

for (const nextMajor of NEXT_MAJORS) {
for (const nodeMajor of NODE_MAJORS) {
const buildResult = await build(getNextImageName(nextMajor, nodeMajor), [
'build',
'--build-arg',
`NODE_MAJOR=${nodeMajor}`,
`BASE_IMAGE=${getNodeBaseImageName(nodeMajor)}`,
'--build-arg',
`NEXT_MAJOR=${nextMajor}`,
'-t',
getNodeBaseImageName(nodeMajor),
getNextImageName(nextMajor, nodeMajor),
'-f',
join(import.meta.dirname, 'base.dockerfile'),
join(import.meta.dirname, 'next.dockerfile'),
join(import.meta.dirname, '..'),
])
)
);

validateResults(nodeImagesBuildResults);

const NEXT_MAJORS = ['13', '14', '15'];
]);

for (const nextMajor of NEXT_MAJORS) {
const nextImageBuildResults = await Promise.all(
NODE_MAJORS.map((nodeMajor) =>
build(getNextImageName(nextMajor, nodeMajor), [
'build',
'--build-arg',
`BASE_IMAGE=${getNodeBaseImageName(nodeMajor)}`,
'--build-arg',
`NEXT_MAJOR=${nextMajor}`,
'-t',
getNextImageName(nextMajor, nodeMajor),
'-f',
join(import.meta.dirname, 'next.dockerfile'),
join(import.meta.dirname, '..'),
])
)
);

validateResults(nextImageBuildResults);
}

function validateResults(results) {
let success = true;
for (const result of results) {
if (result.code !== 0) success = false;

if (DEBUG || !success) {
console.log(`Image \x1b[94m${result.name}\x1b[0m build process exited with: \x1b[35m${result.code}\x1b[0m\n`);
result.stdout !== '' && console.log('\x1b[32mstdout\x1b[0m:\n' + result.stdout + '\n');
result.stderr !== '' && console.log('\x1b[31mstderr\x1b[0m:\n' + result.stderr + '\n');
}
}

if (!success) {
process.exit(1);
validateResult(buildResult);
}
}

0 comments on commit 4270782

Please sign in to comment.