Browse Source

feat: Add build tool

master
Maciej Krüger 6 years ago
parent
commit
f4bb39e13c
No known key found for this signature in database GPG Key ID: D948CE19CF49C5F
  1. 3
      .gitignore
  2. 6
      Makefile
  3. 3
      boards/opi0.yaml
  4. 86
      build-tool.js
  5. 2
      definition.yaml
  6. 9
      deps/opi0.yaml
  7. 28
      package.json

3
.gitignore

@ -1,3 +1,6 @@
*.img
*.model
*.manifest
node_modules
package-lock.json
snaps

6
Makefile

@ -1,11 +1,14 @@
CHANNEL=stable
ENV=dev
clean:
rm -rf *.img *.model *.manifest
%.model: boards/%.yaml # sign a model file
cat definition.yaml $< | python -c "import sys, yaml, json; json.dump(yaml.load(sys.stdin), sys.stdout, indent=2)" | sed "s|TIMESTAMP|$(shell date -Iseconds --utc)|g" | snap sign -k default > $@
%.img: %.model # build an image
snaps/%:
node build-tool.js --env $(ENV) --channel $(CHANNEL) --board $*
%.img: %.model snaps/% # build an image
sudo ubuntu-image snap -o $@ -c $(CHANNEL) $<
# VM stuff
@ -16,4 +19,3 @@ start: vm.img # launch the image with kvm
kvm -smp 2 -m 1500 -netdev user,id=mynet0,hostfwd=tcp::8022-:22,hostfwd=tcp::8090-:80 -device virtio-net-pci,netdev=mynet0 -drive file=vm.img,format=raw
ssh: # ssh into it (don't check the key because that one changes after every rebuild)
ssh mkg20001@localhost -p 8022 -o StrictHostKeyChecking=no -o GlobalKnownHostsFile=/dev/null -o UserKnownHostsFile=/dev/null

3
boards/opi0.yaml

@ -0,0 +1,3 @@
architecture: armhf
gadget: orangepi-zero-gadget
kernel: orangepi-zero-kernel

86
build-tool.js

@ -0,0 +1,86 @@
#!/usr/bin/env node
/* eslint-disable no-console */
'use strict'
const {board, env} = require('yargs').argv
require('colors')
const fs = require('fs')
const path = require('path')
const read = (...file) => String(fs.readFileSync(path.join(__dirname, ...file)))
const yaml = require('js-yaml')
const cp = require('child_process')
const JSON5 = require('json5')
const mkdir = require('mkdirp').sync
const isDev = env === 'dev'
const forceBuild = isDev
const deps = yaml.safeLoad(read('deps/' + board + '.yaml'))
const boardDef = yaml.safeLoad(read('boards/' + board + '.yaml'))
const exec = (cmd, dir, ...args) => new Promise((resolve, reject) => {
console.log('$ %s'.bold, [cmd, ...args].map(JSON5.stringify).join(' '))
const p = cp.spawn(cmd, args, {stdio: 'inherit', cwd: dir})
p.once('close', (code, sig) => {
if (code || sig) {
return reject(new Error('Failed with code/sig: ' + (code || sig)))
}
resolve()
})
})
const execWithOutput = (cmd, ...args) => {
const p = cp.spawnSync(cmd, args)
if (p.status || p.signal) {
throw new Error('Failed with code/sig: ' + (p.status || p.signal))
}
return p
}
async function snapcraft (folder, outFile, targetArch) {
await exec('snapcraft', folder, 'snap', '-o', outFile, '--target-arch=' + targetArch)
}
async function pullOrClone (repo, dest, checkout) {
let currentCommit = ''
if (fs.existsSync(dest)) {
await exec('git', dest, 'remote', 'update', '--recurse-submodules=yes', '-p')
} else {
await exec('git', process.cwd(), 'clone', '--recursive', repo, dest)
currentCommit = String(execWithOutput('git', '-C', dest, 'rev-parse', '--verify', 'HEAD').stdout)
}
await exec('git', dest, 'checkout', checkout)
let newCommit = String(execWithOutput('git', '-C', dest, 'rev-parse', '--verify', 'HEAD').stdout)
return currentCommit !== newCommit // returns bool if snap need recompilation
}
async function main () {
for (const snapName in deps.snaps) { // eslint-disable-line guard-for-in
const snap = deps.snaps[snapName]
if (snap.mustBuild || forceBuild) {
console.log('Building %s...', snapName)
let buildFolder = path.join('snaps', board, snapName)
mkdir(buildFolder)
let sourceFolder = path.join(buildFolder, 'source')
let snapFile = path.join(buildFolder, snapName + '.snap')
if (await pullOrClone(snap.git, path.join(buildFolder, 'source'), snap.version)) {
if (fs.existsSync(snapFile)) {
fs.unlinkSync(snapFile)
}
}
if (!fs.existsSync(snapFile)) {
await snapcraft(sourceFolder, snapFile, boardDef.architecture)
}
}
}
}
main()

2
definition.yaml

@ -1,7 +1,7 @@
# basic
type: model
series: "16"
model: hub
model: ppl-hub
# snaps to be preinstalled:
required-snaps:
- nextcloud # just for proof-of-concept

9
deps/opi0.yaml

@ -0,0 +1,9 @@
snaps:
orangepi-zero-gadget:
git: https://github.com/fuzeman/orangepi-zero-gadget
version: 1.0.0-beta.3
mustBuild: true # snap is only available in orange pi store
orangepi-zero-kernel:
git: https://github.com/fuzeman/orangepi-zero-kernel
version: 4.10.0-2001.2-beta.2
mustBuild: true # snap is only available in orange pi store

28
package.json

@ -0,0 +1,28 @@
{
"name": "ppl-os",
"version": "0.0.1",
"description": "Files required to build the ubuntu core based pplOS",
"main": "build-tool.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "ssh://gitea@git.coolaj86.com:22042/mkg20001/ppl-os.git"
},
"keywords": [
"pplOS",
"pplfamily",
"ubuntu-core",
"build-tool"
],
"author": "Maciej Krüger <mkg20001@gmail.com>",
"license": "MIT",
"dependencies": {
"colors": "^1.3.1",
"js-yaml": "^3.12.0",
"json5": "^1.0.1",
"mkdirp": "^0.5.1",
"yargs": "^12.0.1"
}
}
Loading…
Cancel
Save