gitdataai/scripts/push.js
ZhenYi 1daab11ba4 feat(scripts): add deployment and build utility scripts
Replace old scripting approach with new build, deploy, push,
and uninstall utilities.
2026-05-11 17:08:29 +08:00

43 lines
1.4 KiB
JavaScript

import {execSync} from 'child_process';
import {dirname, resolve} from 'path';
import {fileURLToPath} from 'url';
import process from 'process';
const __dirname = dirname(fileURLToPath(import.meta.url));
const ROOT = resolve(__dirname, '..');
const G = (s) => `\x1b[0;32m${s}\x1b[0m`;
const R = (s) => `\x1b[0;31m${s}\x1b[0m`;
const log = (msg) => console.log(`${G('[OK]')} ${msg}`);
const err = (msg) => {
console.error(`${R('[ERR]')} ${msg}`);
process.exit(1);
};
const REGISTRY = process.env.REGISTRY || 'harbor.gitdata.me/gtateam';
const TAG = process.env.TAG || execSync('git rev-parse --short HEAD', {encoding: 'utf8', cwd: ROOT}).trim();
const USER = process.env.DOCKER_USERNAME;
const PASS = process.env.DOCKER_PASSWORD;
if (!USER) err('DOCKER_USERNAME env var required');
if (!PASS) err('DOCKER_PASSWORD env var required');
log(`Logging into ${REGISTRY}...`);
execSync(`echo "${PASS}" | docker login "${REGISTRY}" -u "${USER}" --password-stdin`, {stdio: 'inherit'});
const images = ['app', 'email-worker', 'git-hook', 'gitserver', 'metrics-aggregator', 'static-server', 'gingress'];
for (const name of images) {
const src = `${name}:${TAG}`;
const dst = `${REGISTRY}/${name}:${TAG}`;
log(`Tagging ${src} -> ${dst}`);
execSync(`docker tag "${src}" "${dst}"`, {stdio: 'inherit'});
log(`Pushing ${dst}`);
execSync(`docker push "${dst}"`, {stdio: 'inherit'});
}
log(`All images pushed to ${REGISTRY}`);