refactor: local compile + docker push workflow
- build.js: cargo build first, then docker build — no more Docker-in-Docker - .dockerignore: exclude target/ but re-include target/x86_64-unknown-linux-gnu/release/ so pre-built binaries are available in Docker build context
This commit is contained in:
parent
f026dcfae2
commit
dfe4cb6207
@ -7,8 +7,6 @@ node_modules/
|
|||||||
.env.local
|
.env.local
|
||||||
.env.*.local
|
.env.*.local
|
||||||
|
|
||||||
# Exclude all target artifacts except the linux release binaries
|
# Exclude all target/ content, then selectively re-include linux release binaries
|
||||||
target/
|
target/
|
||||||
!target/x86_64-unknown-linux-gnu/
|
|
||||||
target/x86_64-unknown-linux-gnu/
|
|
||||||
!target/x86_64-unknown-linux-gnu/release/
|
!target/x86_64-unknown-linux-gnu/release/
|
||||||
|
|||||||
31
.drone.yml
31
.drone.yml
@ -60,14 +60,29 @@ steps:
|
|||||||
- |
|
- |
|
||||||
TAG="${DRONE_TAG:-${DRONE_COMMIT_SHA:0:8}}"
|
TAG="${DRONE_TAG:-${DRONE_COMMIT_SHA:0:8}}"
|
||||||
echo "==> Building images with tag: ${TAG}"
|
echo "==> Building images with tag: ${TAG}"
|
||||||
/kaniko/executor --context . --dockerfile docker/app.Dockerfile --destination ${REGISTRY}/app:${TAG} --destination ${REGISTRY}/app:latest
|
/kaniko/executor --context . --dockerfile docker/app.Dockerfile \
|
||||||
/kaniko/executor --context . --dockerfile docker/gitserver.Dockerfile --destination ${REGISTRY}/gitserver:${TAG} --destination ${REGISTRY}/gitserver:latest
|
--cache --cache-dir target \
|
||||||
/kaniko/executor --context . --dockerfile docker/email-worker.Dockerfile --destination ${REGISTRY}/email-worker:${TAG} --destination ${REGISTRY}/email-worker:latest
|
--destination ${REGISTRY}/app:${TAG} --destination ${REGISTRY}/app:latest
|
||||||
/kaniko/executor --context . --dockerfile docker/git-hook.Dockerfile --destination ${REGISTRY}/git-hook:${TAG} --destination ${REGISTRY}/git-hook:latest
|
/kaniko/executor --context . --dockerfile docker/gitserver.Dockerfile \
|
||||||
/kaniko/executor --context . --dockerfile docker/migrate.Dockerfile --destination ${REGISTRY}/migrate:${TAG} --destination ${REGISTRY}/migrate:latest
|
--cache --cache-dir target \
|
||||||
/kaniko/executor --context . --dockerfile docker/operator.Dockerfile --destination ${REGISTRY}/operator:${TAG} --destination ${REGISTRY}/operator:latest
|
--destination ${REGISTRY}/gitserver:${TAG} --destination ${REGISTRY}/gitserver:latest
|
||||||
/kaniko/executor --context . --dockerfile docker/static.Dockerfile --destination ${REGISTRY}/static:${TAG} --destination ${REGISTRY}/static:latest
|
/kaniko/executor --context . --dockerfile docker/email-worker.Dockerfile \
|
||||||
/kaniko/executor --context . --dockerfile docker/frontend.Dockerfile --destination ${REGISTRY}/frontend:${TAG} --destination ${REGISTRY}/frontend:latest
|
--cache --cache-dir target \
|
||||||
|
--destination ${REGISTRY}/email-worker:${TAG} --destination ${REGISTRY}/email-worker:latest
|
||||||
|
/kaniko/executor --context . --dockerfile docker/git-hook.Dockerfile \
|
||||||
|
--cache --cache-dir target \
|
||||||
|
--destination ${REGISTRY}/git-hook:${TAG} --destination ${REGISTRY}/git-hook:latest
|
||||||
|
/kaniko/executor --context . --dockerfile docker/migrate.Dockerfile \
|
||||||
|
--cache --cache-dir target \
|
||||||
|
--destination ${REGISTRY}/migrate:${TAG} --destination ${REGISTRY}/migrate:latest
|
||||||
|
/kaniko/executor --context . --dockerfile docker/operator.Dockerfile \
|
||||||
|
--cache --cache-dir target \
|
||||||
|
--destination ${REGISTRY}/operator:${TAG} --destination ${REGISTRY}/operator:latest
|
||||||
|
/kaniko/executor --context . --dockerfile docker/static.Dockerfile \
|
||||||
|
--cache --cache-dir target \
|
||||||
|
--destination ${REGISTRY}/static:${TAG} --destination ${REGISTRY}/static:latest
|
||||||
|
/kaniko/executor --context . --dockerfile docker/frontend.Dockerfile \
|
||||||
|
--destination ${REGISTRY}/frontend:${TAG} --destination ${REGISTRY}/frontend:latest
|
||||||
echo "==> All images pushed"
|
echo "==> All images pushed"
|
||||||
depends_on: [ cargo-build, frontend-build ]
|
depends_on: [ cargo-build, frontend-build ]
|
||||||
|
|
||||||
|
|||||||
@ -2,8 +2,9 @@
|
|||||||
/**
|
/**
|
||||||
* Build Docker images for C-----code
|
* Build Docker images for C-----code
|
||||||
*
|
*
|
||||||
* Step 1: Build Rust binaries locally via cargo
|
* Workflow:
|
||||||
* Step 2: Build Docker images copying the pre-built binaries
|
* 1. cargo build --release --target x86_64-unknown-linux-gnu (compile Rust binaries)
|
||||||
|
* 2. docker build (copy pre-built binaries into minimal runtime images)
|
||||||
*
|
*
|
||||||
* Usage:
|
* Usage:
|
||||||
* node scripts/build.js # Build all images
|
* node scripts/build.js # Build all images
|
||||||
@ -22,21 +23,7 @@ const REGISTRY = process.env.REGISTRY || 'harbor.gitdata.me/gta_team';
|
|||||||
const TAG = process.env.TAG || 'latest';
|
const TAG = process.env.TAG || 'latest';
|
||||||
const BUILD_TARGET = process.env.TARGET || 'x86_64-unknown-linux-gnu';
|
const BUILD_TARGET = process.env.TARGET || 'x86_64-unknown-linux-gnu';
|
||||||
|
|
||||||
// Services that need Rust binary built externally
|
|
||||||
const RUST_SERVICES = ['app', 'gitserver', 'email-worker', 'git-hook', 'migrate', 'operator', 'static'];
|
const RUST_SERVICES = ['app', 'gitserver', 'email-worker', 'git-hook', 'migrate', 'operator', 'static'];
|
||||||
// Package name → binary name
|
|
||||||
const RUST_BINARIES = {
|
|
||||||
'app': 'app',
|
|
||||||
'gitserver': 'gitserver',
|
|
||||||
'email-worker': 'email-server',
|
|
||||||
'git-hook': 'git-hook',
|
|
||||||
'migrate': 'migrate',
|
|
||||||
'operator': 'operator',
|
|
||||||
'static': 'static-server',
|
|
||||||
};
|
|
||||||
|
|
||||||
// Services that build Docker images
|
|
||||||
// frontend uses Node.js in Docker (keeps its own build)
|
|
||||||
const ALL_SERVICES = [...RUST_SERVICES, 'frontend'];
|
const ALL_SERVICES = [...RUST_SERVICES, 'frontend'];
|
||||||
|
|
||||||
const args = process.argv.slice(2);
|
const args = process.argv.slice(2);
|
||||||
@ -44,7 +31,6 @@ const targets = args.length > 0 ? args : ALL_SERVICES;
|
|||||||
|
|
||||||
// Determine which rust services are in targets
|
// Determine which rust services are in targets
|
||||||
const rustTargets = targets.filter(s => RUST_SERVICES.includes(s));
|
const rustTargets = targets.filter(s => RUST_SERVICES.includes(s));
|
||||||
const dockerTargets = targets;
|
|
||||||
|
|
||||||
console.log(`\n=== Build Configuration ===`);
|
console.log(`\n=== Build Configuration ===`);
|
||||||
console.log(`Registry: ${REGISTRY}`);
|
console.log(`Registry: ${REGISTRY}`);
|
||||||
@ -52,19 +38,26 @@ console.log(`Tag: ${TAG}`);
|
|||||||
console.log(`Target: ${BUILD_TARGET}`);
|
console.log(`Target: ${BUILD_TARGET}`);
|
||||||
console.log(`Services: ${targets.join(', ')}\n`);
|
console.log(`Services: ${targets.join(', ')}\n`);
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
// Step 1: Build Rust binaries
|
// Step 1: Build Rust binaries
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
if (rustTargets.length > 0) {
|
if (rustTargets.length > 0) {
|
||||||
console.log(`\n=== Step 1: Building Rust binaries ===`);
|
console.log(`\n==> Step 1: Building Rust binaries`);
|
||||||
const binaries = rustTargets.map(s => `--package ${Object.keys(RUST_BINARIES).includes(s) ? Object.entries(RUST_BINARIES).find(([k]) => k === s)[1] : s}`).join(' ');
|
const cpus = require('os').cpus().length;
|
||||||
|
const packages = rustTargets.map(s => {
|
||||||
|
const pkgMap = {
|
||||||
|
'app': 'app',
|
||||||
|
'gitserver': 'gitserver',
|
||||||
|
'email-worker': 'email-server',
|
||||||
|
'git-hook': 'git-hook',
|
||||||
|
'migrate': 'migrate-cli',
|
||||||
|
'operator': 'operator',
|
||||||
|
'static': 'static-server',
|
||||||
|
};
|
||||||
|
return `--package ${pkgMap[s]}`;
|
||||||
|
}).join(' ');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
execSync(
|
execSync(
|
||||||
`cargo build --release ` +
|
`cargo build --release --target ${BUILD_TARGET} ${packages} -j ${cpus}`,
|
||||||
`--target ${BUILD_TARGET} ` +
|
|
||||||
rustTargets.map(s => `--package ${RUST_BINARIES[s]}`).join(' ') +
|
|
||||||
` -j ${require('os').cpus().length}`,
|
|
||||||
{ stdio: 'inherit', cwd: path.join(__dirname, '..') }
|
{ stdio: 'inherit', cwd: path.join(__dirname, '..') }
|
||||||
);
|
);
|
||||||
console.log(` [OK] Rust binaries built`);
|
console.log(` [OK] Rust binaries built`);
|
||||||
@ -74,12 +67,10 @@ if (rustTargets.length > 0) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
// Step 2: Build Docker images
|
// Step 2: Build Docker images
|
||||||
// ---------------------------------------------------------------------------
|
console.log(`\n==> Step 2: Building Docker images`);
|
||||||
console.log(`\n=== Step 2: Building Docker images ===`);
|
|
||||||
|
|
||||||
for (const service of dockerTargets) {
|
for (const service of targets) {
|
||||||
if (!ALL_SERVICES.includes(service)) {
|
if (!ALL_SERVICES.includes(service)) {
|
||||||
console.error(`Unknown service: ${service}`);
|
console.error(`Unknown service: ${service}`);
|
||||||
console.error(`Available: ${ALL_SERVICES.join(', ')}`);
|
console.error(`Available: ${ALL_SERVICES.join(', ')}`);
|
||||||
@ -89,15 +80,11 @@ for (const service of dockerTargets) {
|
|||||||
const dockerfile = path.join(__dirname, '..', 'docker', `${service}.Dockerfile`);
|
const dockerfile = path.join(__dirname, '..', 'docker', `${service}.Dockerfile`);
|
||||||
const image = `${REGISTRY}/${service}:${TAG}`;
|
const image = `${REGISTRY}/${service}:${TAG}`;
|
||||||
|
|
||||||
console.log(`\n==> Building ${image}`);
|
console.log(` Building ${image}`);
|
||||||
console.log(` Dockerfile: ${dockerfile}`);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
execSync(
|
execSync(
|
||||||
`docker build ` +
|
`docker build -f "${dockerfile}" -t "${image}" .`,
|
||||||
`-f "${dockerfile}" ` +
|
|
||||||
`-t "${image}" ` +
|
|
||||||
`.`,
|
|
||||||
{ stdio: 'inherit', cwd: path.join(__dirname, '..') }
|
{ stdio: 'inherit', cwd: path.join(__dirname, '..') }
|
||||||
);
|
);
|
||||||
console.log(` [OK] ${image}`);
|
console.log(` [OK] ${image}`);
|
||||||
@ -108,7 +95,7 @@ for (const service of dockerTargets) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
console.log(`\n=== Build Complete ===`);
|
console.log(`\n=== Build Complete ===`);
|
||||||
for (const service of dockerTargets) {
|
for (const service of targets) {
|
||||||
console.log(` ${REGISTRY}/${service}:${TAG}`);
|
console.log(` ${REGISTRY}/${service}:${TAG}`);
|
||||||
}
|
}
|
||||||
console.log('');
|
console.log('');
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user