create dockerfiles from lua script

This commit is contained in:
Natanael Copa committed 2019-03-04 18:23:10 +01:00
1 parent 2ef049f41f
commit 69f5a7f8dd
2 files changed
+12 -33

No files matched your search

+11 -18
View File
@@ -10,7 +10,6 @@ local lfs = require("lfs")
local mirror = "https://cz.alpinelinux.org/alpine"
function fetch(url)
local headers, stream = assert(request.new_from_uri(url):go())
local body= assert(stream:get_body_as_string())
@@ -37,6 +36,11 @@ function fetch_file(url, outfile)
return os.rename(partfile, outfile)
end
function mkdockerfile(dir, rootfsfile)
local f = assert(io.open(string.format("%s/Dockerfile", dir), "w"))
f:write(string.format("FROM scratch\nADD %s /\nCMD [\"/bin/sh\"]\n", rootfsfile))
f:close()
end
function get_minirootfs(images, destdir)
for _,img in pairs(images) do
@@ -46,10 +50,8 @@ function get_minirootfs(images, destdir)
mirror, img.branch, img.arch, img.file)
local archdir = string.format("%s/%s", destdir, img.arch)
local ok, errmsg = lfs.mkdir(archdir)
if not ok then
return errormsg(errmsg)
end
fetch_file(url, string.format("%s/%s", archdir, img.file))
mkdockerfile(archdir, img.file)
print(img.file)
end
return { version=img.version, file=img.file, sha512=img.sha512 }
@@ -57,7 +59,6 @@ function get_minirootfs(images, destdir)
end
end
-- get array of minirootsfs releases --
function get_releases(branch, destdir)
local arches = { "aarch64", "armhf", "armv7", "ppc64le" , "s390x", "x86", "x86_64" }
@@ -69,7 +70,7 @@ function get_releases(branch, destdir)
mirror, branch, arch)
local status, body = fetch(url)
if status == "200" then
t[arch] = get_minirootfs(yaml.load(body), destdir)
t[arch] = get_minirootfs((yaml.load(body)), destdir)
end
end)
end
@@ -78,23 +79,15 @@ function get_releases(branch, destdir)
end
local branch = arg[1] or "edge"
local destdir = arg[2]
local destdir = arg[2] or "out"
local f
lfs.mkdir(destdir)
if destdir then
lfs.mkdir(destdir)
f = io.open(string.format("%s/checksums.sha512", destdir), "w")
else
f = io.stdout
end
local f = io.open(string.format("%s/checksums.sha512", destdir), "w")
for arch,rel in pairs(get_releases(branch, destdir)) do
local line = string.format("%s %s/%s\n", rel.sha512, arch, rel.file)
f:write(line)
end
if f ~= io.stdout then
f:close()
end
f:close()
+1 -15
View File
@@ -5,21 +5,7 @@ branch=${1:-edge}
dir=$(mktemp -d /tmp/docker-brew-alpine-XXXXXX)
docker build -t docker-brew-alpine-fetch .
docker run --user $(id -u) --rm -it -v $dir:/out docker-brew-alpine-fetch $branch /out
(
cd $dir
sha512sum -c checksums.sha512
for img in */*.tar.gz; do
arch=${img%%/*}
rootfs=${img##*/}
cat > $arch/Dockerfile <<-EOF
FROM scratch
ADD ${rootfs} /
CMD ["/bin/sh"]
EOF
done
)
( cd $dir && sha512sum -c checksums.sha512)
echo "COMPLETED"
echo "=> Temp dir: $dir"