diff --git a/.drone-manifest-fickit-deploy.yml b/.drone-manifest-fickit-deploy.yml new file mode 100644 index 00000000..bfa37052 --- /dev/null +++ b/.drone-manifest-fickit-deploy.yml @@ -0,0 +1,22 @@ +image: nemunaire/fickit-deploy:{{#if build.tag}}{{trimPrefix "v" build.tag}}{{else}}latest{{/if}} +{{#if build.tags}} +tags: +{{#each build.tags}} + - {{this}} +{{/each}} +{{/if}} +manifests: + - image: nemunaire/fickit-deploy:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-amd64 + platform: + architecture: amd64 + os: linux + - image: nemunaire/fickit-deploy:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-arm64 + platform: + architecture: arm64 + os: linux + variant: v8 + - image: nemunaire/fickit-deploy:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-arm + platform: + architecture: arm + os: linux + variant: v7 diff --git a/.drone.yml b/.drone.yml index c48944af..2b245598 100644 --- a/.drone.yml +++ b/.drone.yml @@ -326,6 +326,21 @@ steps: branch: - master + - name: docker fickit-deploy + image: plugins/docker + settings: + username: + from_secret: docker_username + password: + from_secret: docker_password + repo: nemunaire/fickit-deploy + auto_tag: true + auto_tag_suffix: ${DRONE_STAGE_OS}-${DRONE_STAGE_ARCH} + dockerfile: Dockerfile-deploy + when: + branch: + - master + trigger: event: - cron @@ -726,6 +741,17 @@ steps: password: from_secret: docker_password + - name: publish fickit-deploy + image: plugins/manifest + settings: + auto_tag: true + ignore_missing: true + spec: .drone-manifest-fickit-deploy.yml + username: + from_secret: docker_username + password: + from_secret: docker_password + trigger: event: - push diff --git a/Dockerfile-deploy b/Dockerfile-deploy new file mode 100644 index 00000000..e775e9cb --- /dev/null +++ b/Dockerfile-deploy @@ -0,0 +1,21 @@ +FROM alpine:3.18 + +EXPOSE 67/udp +EXPOSE 69/udp +EXPOSE 80/tcp + +CMD ["/usr/bin/supervisord", "-c", "/etc/supervisord.conf"] + +WORKDIR /srv + +RUN apk add --no-cache \ + busybox-extras \ + supervisor \ + syslinux \ + tftp-hpa + +RUN touch /var/lib/udhcpd/udhcpd.leases + +COPY configs/deploy-supervisord.conf /etc/supervisord.conf +COPY configs/udhcpd-sample.conf /etc/udhcpd.conf +COPY configs/pxelinux.cfg /usr/share/syslinux/pxelinux.cfg/default \ No newline at end of file diff --git a/configs/deploy-supervisord.conf b/configs/deploy-supervisord.conf new file mode 100644 index 00000000..41f2070e --- /dev/null +++ b/configs/deploy-supervisord.conf @@ -0,0 +1,24 @@ +[supervisord] +nodaemon = true +silent = true + +[program:httpd] +command = /usr/sbin/httpd -f -vv -h /srv +stdout_logfile = /dev/stdout +stdout_logfile_maxbytes = 0 +stderr_logfile = /dev/stderr +stderr_logfile_maxbytes = 0 + +[program:tftpd] +command = /usr/sbin/in.tftpd -R 4096:32767 -v -s /usr/share/syslinux/ +stdout_logfile = /dev/stdout +stdout_logfile_maxbytes = 0 +stderr_logfile = /dev/stderr +stderr_logfile_maxbytes = 0 + +[program:udhcpd] +command = /usr/sbin/udhcpd -f +stdout_logfile = /dev/stdout +stdout_logfile_maxbytes = 0 +stderr_logfile = /dev/stderr +stderr_logfile_maxbytes = 0 \ No newline at end of file diff --git a/configs/pxelinux.cfg b/configs/pxelinux.cfg new file mode 100644 index 00000000..dd7ad2c1 --- /dev/null +++ b/configs/pxelinux.cfg @@ -0,0 +1,35 @@ +TIMEOUT 30 +ONTIMEOUT update + +MENU background #00000000 * * +MENU color title * #FF22BBCC * +MENU color sel * #FFFFFFFF #FF22BBCC * +MENU color hotsel 1;7;37;40 #ffffffff #76a1d0ff * + +UI vesamenu.c32 +MENU TITLE FICKIT PXE BOOT + +LABEL backend + MENU LABEL Prepare for ^backend + LINUX /fickit-prepare-kernel + INITRD /fickit-prepare-initrd.img + APPEND console=tty0 fickit.autoprepare=backend +LABEL frontend + MENU LABEL Prepare for ^frontend + LINUX /fickit-kernel + INITRD /fickit-boot-initrd.img + APPEND console=tty0 fickit.autoprepare=frontend +LABEL prepare + MENU LABEL Prepare with ^shell + LINUX /fickit-kernel + INITRD /fickit-boot-initrd.img + APPEND console=tty0 +LABEL update + MENU LABEL ^Update images + LINUX /fickit-kernel + INITRD /fickit-update-initrd.img + APPEND console=ttyS0 console=tty0 +MENU SEPARATOR +LABEL poweroff + MENU LABEL ^Shutdown + KERNEL poweroff.c32 diff --git a/configs/udhcpd-sample.conf b/configs/udhcpd-sample.conf new file mode 100644 index 00000000..30f9b119 --- /dev/null +++ b/configs/udhcpd-sample.conf @@ -0,0 +1,59 @@ +# Sample udhcpd configuration file (/etc/udhcpd.conf) +# Values shown are defaults + +# The start and end of the IP lease block +start 192.168.255.100 +end 192.168.255.200 + +# The interface that udhcpd will use +interface eth0 + +# The maximum number of leases (includes addresses reserved +# by OFFER's, DECLINE's, and ARP conflicts). Will be corrected +# if it's bigger than IP lease block, but it ok to make it +# smaller than lease block. +max_leases 100 + +# The amount of time that an IP will be reserved (leased to nobody) +# if a DHCP decline message is received (seconds) +#decline_time 3600 + +# The amount of time that an IP will be reserved +# if an ARP conflict occurs (seconds) +#conflict_time 3600 + +# How long an offered address is reserved (seconds) +#offer_time 60 + +# If client asks for lease below this value, it will be rounded up +# to this value (seconds) +#min_lease 60 + +# The location of the pid file +#pidfile /var/run/udhcpd.pid + +# The location of the leases file +#lease_file /var/lib/misc/udhcpd.leases + +# The following are BOOTP specific options +# next server to use in bootstrap +siaddr 192.168.255.2 # default: 0.0.0.0 (none) +# tftp server name +#sname zorak # default: none +# tftp file to download (e.g. kernel image) +boot_file pxelinux.0 # default: none + +# NOTE: "boot_file FILE" and "opt bootfile FILE" are conceptually the same, +# but "boot_file" goes into BOOTP-defined fixed-size field in the packet, +# whereas "opt bootfile" goes into DHCP option 0x43. +# Same for "sname HOST" and "opt tftp HOST". + +# The remainder of options are DHCP options and can be specified with the +# keyword 'opt' or 'option'. If an option can take multiple items, such +# as the dns option, they can be listed on the same line, or multiple +# lines. +# Examples: +#opt dns 192.168.10.2 192.168.10.10 +option subnet 255.255.255.0 +opt router 192.168.255.2 +option lease 3600 diff --git a/fickit-prepare.yml b/fickit-prepare.yml index 45b07993..6e63bd58 100644 --- a/fickit-prepare.yml +++ b/fickit-prepare.yml @@ -53,30 +53,57 @@ files: ip link set eth0 up udhcpc -i eth0 + # /proc/cmdline parser (from Gentoo Wiki) + cmdline() { + local value + value=" $(cat /proc/cmdline) " + value="${value##* $1=}" + value="${value%% *}" + [ "$value" != "" ] && echo "$value" + } + # Retrieve metadata wget -O /tmp/metadata.iso "$(ip r | grep default | awk '{ print $3 }')/fickit-metadata.iso" mount /tmp/metadata.iso /mnt /usr/bin/metadata -v file=/mnt/user-data - # Try to detect backend/frontend setup - if ip l | grep eth3 > /dev/null + AUTOPREPARE=$(cmdline fickit.autoprepare) + if [ -z "${AUTOPREPARE}" ] + then + # Try to detect backend/frontend setup + if ip l | grep -q eth3 + then + DEFAULT_BOOT=1 + echo -n "Detected: FRONTEND host " + else + DEFAULT_BOOT=0 + echo -n "Detected: BACKEND host " + fi + + [ "${RAID}" -eq 1 ] && echo "with RAID setup" || echo "without raid" + + echo + read -p "Proceed? (y/N/Front/Back) " V + if [ "$V" == "F" ] || [ "$V" == "f" ]; then + DEFAULT_BOOT=1 + elif [ "$V" == "B" ] || [ "$V" == "b" ]; then + DEFAULT_BOOT=0 + elif [ "$V" != "y" ]; then + while true; do + /bin/ash + done + fi + elif [ "${AUTOPREPARE}" == "backend" ] then DEFAULT_BOOT=1 - echo -n "Detected: FRONTEND host " + elif [ "${AUTOPREPARE}" == "frontend" ] + then + DEFAULT_BOOT=0 else - DEFAULT_BOOT=0 - echo -n "Detected: BACKEND host " - fi + echo + echo "Invalid fickit.autoprepare value: got $AUTOPREPARE, expected frontend or backend." + echo - [ "${RAID}" -eq 1 ] && echo "with RAID setup" || echo "without raid" - - echo - read -p "Proceed? (y/N/Front/Back) " V - if [ "$V" == "F" ] || [ "$V" == "f" ]; then - DEFAULT_BOOT=1 - elif [ "$V" == "B" ] || [ "$V" == "b" ]; then - DEFAULT_BOOT=0 - elif [ "$V" != "y" ]; then while true; do /bin/ash done