-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathci-cd.js
More file actions
52 lines (45 loc) · 1.39 KB
/
ci-cd.js
File metadata and controls
52 lines (45 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env node
/**
* CI/CD pipeline — pack and publish a ModelKit.
*
* Reads credentials and version metadata from environment variables so nothing
* sensitive ends up in the script or the process list.
*
* Typical usage in GitHub Actions:
*
* - name: Publish ModelKit
* run: node examples/ci-cd.js
* env:
* REGISTRY: ghcr.io
* REGISTRY_USER: ${{ github.actor }}
* REGISTRY_PASS: ${{ secrets.GITHUB_TOKEN }}
* MODEL_VERSION: ${{ github.ref_name }}
*
* Run locally: REGISTRY=... REGISTRY_USER=... REGISTRY_PASS=... node examples/ci-cd.js
*/
import { login, pack, push, logout } from '../dist/index.js';
const registry = requireEnv('REGISTRY');
const user = requireEnv('REGISTRY_USER');
const pass = requireEnv('REGISTRY_PASS');
const version = process.env.MODEL_VERSION ?? 'latest';
const ref = `${registry}/org/my-model:${version}`;
await login(registry, user, pass);
console.log(`Logged in to ${registry}`);
try {
await pack('.', { tag: ref });
console.log(`Packed: ${ref}`);
await push(ref);
console.log(`Pushed: ${ref}`);
} finally {
// Always log out so credentials aren't cached on shared runners.
await logout(registry);
console.log('Logged out.');
}
function requireEnv(name) {
const value = process.env[name];
if (!value) {
console.error(`Missing required environment variable: ${name}`);
process.exit(1);
}
return value;
}