build squashfs in packer; set hostname using mac address
This commit is contained in:
parent
657336cf7c
commit
2bc4d064b3
6 changed files with 58 additions and 38 deletions
1
Makefile
1
Makefile
|
|
@ -55,6 +55,7 @@ images/debian-stretch.squashfs: images
|
||||||
-v "${PWD}/images:/images" \
|
-v "${PWD}/images:/images" \
|
||||||
-e "user=`id -u`" \
|
-e "user=`id -u`" \
|
||||||
-e "group=`id -g`" \
|
-e "group=`id -g`" \
|
||||||
|
-e "IMAGES=${PWD}/images" \
|
||||||
-e "ANNOUNCE=$(ANNOUNCE)" \
|
-e "ANNOUNCE=$(ANNOUNCE)" \
|
||||||
-e "WEBSEED=$(WEBSEED)" \
|
-e "WEBSEED=$(WEBSEED)" \
|
||||||
-e "COMPRESSION_LEVEL=$(COMPRESSION_LEVEL)" \
|
-e "COMPRESSION_LEVEL=$(COMPRESSION_LEVEL)" \
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
FROM docker:dind
|
FROM docker
|
||||||
|
|
||||||
RUN apk add --no-cache \
|
RUN apk add --no-cache \
|
||||||
ca-certificates \
|
ca-certificates \
|
||||||
|
|
|
||||||
|
|
@ -37,36 +37,10 @@ make_torrent() {
|
||||||
}
|
}
|
||||||
|
|
||||||
run_packer() {
|
run_packer() {
|
||||||
packer build "$PACKER_JSON"
|
packer build "$NAME.json"
|
||||||
|
|
||||||
mkdir -p build/rootfs
|
|
||||||
tar xf build/rootfs.tar -C build/rootfs
|
|
||||||
|
|
||||||
mv build/rootfs/artifacts/initramfs "/images/$INITRAMFS_FILE"
|
|
||||||
mv build/rootfs/artifacts/linux "/images/$LINUX_FILE"
|
|
||||||
|
|
||||||
rm -rf build/rootfs/artifacts
|
|
||||||
|
|
||||||
rm -- \
|
|
||||||
build/rootfs/.dockerenv \
|
|
||||||
build/rootfs/initrd.* \
|
|
||||||
build/rootfs/vmlinuz*
|
|
||||||
|
|
||||||
if [ -e "/images/$SQUASHFS_FILE" ]; then
|
|
||||||
rm "/images/$SQUASHFS_FILE"
|
|
||||||
fi
|
|
||||||
|
|
||||||
mksquashfs build/rootfs "/images/$SQUASHFS_FILE" \
|
|
||||||
-comp lzo \
|
|
||||||
-Xcompression-level $COMPRESSION_LEVEL
|
|
||||||
|
|
||||||
rm -rf build
|
|
||||||
|
|
||||||
if [ "$user" != "" ] && [ "$group" != "" ]; then
|
if [ "$user" != "" ] && [ "$group" != "" ]; then
|
||||||
chown $user:$group \
|
chown $user:$group "/images/${NAME}."*
|
||||||
"/images/$INITRAMFS_FILE" \
|
|
||||||
"/images/$LINUX_FILE" \
|
|
||||||
"/images/$SQUASHFS_FILE"
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -77,10 +51,7 @@ if [ "$NAME" = "" ]; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
export PACKER_JSON="$NAME.json"
|
export NAME
|
||||||
export INITRAMFS_FILE="$NAME.initramfs"
|
|
||||||
export LINUX_FILE="$NAME.linux"
|
|
||||||
export SQUASHFS_FILE="$NAME.squashfs"
|
|
||||||
|
|
||||||
if [ -z "$TASK" ] || [ "$TASK" == "packer" ]; then
|
if [ -z "$TASK" ] || [ "$TASK" == "packer" ]; then
|
||||||
run_packer
|
run_packer
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,11 @@
|
||||||
{
|
{
|
||||||
"variables": {
|
"variables": {
|
||||||
|
"name": "{{env `NAME`}}",
|
||||||
|
"squashfs_file": "{{env `NAME`}}.squashfs",
|
||||||
|
"initramfs_file": "{{env `NAME`}}.initramfs",
|
||||||
|
"linux_file": "{{env `NAME`}}.linux",
|
||||||
|
"compression_level": "{{env `COMPRESSION_LEVEL`}}",
|
||||||
|
"images": "{{env `IMAGES`}}",
|
||||||
"ci_job_id": "{{env `CI_JOB_ID`}}",
|
"ci_job_id": "{{env `CI_JOB_ID`}}",
|
||||||
"ci_commit_sha": "{{env `CI_COMMIT_SHA`}}",
|
"ci_commit_sha": "{{env `CI_COMMIT_SHA`}}",
|
||||||
"ci_commit_tag": "{{env `CI_COMMIT_TAG`}}",
|
"ci_commit_tag": "{{env `CI_COMMIT_TAG`}}",
|
||||||
|
|
@ -16,7 +22,15 @@
|
||||||
{
|
{
|
||||||
"type": "docker",
|
"type": "docker",
|
||||||
"image": "debian:stretch",
|
"image": "debian:stretch",
|
||||||
"export_path": "build/rootfs.tar"
|
"discard": true,
|
||||||
|
"run_command": [
|
||||||
|
"-d",
|
||||||
|
"-i",
|
||||||
|
"-t",
|
||||||
|
"-v", "{{user `images`}}:/tmp/images",
|
||||||
|
"{{.Image}}",
|
||||||
|
"/bin/bash"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"provisioners": [
|
"provisioners": [
|
||||||
|
|
@ -58,10 +72,9 @@
|
||||||
"echo overlay >> /etc/initramfs-tools/modules",
|
"echo overlay >> /etc/initramfs-tools/modules",
|
||||||
"echo 'RESUME=none' > /etc/initramfs-tools/conf.d/resume",
|
"echo 'RESUME=none' > /etc/initramfs-tools/conf.d/resume",
|
||||||
"mkdir /usr/local/boot",
|
"mkdir /usr/local/boot",
|
||||||
"apt-get -f -y install aria2 ca-certificates linux-image-amd64 lvm2",
|
"apt-get -f -y install aria2 linux-image-amd64 lvm2",
|
||||||
"mkdir /artifacts",
|
"cp $(find /boot/ -name 'initrd.img-*' | sort -V | tail -n 1) '/tmp/images/{{user `initramfs_file`}}'",
|
||||||
"cp $(find /boot/ -name 'initrd.img-*' | sort -V | tail -n 1) /artifacts/initramfs",
|
"cp $(find /boot/ -name 'vmlinuz-*' | sort -V | tail -n 1) '/tmp/images/{{user `linux_file`}}'"
|
||||||
"cp $(find /boot/ -name 'vmlinuz-*' | sort -V | tail -n 1) /artifacts/linux"
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
@ -76,6 +89,31 @@
|
||||||
{
|
{
|
||||||
"type": "shell",
|
"type": "shell",
|
||||||
"inline": [ "rm /boot && mkdir /boot" ]
|
"inline": [ "rm /boot && mkdir /boot" ]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "shell",
|
||||||
|
"inline": [
|
||||||
|
"set -x",
|
||||||
|
"apt-get -y install squashfs-tools",
|
||||||
|
"dpkg -L squashfs-tools liblzo2-2 | while read f; do [ -f \"$f\" ] && echo \"$f\"; done > /tmp/ignore_files",
|
||||||
|
"echo '/etc/resolv.conf' >> /tmp/ignore_files",
|
||||||
|
"echo '/etc/hostname' >> /tmp/ignore_files",
|
||||||
|
"echo '/etc/hosts' >> /tmp/ignore_files",
|
||||||
|
"mkdir -p /tmp/extra/tmp /tmp/extra/proc /tmp/extra/sys /tmp/extra/etc"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "file",
|
||||||
|
"source": "hosts",
|
||||||
|
"destination": "/tmp/extra/etc/hosts"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "shell",
|
||||||
|
"inline": [
|
||||||
|
"if [ -e '/tmp/images/{{user `squashfs_file`}}' ]; then rm '/tmp/images/{{user `squashfs_file`}}'; fi",
|
||||||
|
"squashfs_content=\"$(find / -mindepth 1 -maxdepth 1 | grep -vE '^/(proc|sys|tmp|[.]dockerenv|packer-files)$')\"",
|
||||||
|
"mksquashfs $squashfs_content /tmp/extra/* '/tmp/images/{{user `squashfs_file`}}' -comp lzo -Xcompression-level {{user `compression_level`}} -ef /tmp/ignore_files"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
6
packer/hosts
Normal file
6
packer/hosts
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
127.0.0.1 localhost
|
||||||
|
127.0.1.1 @@HOSTNAME@@
|
||||||
|
|
||||||
|
::1 localhost ip6-localhost ip6-loopback
|
||||||
|
ff02::1 ip6-allnodes
|
||||||
|
ff02::2 ip6-allrouters
|
||||||
|
|
@ -184,6 +184,10 @@ PARTTABLE
|
||||||
mount -n -o move /overlay ${rootmnt}/overlay
|
mount -n -o move /overlay ${rootmnt}/overlay
|
||||||
mount -n -o move /rom ${rootmnt}/rom
|
mount -n -o move /rom ${rootmnt}/rom
|
||||||
|
|
||||||
|
hostname=$(ip -o link show | sed -ne 's#^.*link/ether \([0-9a-f:]*\).*$#\1#p' | sed -ne '1{s/://g;p}')
|
||||||
|
echo $hostname > ${rootmnt}/etc/hostname
|
||||||
|
sed -i "s/@@HOSTNAME@@/$hostname/" ${rootmnt}/etc/hosts
|
||||||
|
|
||||||
if [ -z "$labsync_localboot" ]; then
|
if [ -z "$labsync_localboot" ]; then
|
||||||
labsync_set_environment LABSYNC "$torrent_name"
|
labsync_set_environment LABSYNC "$torrent_name"
|
||||||
labsync_set_environment LABSYNC_TORRENT "${labsync_torrent}"
|
labsync_set_environment LABSYNC_TORRENT "${labsync_torrent}"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue