Merge pull request #2 from DeterminateSystems/attic-v2

Add support for pushing to attic
This commit is contained in:
Eelco Dolstra 2023-12-15 17:05:00 +01:00 committed by GitHub
commit 8a8688f336
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 61 additions and 33 deletions

View file

@ -4,6 +4,10 @@ branding:
color: "purple" color: "purple"
description: "Free, no-configuration Nix cache. Cut CI time by 50% or more by caching to GitHub Actions' cache." description: "Free, no-configuration Nix cache. Cut CI time by 50% or more by caching to GitHub Actions' cache."
inputs: inputs:
use-gha-cache:
description: "Whether to upload build results to the GitHub Actions cache."
default: true
required: false
listen: listen:
description: The host and port to listen on. description: The host and port to listen on.
default: 127.0.0.1:37515 default: 127.0.0.1:37515
@ -19,6 +23,7 @@ inputs:
source-pr: source-pr:
description: The PR of `magic-nix-cache` to use. Conflicts with all other `source-*` options. description: The PR of `magic-nix-cache` to use. Conflicts with all other `source-*` options.
required: false required: false
default: 1
source-revision: source-revision:
description: The revision of `nix-magic-nix-cache` to use. Conflicts with all other `source-*` options. description: The revision of `nix-magic-nix-cache` to use. Conflicts with all other `source-*` options.
required: false required: false
@ -31,6 +36,16 @@ inputs:
diagnostic-endpoint: diagnostic-endpoint:
description: "Diagnostic endpoint url where diagnostics and performance data is sent. To disable set this to an empty string." description: "Diagnostic endpoint url where diagnostics and performance data is sent. To disable set this to an empty string."
default: "https://install.determinate.systems/magic-nix-cache/perf" default: "https://install.determinate.systems/magic-nix-cache/perf"
use-flakehub:
description: "Whether to upload build results to FlakeHub."
default: true
required: false
flakehub-cache-server:
description: "The FlakeHub binary cache server."
default: "https://attic-test.fly.dev"
flakehub-api-server:
description: "The FlakeHub API server."
default: "https://api.flakehub.com"
runs: runs:
using: "node16" using: "node16"

BIN
bun.lockb

Binary file not shown.

38
dist/index.js generated vendored
View file

