
Research
/Security News
Weaponizing Discord for Command and Control Across npm, PyPI, and RubyGems.org
Socket researchers uncover how threat actors weaponize Discord across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.
@winner-fed/go-deploy
Advanced tools
基于 Go 的自动化部署工具 - 通过 SFTP 协议将本地文件上传到远程服务器
npm install @winner-fed/go-deploy
npm install -g @winner-fed/go-deploy
yarn add @winner-fed/go-deploy
创建 config.json
文件:
{
"server": {
"host": "your-server-ip",
"port": 22,
"username": "your-username",
"password": "your-password",
"timeout": 10
},
"paths": {
"local": "./dist",
"remote": "/opt/your-app/dist"
},
"options": {
"backup": true,
"backup_suffix": ".backup",
"exclude_patterns": [
"*.log",
"*.map",
".DS_Store",
"node_modules"
],
"max_retries": 3,
"chunk_size": 1048576
}
}
# 使用默认配置文件 config.json
go-deploy
# 使用指定配置文件
go-deploy --config prod.json
# 显示帮助信息
go-deploy --help
# 显示版本信息
go-deploy --version
const { deploy } = require('@winner-fed/go-deploy');
async function deployApp() {
try {
await deploy({
config: './config.json'
});
console.log('部署成功!');
} catch (error) {
console.error('部署失败:', error.message);
}
}
deployApp();
const {
deploy,
getVersion,
checkBinary,
getBinaryPath
} = require('@winner-fed/go-deploy');
执行部署操作。
参数:
options
(Object): 部署选项
config
(string): 配置文件路径cwd
(string): 工作目录,默认为 process.cwd()
silent
(boolean): 静默模式,默认为 false
help
(boolean): 显示帮助信息version
(boolean): 显示版本信息返回值: Promise<Object>
code
(number): 退出代码stdout
(string): 标准输出stderr
(string): 标准错误示例:
// 基本使用
await deploy({ config: './config.json' });
// 静默模式
const result = await deploy({
config: './config.json',
silent: true
});
console.log(result.stdout);
// 指定工作目录
await deploy({
config: './config.json',
cwd: '/path/to/project'
});
获取 go-deploy 版本信息。
返回值: Promise<string>
- 版本信息
示例:
const version = await getVersion();
console.log('版本:', version);
检查二进制文件是否可用。
返回值: boolean - 是否可用
示例:
const isAvailable = checkBinary();
if (!isAvailable) {
console.error('go-deploy 二进制文件不可用');
}
获取当前平台对应的二进制文件路径。
返回值: string - 二进制文件路径
示例:
try {
const binaryPath = getBinaryPath();
console.log('二进制文件路径:', binaryPath);
} catch (error) {
console.error('获取二进制文件路径失败:', error.message);
}
字段 | 类型 | 必填 | 默认值 | 说明 |
---|---|---|---|---|
host | string | ✅ | - | SSH 服务器地址 |
port | number | ❌ | 22 | SSH 端口 |
username | string | ✅ | - | SSH 用户名 |
password | string | ✅ | - | SSH 密码(建议使用密钥认证) |
timeout | number | ❌ | 10 | 连接超时时间(秒) |
字段 | 类型 | 必填 | 默认值 | 说明 |
---|---|---|---|---|
local | string | ✅ | - | 本地目录路径(支持相对和绝对路径) |
remote | string | ✅ | - | 远程目录路径(必须是绝对路径) |
字段 | 类型 | 必填 | 默认值 | 说明 |
---|---|---|---|---|
backup | boolean | ❌ | false | 是否在上传前备份远程现有文件 |
backup_suffix | string | ❌ | .backup | 备份文件的后缀名 |
exclude_patterns | string[] | ❌ | [] | 文件排除模式(支持通配符) |
max_retries | number | ❌ | 3 | 上传失败时的最大重试次数 |
chunk_size | number | ❌ | 1048576 | 文件传输块大小(字节) |
{
"server": {
"host": "192.168.1.100",
"port": 22,
"username": "deployer",
"password": "your-secure-password",
"timeout": 30
},
"paths": {
"local": "./build",
"remote": "/var/www/html"
},
"options": {
"backup": true,
"backup_suffix": ".bak",
"exclude_patterns": [
"*.log",
"*.map",
".DS_Store",
"node_modules",
"*.tmp"
],
"max_retries": 5,
"chunk_size": 2097152
}
}
{
"scripts": {
"build": "webpack --mode production",
"deploy": "npm run build && go-deploy",
"deploy:prod": "npm run build && go-deploy --config prod.json",
"deploy:test": "npm run build && go-deploy --config test.json",
"deploy:staging": "npm run build && go-deploy --config staging.json"
}
}
创建不同环境的配置文件:
config/
├── prod.json # 生产环境
├── test.json # 测试环境
└── staging.json # 预发布环境
name: Deploy
on:
push:
branches: [ main ]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
- name: Install dependencies
run: npm ci
- name: Build
run: npm run build
- name: Deploy
run: npx @winner-fed/go-deploy --config config/prod.json
可以通过环境变量动态替换配置:
const { deploy } = require('@winner-fed/go-deploy');
const fs = require('fs');
// 读取配置模板
const configTemplate = JSON.parse(fs.readFileSync('config.template.json', 'utf8'));
// 使用环境变量替换
const config = {
...configTemplate,
server: {
...configTemplate.server,
host: process.env.DEPLOY_HOST || configTemplate.server.host,
username: process.env.DEPLOY_USER || configTemplate.server.username,
password: process.env.DEPLOY_PASSWORD || configTemplate.server.password
}
};
// 写入临时配置文件
fs.writeFileSync('config.temp.json', JSON.stringify(config, null, 2));
// 执行部署
await deploy({ config: 'config.temp.json' });
// 清理临时文件
fs.unlinkSync('config.temp.json');
操作系统 | 架构 | 状态 | 二进制包 |
---|---|---|---|
macOS | x64 | ✅ | @winner-fed/go-deploy-darwin-x64 |
macOS | ARM64 | ✅ | @winner-fed/go-deploy-darwin-arm64 |
Linux | x64 | ✅ | @winner-fed/go-deploy-linux-x64 |
Linux | ARM64 | ✅ | @winner-fed/go-deploy-linux-arm64 |
Windows | x64 | ✅ | @winner-fed/go-deploy-win32-x64 |
const { deploy } = require('@winner-fed/go-deploy');
try {
await deploy({ config: './config.json' });
} catch (error) {
if (error.message.includes('找不到')) {
console.error('❌ 二进制文件不可用,请检查安装');
console.error('尝试重新安装: npm install @winner-fed/go-deploy');
} else if (error.message.includes('配置文件')) {
console.error('❌ 配置文件错误,请检查配置');
console.error('配置文件路径:', path.resolve('./config.json'));
} else if (error.message.includes('连接')) {
console.error('❌ 服务器连接失败,请检查网络和服务器配置');
} else if (error.message.includes('权限')) {
console.error('❌ 权限不足,请检查用户权限和目录权限');
} else {
console.error('❌ 部署失败:', error.message);
}
}
const { deploy } = require('@winner-fed/go-deploy');
// 启用详细输出
await deploy({
config: './config.json',
silent: false // 显示详细的部署过程
});
# 克隆项目
git clone https://github.com/cklwblove/go-deploy.git
cd go-deploy
# 安装依赖
npm install
# 构建二进制文件
npm run build
# 运行测试
npm test
# 构建所有平台
npm run build
# 查看构建结果
ls bin/
# 在项目目录中
npm link
# 在其他项目中测试
npm link @winner-fed/go-deploy
欢迎贡献代码!请遵循以下步骤:
git checkout -b feature/AmazingFeature
)git commit -m 'Add some AmazingFeature'
)git push origin feature/AmazingFeature
)A: 工具会自动分块传输,通过 chunk_size
配置项可以调整块大小,默认 1MB。
A: 当前版本不支持断点续传,如果传输中断需要重新开始。
A: 当前版本主要支持密码认证,SSH 密钥认证功能在开发计划中。
A: 当前版本不支持,需要分别配置和执行多次部署。
本项目基于 MIT 许可证 开源。
如果这个项目对你有帮助,请给它一个 ⭐️ Star!
Made with ❤️ by cklwblove
FAQs
基于 Go 的自动化部署工具 - 通过 SFTP 协议将本地文件上传到远程服务器
The npm package @winner-fed/go-deploy receives a total of 23 weekly downloads. As such, @winner-fed/go-deploy popularity was classified as not popular.
We found that @winner-fed/go-deploy demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
/Security News
Socket researchers uncover how threat actors weaponize Discord across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.
Security News
Socket now integrates with Bun 1.3’s Security Scanner API to block risky packages at install time and enforce your organization’s policies in local dev and CI.
Research
The Socket Threat Research Team is tracking weekly intrusions into the npm registry that follow a repeatable adversarial playbook used by North Korean state-sponsored actors.