Skip to content

Commit d64d65e

Browse files
committed
[bioconda][backup] add new scripts
1 parent 2787fd0 commit d64d65e

File tree

10 files changed

+5309
-0
lines changed

10 files changed

+5309
-0
lines changed

bioconda-backup/README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# containers backup
2+
3+
Check for biocontainers and bioconda container updates to copy them
4+
to local backup registry and optionally to aws.
5+
Also add security scan
6+
7+
Support full scan update or update from last repo check
8+
9+
## setup
10+
11+
* nodejs
12+
* aws cli and aws credentials set in ~/.aws
13+
14+
ls ~/.aws
15+
config credentials
16+
17+
# config
18+
[default]
19+
region = us-east-1
20+
# credentials
21+
[default]
22+
aws_access_key_id =
23+
aws_secret_access_key =
24+
25+
## run
26+
27+
node index.js --help

bioconda-backup/config.yml.example

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
default:
2+
mail:
3+
to: '' # destination email
4+
smtp: '' # smtp ip
5+
s3:
6+
endpoint: ''
7+
access_key: ''
8+
secret_access_key: ''
9+
bucket: 'biocontainers2'
10+
11+
registry:
12+
host: 'biocontainers.novalocal:5000'
13+
14+
anchore:
15+
url: 'http://localhost:8228/v1'
16+
user: 'admin'
17+
password: ''
18+
19+
aws: null # aws registry id
20+
21+
workdir: '/tmp'

bioconda-backup/git.js

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
const Git = require("nodegit");
4+
5+
const workdir = '/tmp';
6+
const biocontainers = 'https://github.com/BioContainers/containers.git';
7+
const bioconda = 'https://github.com/bioconda/bioconda-recipes.git';
8+
9+
const getRepoFiles = function(dirPath, arrayOfFiles) {
10+
let files = fs.readdirSync(dirPath)
11+
arrayOfFiles = arrayOfFiles || []
12+
13+
files.forEach(function(file) {
14+
if (fs.statSync(dirPath + "/" + file).isDirectory()) {
15+
arrayOfFiles = getRepoFiles(dirPath + "/" + file, arrayOfFiles)
16+
} else {
17+
let dirElt = dirPath.split('/');
18+
if(file == 'Dockerfile' || (file == 'meta.yaml' && dirElt[dirElt.length-2] == 'recipes')) {
19+
arrayOfFiles.push(path.join(dirPath, "/", file))
20+
}
21+
}
22+
})
23+
24+
return arrayOfFiles
25+
}
26+
27+
async function repoFiles(kind='biocontainers') {
28+
let destDir = `${workdir}/${kind}`;
29+
let lastCommit = null;
30+
if (fs.existsSync(destDir)) {
31+
let existingRepo = await Git.Repository.open(destDir);
32+
let bc = await existingRepo.getBranchCommit('master');
33+
lastCommit = bc.sha();
34+
console.log('existing, last commit', lastCommit);
35+
fs.rmSync(destDir, {recursive: true});
36+
}
37+
let repoUrl = kind == 'biocontainers' ? biocontainers : bioconda;
38+
await Git.Clone(repoUrl, destDir);
39+
let repo = await Git.Repository.open(destDir);
40+
let headc = await repo.getBranchCommit('master');
41+
let headCommit = headc.sha();
42+
console.log('last commit', lastCommit);
43+
console.log('head commit', headCommit);
44+
45+
let files = [];
46+
if(lastCommit && lastCommit == headCommit) {
47+
console.log('nothing to do');
48+
return [];
49+
}
50+
if(lastCommit) {
51+
console.log('get diff');
52+
let cold = await repo.getCommit(lastCommit);
53+
let coldTree = await cold.getTree();
54+
let cnew = await repo.getCommit(headCommit);
55+
let cnewTree = await cnew.getTree();
56+
const diff = await cnewTree.diff(coldTree);
57+
const patches = await diff.patches();
58+
59+
for (const patch of patches) {
60+
files.push(patch.newFile().path());
61+
}
62+
return files;
63+
64+
}
65+
console.log('take all');
66+
let allFiles = getRepoFiles(destDir);
67+
for(let i=0;i<allFiles.length;i++) {
68+
allFiles[i] = allFiles[i].replace(destDir + '/', '');
69+
}
70+
return allFiles;
71+
}
72+
73+
repoFiles('biocontainers').then(files => {
74+
console.log('files', files.length, files[0]);
75+
process.exit(0);
76+
}).catch(err => {
77+
console.error(err);
78+
process.exit(1);
79+
})

0 commit comments

Comments
 (0)