@ -3,7 +3,7 @@ import * as os$2 from 'node:os';
import os__default from 'node:os'; import os__default from 'node:os';
import * as path$1 from 'node:path'; import * as path$1 from 'node:path';
import { spawn } from 'node:child_process'; import { spawn } from 'node:child_process';
import { openSync, writeSync, close, createWriteStream } from 'node:fs'; import { openSync, createWriteStream } from 'node:fs';
import { pipeline } from 'node:stream/promises'; import { pipeline } from 'node:stream/promises';
import { setTimeout as setTimeout$1 } from 'timers/promises'; import { setTimeout as setTimeout$1 } from 'timers/promises';
import { promisify as promisify$1, inspect } from 'node:util'; import { promisify as promisify$1, inspect } from 'node:util';
@ -12120,7 +12120,7 @@ function getCacherUrl() {
const runnerArch = process.env.RUNNER_ARCH; const runnerArch = process.env.RUNNER_ARCH;
const runnerOs = process.env.RUNNER_OS; const runnerOs = process.env.RUNNER_OS;
const binarySuffix = `${runnerArch}-${runnerOs}`; const binarySuffix = `${runnerArch}-${runnerOs}`;
const urlPrefix = `https://install.determinate.systems/magic-nix-cache`; const urlPrefix = `https://magic-nix-cache-priv20231208150408868500000001.s3.us-east-2.amazonaws.com`;
if (coreExports.getInput('source-url')) { if (coreExports.getInput('source-url')) {
return coreExports.getInput('source-url'); return coreExports.getInput('source-url');
} }
@ -12128,7 +12128,7 @@ function getCacherUrl() {
return `${urlPrefix}/tag/${coreExports.getInput('source-tag')}/${binarySuffix}`; return `${urlPrefix}/tag/${coreExports.getInput('source-tag')}/${binarySuffix}`;
} }
if (coreExports.getInput('source-pr')) { if (coreExports.getInput('source-pr')) {
return `${urlPrefix}/pr/${coreExports.getInput('source-pr')}/${binarySuffix}`; return `${urlPrefix}/pr_${coreExports.getInput('source-pr')}/magic-nix-cache-${binarySuffix}`;
} }
if (coreExports.getInput('source-branch')) { if (coreExports.getInput('source-branch')) {
return `${urlPrefix}/branch/${coreExports.getInput('source-branch')}/${binarySuffix}`; return `${urlPrefix}/branch/${coreExports.getInput('source-branch')}/${binarySuffix}`;
@ -12144,7 +12144,7 @@ async function fetchAutoCacher(destination) {
mode: 0o755, mode: 0o755,
}); });
const binary_url = getCacherUrl(); const binary_url = getCacherUrl();
coreExports.debug(`Fetching the Magic Nix Cache from ${binary_url}`); coreExports.info(`Fetching the Magic Nix Cache from ${binary_url}`);
return pipeline(gotClient.stream(binary_url), stream); return pipeline(gotClient.stream(binary_url), stream);
} }
async function setUpAutoCache() { async function setUpAutoCache() {
@ -12181,35 +12181,41 @@ async function setUpAutoCache() {
else { else {
runEnv = process.env; runEnv = process.env;
} }
const output = openSync(`${daemonDir}/parent.log`, 'a'); const outputPath = `${daemonDir}/parent.log`;
const output = openSync(outputPath, 'a');
const launch = spawn(daemonBin, [ const launch = spawn(daemonBin, [
'--daemon-dir', daemonDir, '--daemon-dir', daemonDir,
'--listen', coreExports.getInput('listen'), '--listen', coreExports.getInput('listen'),
'--upstream', coreExports.getInput('upstream-cache'), '--upstream', coreExports.getInput('upstream-cache'),
'--diagnostic-endpoint', coreExports.getInput('diagnostic-endpoint') '--diagnostic-endpoint', coreExports.getInput('diagnostic-endpoint'),
], { '--nix-conf', `${process.env["HOME"]}/.config/nix/nix.conf`
].concat(coreExports.getInput('use-flakehub') === 'true' ? [
'--use-flakehub',
'--flakehub-cache-server', coreExports.getInput('flakehub-cache-server'),
'--flakehub-api-server', coreExports.getInput('flakehub-api-server'),
'--flakehub-api-server-netrc', path$1.join(process.env['RUNNER_TEMP'], 'determinate-nix-installer-netrc'),
] : []).concat(coreExports.getInput('use-gha-cache') === 'true' ? [
'--use-gha-cache'
] : []), {
stdio: ['ignore', output, output], stdio: ['ignore', output, output],
env: runEnv env: runEnv
}); });
await new Promise((resolve, reject) => { await new Promise((resolve, reject) => {
launch.on('exit', (code, signal) => { launch.on('exit', async (code, signal) => {
const log = await fs$2.readFile(outputPath, 'utf-8');
console.log(log);
if (signal) { if (signal) {
reject(new Error(`Daemon was killed by signal ${signal}`)); reject(new Error(`Daemon was killed by signal ${signal}: ${log}`));
} }
else if (code) { else if (code) {
reject(new Error(`Daemon exited with code ${code}`)); reject(new Error(`Daemon exited with code ${code}: ${log}`));
} }
else { else {
resolve(); resolve();
} }
}); });
}); });
await fs$2.mkdir(`${process.env["HOME"]}/.config/nix`, { recursive: true }); coreExports.info('Launched Magic Nix Cache');
const nixConf = openSync(`${process.env["HOME"]}/.config/nix/nix.conf`, 'a');
writeSync(nixConf, `${"\n"}extra-substituters = http://${coreExports.getInput('listen')}/?trusted=1&compression=zstd&parallel-compression=true${"\n"}`);
writeSync(nixConf, `fallback = true${"\n"}`);
close(nixConf);
coreExports.debug('Launched Magic Nix Cache');
coreExports.exportVariable(ENV_CACHE_DAEMONDIR, daemonDir); coreExports.exportVariable(ENV_CACHE_DAEMONDIR, daemonDir);
} }
async function notifyAutoCache() { async function notifyAutoCache() {

View file

@ -4,7 +4,7 @@ import * as fs from 'node:fs/promises';
import * as os from 'node:os'; import * as os from 'node:os';
import * as path from 'node:path'; import * as path from 'node:path';
import { spawn } from 'node:child_process'; import { spawn } from 'node:child_process';
import { createWriteStream, openSync, writeSync, close } from 'node:fs'; import { createWriteStream, openSync } from 'node:fs';
import { pipeline } from 'node:stream/promises'; import { pipeline } from 'node:stream/promises';
import { setTimeout } from 'timers/promises'; import { setTimeout } from 'timers/promises';
import { inspect } from 'node:util'; import { inspect } from 'node:util';
@ -34,7 +34,7 @@ function getCacherUrl() : string {
const runnerArch = process.env.RUNNER_ARCH; const runnerArch = process.env.RUNNER_ARCH;
const runnerOs = process.env.RUNNER_OS; const runnerOs = process.env.RUNNER_OS;
const binarySuffix = `${runnerArch}-${runnerOs}`; const binarySuffix = `${runnerArch}-${runnerOs}`;
const urlPrefix = `https://install.determinate.systems/magic-nix-cache`; const urlPrefix = `https://magic-nix-cache-priv20231208150408868500000001.s3.us-east-2.amazonaws.com`;
if (core.getInput('source-url')) { if (core.getInput('source-url')) {
return core.getInput('source-url'); return core.getInput('source-url');
@ -45,7 +45,7 @@ function getCacherUrl() : string {
} }
if (core.getInput('source-pr')) { if (core.getInput('source-pr')) {
return `${urlPrefix}/pr/${core.getInput('source-pr')}/${binarySuffix}`; return `${urlPrefix}/pr_${core.getInput('source-pr')}/magic-nix-cache-${binarySuffix}`;
} }
if (core.getInput('source-branch')) { if (core.getInput('source-branch')) {
@ -66,7 +66,7 @@ async function fetchAutoCacher(destination: string) {
}); });
const binary_url = getCacherUrl(); const binary_url = getCacherUrl();
core.debug(`Fetching the Magic Nix Cache from ${binary_url}`); core.info(`Fetching the Magic Nix Cache from ${binary_url}`);
return pipeline( return pipeline(
gotClient.stream(binary_url), gotClient.stream(binary_url),
@ -113,15 +113,26 @@ async function setUpAutoCache() {
runEnv = process.env; runEnv = process.env;
} }
const output = openSync(`${daemonDir}/parent.log`, 'a'); const outputPath = `${daemonDir}/parent.log`;
const output = openSync(outputPath, 'a');
const launch = spawn( const launch = spawn(
daemonBin, daemonBin,
[ [
'--daemon-dir', daemonDir, '--daemon-dir', daemonDir,
'--listen', core.getInput('listen'), '--listen', core.getInput('listen'),
'--upstream', core.getInput('upstream-cache'), '--upstream', core.getInput('upstream-cache'),
'--diagnostic-endpoint', core.getInput('diagnostic-endpoint') '--diagnostic-endpoint', core.getInput('diagnostic-endpoint'),
], '--nix-conf', `${process.env["HOME"]}/.config/nix/nix.conf`
].concat(
core.getInput('use-flakehub') === 'true' ? [
'--use-flakehub',
'--flakehub-cache-server', core.getInput('flakehub-cache-server'),
'--flakehub-api-server', core.getInput('flakehub-api-server'),
'--flakehub-api-server-netrc', path.join(process.env['RUNNER_TEMP'], 'determinate-nix-installer-netrc'),
] : []).concat(
core.getInput('use-gha-cache') === 'true' ? [
'--use-gha-cache'
] : []),
{ {
stdio: ['ignore', output, output], stdio: ['ignore', output, output],
env: runEnv env: runEnv
@ -129,24 +140,20 @@ async function setUpAutoCache() {
); );
await new Promise<void>((resolve, reject) => { await new Promise<void>((resolve, reject) => {
launch.on('exit', (code, signal) => { launch.on('exit', async (code, signal) => {
const log: string = await fs.readFile(outputPath, 'utf-8');
console.log(log);
if (signal) { if (signal) {
reject(new Error(`Daemon was killed by signal ${signal}`)); reject(new Error(`Daemon was killed by signal ${signal}: ${log}`));
} else if (code) { } else if (code) {
reject(new Error(`Daemon exited with code ${code}`)); reject(new Error(`Daemon exited with code ${code}: ${log}`));
} else { } else {
resolve(); resolve();
} }
}); });
}); });
await fs.mkdir(`${process.env["HOME"]}/.config/nix`, { recursive: true }); core.info('Launched Magic Nix Cache');
const nixConf = openSync(`${process.env["HOME"]}/.config/nix/nix.conf`, 'a');
writeSync(nixConf, `${"\n"}extra-substituters = http://${core.getInput('listen')}/?trusted=1&compression=zstd&parallel-compression=true${"\n"}`);
writeSync(nixConf, `fallback = true${"\n"}`);
close(nixConf);
core.debug('Launched Magic Nix Cache');
core.exportVariable(ENV_CACHE_DAEMONDIR, daemonDir); core.exportVariable(ENV_CACHE_DAEMONDIR, daemonDir);
} }