Commit f319ba21 authored by nano's avatar nano

oss upload

parent 29f1a5a8
This diff is collapsed.
......@@ -2,6 +2,10 @@ FROM node
RUN apt-get update
RUN apt-get install aria2 -y
RUN apt-get curl
RUN curl --location --retry 5 --output ossutil 'https://github.com/mycard/ossutil/releases/download/1.0.0.Beta2/ossutil
RUN chmod +x ossutil && mv ossutil /usr/local/bin/ossutil
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
......
......@@ -80,6 +80,7 @@ export async function bundle(...args) {
await fs.renameAsync(filePath, fullPath);
return {
distPath: dist_path,
files: Array.from(files.values()),
archives: Array.from(archives.values()),
fullSize,
......
......@@ -7,18 +7,12 @@ import * as Client from 'aliyun-oss-upload-stream';
import * as fs from 'fs-extra-promise';
import * as path from 'path';
import * as Aria2 from 'aria2';
import Router = require('koa-router');
import {bundle} from '../../package/main';
import {mongodb} from '../models/Iridium';
import {toObjectID} from 'iridium';
import config from '../../config';
// const Aria2Options = {
// host: 'localhost',
// port: 6800,
// secure: false,
// secret: '',
// path: path.join(__dirname, '../../test/upload')
// }
import {UploadOSS} from '../utils'
const checkPackage = async (file) => {
if (['application/zip', 'application/gz', 'application/rar', 'application/7z', 'application/x-gzip'].indexOf(file.mime) === -1) {
......@@ -35,13 +29,13 @@ const checkImage = async (file) => {
};
import Router = require('koa-router');
const ossStream = Client(new OSS({
accessKeyId: process.env['OSS_ACCESS_ID'],
secretAccessKey: process.env['OSS_ACCESS_KEY'],
endpoint: process.env['OSS_ENDPOINT'],
apiVersion: '2013-10-15'
}));
const router = new Router();
const UploadImage = async (ctx: Context) => {
......@@ -105,13 +99,15 @@ export const UploadPackage = async (ctx: Context) => {
// 上传完, 打包
const bundled = await bundle(filename);
// 打包完,上传阿里云
await UploadOSS(bundled.distPath)
Object.assign(pack, bundled);
pack!.status = 'uploaded';
await mongodb.Packages.update({id: pack!.id}, {$set: {status: 'deprecated'}}, {multi: true});
await pack!.save();
// 打包完,上传阿里云
} catch (e) {
pack!.status = 'failed';
......@@ -166,6 +162,7 @@ const uploadPackageUrl = async (ctx: Context) => {
const bundled = await bundle(path.basename(file.path));
// 打包完, 上传阿里云
await UploadOSS(bundled.distPath)
Object.assign(pack, bundled);
pack!.status = 'uploaded';
......
import {URL} from 'url';
import * as child_process from 'child_process';
export const handleImg = (img) => {
if (img) {
......@@ -17,3 +18,19 @@ export const handleImg = (img) => {
export function renderChecksum(files: { path: string, hash?: string }[]) {
return files.map(({path, hash}) => `${hash || ''} ${path}`).join('\n');
}
export function UploadOSS(dist: string): Promise<void> {
return new Promise<void>((resolve, reject) => {
let child = child_process.spawn('ossutil', ['cp', dist, 'oss://mycard/test-release'], {stdio: 'inherit'});
child.on('exit', (code) => {
if (code == 0) {
resolve();
} else {
reject(code);
}
});
child.on('error', (error) => {
reject(error);
});
});
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment