mirror of
https://github.com/AlbrechtL/openwrt-docker.git
synced 2026-10-28 16:01:02 +00:00
Port OpenWrt docker image to x86_64
This commit is contained in:
@@ -49,18 +49,20 @@ jobs:
|
||||
context: .
|
||||
push: true
|
||||
provenance: false
|
||||
platforms: linux/arm64
|
||||
platforms: |
|
||||
linux/x86_64
|
||||
linux/arm64
|
||||
build-args: |
|
||||
OPENWRT_VERSION=${{ env.OPENWRT_VERSION }}
|
||||
BUILDKIT_MULTI_PLATFORM=1
|
||||
tags: |
|
||||
albrechtloh/qemu-openwrt:openwrt-${{ env.OPENWRT_VERSION }}-${{ env.GIT_HASH }}
|
||||
albrechtloh/qemu-openwrt:latest
|
||||
localhost:5000/local/qemu-openwrt:latest
|
||||
albrechtloh/openwrt-docker:openwrt-${{ env.OPENWRT_VERSION }}-${{ env.GIT_HASH }}
|
||||
albrechtloh/openwrt-docker:latest
|
||||
localhost:5000/local/openwrt-docker:latest
|
||||
|
||||
- name: Inspect
|
||||
run: |
|
||||
docker buildx imagetools inspect localhost:5000/local/qemu-openwrt:latest
|
||||
docker buildx imagetools inspect localhost:5000/local/openwrt-docker:latest
|
||||
|
||||
- name: Login to Weidmueller wmucdev
|
||||
uses: docker/login-action@v3
|
||||
|
||||
+50
-19
@@ -3,12 +3,26 @@ FROM alpine:latest
|
||||
ARG NOVNC_VERSION="1.4.0"
|
||||
ARG OPENWRT_VERSION="23.05.4"
|
||||
ARG VERSION_ARG="0.1"
|
||||
ARG TARGETPLATFORM
|
||||
ARG OPENWRT_ROOTFS_IMG
|
||||
ARG OPENWRT_KERNEL
|
||||
ARG OPENWRT_ROOTFS_TAR
|
||||
|
||||
RUN apk add --no-cache \
|
||||
# Configure Alpine
|
||||
RUN echo "Building for platform '$TARGETPLATFORM'" \
|
||||
&& if [ "$TARGETPLATFORM" = "linux/amd64" ]; then \
|
||||
CPU_ARCH="x86_64"; \
|
||||
elif [ "$TARGETPLATFORM" = "linux/arm64" ]; then \
|
||||
CPU_ARCH="aarch64"; \
|
||||
else \
|
||||
echo "Error: CPU architecture $TARGETPLATFORM is not supported"; \
|
||||
exit 1; \
|
||||
fi \
|
||||
&& apk add --no-cache \
|
||||
supervisor \
|
||||
bash \
|
||||
wget \
|
||||
qemu-system-aarch64 \
|
||||
qemu-system-"$CPU_ARCH" \
|
||||
qemu-hw-usb-host \
|
||||
qemu-hw-usb-redirect \
|
||||
nginx \
|
||||
@@ -30,25 +44,41 @@ RUN apk add --no-cache \
|
||||
&& pip install -r /usr/share/script-server/requirements.txt \
|
||||
&& sed -i 's/^worker_processes.*/worker_processes 1;daemon off;/' /etc/nginx/nginx.conf
|
||||
|
||||
# Get OpenWrt images
|
||||
RUN mkdir /var/vm \
|
||||
mkdir /var/vm/packages \
|
||||
&& if [ "$OPENWRT_VERSION" = "master" ] ; then \
|
||||
wget "https://downloads.openwrt.org/snapshots/targets/armsr/armv8/openwrt-armsr-armv8-generic-ext4-rootfs.img.gz" \
|
||||
-O /var/vm/rootfs-${OPENWRT_VERSION}.img.gz \
|
||||
&& wget "https://downloads.openwrt.org/snapshots/targets/armsr/armv8/openwrt-armsr-armv8-generic-kernel.bin" \
|
||||
-O /var/vm/kernel.bin \
|
||||
&& wget "https://downloads.openwrt.org/snapshots/targets/armsr/armv8/openwrt-armsr-armv8-rootfs.tar.gz" \
|
||||
-O /tmp/rootfs-${OPENWRT_VERSION}.tar.gz ; \
|
||||
# Handle different CPUs architectures and choose the correct OpenWrt images
|
||||
RUN echo "Building for platform '$TARGETPLATFORM'" \
|
||||
&& if [ "$TARGETPLATFORM" = "linux/amd64" ]; then \
|
||||
if [ "$OPENWRT_VERSION" = "master" ]; then \
|
||||
OPENWRT_ROOTFS_IMG="https://downloads.openwrt.org/snapshots/targets/x86/64/openwrt-x86-64-generic-ext4-rootfs.img.gz"; \
|
||||
OPENWRT_KERNEL="https://downloads.openwrt.org/snapshots/targets/x86/64/openwrt-x86-64-generic-kernel.bin"; \
|
||||
OPENWRT_ROOTFS_TAR="https://downloads.openwrt.org/snapshots/targets/x86/64/openwrt-x86-64-rootfs.tar.gz"; \
|
||||
else \
|
||||
OPENWRT_ROOTFS_IMG="https://archive.openwrt.org/releases/${OPENWRT_VERSION}/targets/x86/64/openwrt-${OPENWRT_VERSION}-x86-64-generic-ext4-rootfs.img.gz"; \
|
||||
OPENWRT_KERNEL="https://archive.openwrt.org/releases/${OPENWRT_VERSION}/targets/x86/64/openwrt-${OPENWRT_VERSION}-x86-64-generic-kernel.bin"; \
|
||||
OPENWRT_ROOTFS_TAR="https://archive.openwrt.org/releases/${OPENWRT_VERSION}/targets/x86/64/openwrt-${OPENWRT_VERSION}-x86-64-rootfs.tar.gz"; \
|
||||
fi; \
|
||||
elif [ "$TARGETPLATFORM" = "linux/arm64" ]; then \
|
||||
if [ "$OPENWRT_VERSION" = "master" ]; then \
|
||||
OPENWRT_ROOTFS_IMG="https://downloads.openwrt.org/snapshots/targets/armsr/armv8/openwrt-armsr-armv8-generic-ext4-rootfs.img.gz"; \
|
||||
OPENWRT_KERNEL="https://downloads.openwrt.org/snapshots/targets/armsr/armv8/openwrt-armsr-armv8-generic-kernel.bin"; \
|
||||
OPENWRT_ROOTFS_TAR="https://downloads.openwrt.org/snapshots/targets/armsr/armv8/openwrt-armsr-armv8-rootfs.tar.gz"; \
|
||||
else \
|
||||
OPENWRT_ROOTFS_IMG="https://archive.openwrt.org/releases/${OPENWRT_VERSION}/targets/armsr/armv8/openwrt-${OPENWRT_VERSION}-armsr-armv8-generic-ext4-rootfs.img.gz"; \
|
||||
OPENWRT_KERNEL="https://archive.openwrt.org/releases/${OPENWRT_VERSION}/targets/armsr/armv8/openwrt-${OPENWRT_VERSION}-armsr-armv8-generic-kernel.bin"; \
|
||||
OPENWRT_ROOTFS_TAR="https://archive.openwrt.org/releases/${OPENWRT_VERSION}/targets/armsr/armv8/openwrt-${OPENWRT_VERSION}-armsr-armv8-rootfs.tar.gz"; \
|
||||
fi; \
|
||||
else \
|
||||
wget "https://archive.openwrt.org/releases/${OPENWRT_VERSION}/targets/armsr/armv8/openwrt-${OPENWRT_VERSION}-armsr-armv8-generic-ext4-rootfs.img.gz" \
|
||||
-O /var/vm/rootfs-${OPENWRT_VERSION}.img.gz \
|
||||
&& wget "https://archive.openwrt.org/releases/${OPENWRT_VERSION}/targets/armsr/armv8/openwrt-${OPENWRT_VERSION}-armsr-armv8-generic-kernel.bin" \
|
||||
-O /var/vm/kernel.bin \
|
||||
&& wget "https://archive.openwrt.org/releases/${OPENWRT_VERSION}/targets/armsr/armv8/openwrt-${OPENWRT_VERSION}-armsr-armv8-rootfs.tar.gz" \
|
||||
-O /tmp/rootfs-${OPENWRT_VERSION}.tar.gz ; \
|
||||
echo "Error: CPU architecture $TARGETPLATFORM is not supported"; \
|
||||
exit 1; \
|
||||
fi \
|
||||
\
|
||||
# Get OpenWrt images \
|
||||
&& mkdir /var/vm \
|
||||
&& mkdir /var/vm/packages \
|
||||
&& echo $OPENWRT_ROOTFS_IMG \
|
||||
&& wget $OPENWRT_ROOTFS_IMG -O /var/vm/rootfs-${OPENWRT_VERSION}.img.gz \
|
||||
&& wget "${OPENWRT_KERNEL}" -O /var/vm/kernel.bin \
|
||||
&& wget "${OPENWRT_ROOTFS_TAR}" -O /tmp/rootfs-${OPENWRT_VERSION}.tar.gz \
|
||||
\
|
||||
# Use OpenWrt rootfs to download additional IPKs and put them into the Docker image \
|
||||
&& mkdir /tmp/openwrt-rootfs \
|
||||
&& tar -xzf /tmp/rootfs-${OPENWRT_VERSION}.tar.gz -C /tmp/openwrt-rootfs \
|
||||
@@ -71,7 +101,8 @@ RUN mkdir /var/vm \
|
||||
&& rm /tmp/rootfs-${OPENWRT_VERSION}.tar.gz \
|
||||
&& echo "OPENWRT_VERSION=\"${OPENWRT_VERSION}\"" > /var/vm/openwrt_metadata.conf \
|
||||
&& echo "OPENWRT_IMAGE_CREATE_DATETIME=\"`date`\"" >> /var/vm/openwrt_metadata.conf \
|
||||
&& echo "OPENWRT_IMAGE_ID=\"`uuidgen`\"" >> /var/vm/openwrt_metadata.conf
|
||||
&& echo "OPENWRT_IMAGE_ID=\"`uuidgen`\"" >> /var/vm/openwrt_metadata.conf \
|
||||
&& echo "OPENWRT_CPU_ARCH=\"${TARGETPLATFORM}\"" >> /var/vm/openwrt_metadata.conf
|
||||
|
||||
COPY supervisord.conf /etc/supervisord.conf
|
||||
COPY ./src /run/
|
||||
|
||||
+2
-2
@@ -2,8 +2,8 @@ version: "3"
|
||||
services:
|
||||
qemu:
|
||||
container_name: openwrt
|
||||
#image: albrechtloh/qemu-openwrt:openwrt-23.05.3-2
|
||||
#image: openwrt-docker-arm64
|
||||
#image: albrechtloh/openwrt-docker:latest
|
||||
#image: openwrt-docker
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
# OpenWrt qemu docker container for arm64 and Weidmueller u-OS
|
||||
# OpenWrt qemu docker container for x86_64, arm64 and Weidmueller u-OS
|
||||
|
||||
Automated build: [](https://github.com/AlbrechtL/openwrt-docker-arm64-build/actions/workflows/build.yml)
|
||||
|
||||
OpenWrt in a docker container utilizing qemu. Tested on Raspberry Pi 5 and Weidmueller UC20-M4000 PLC but should work on any ARM64 (aarch64) based hardware. It uses high-performance QEMU options (like KVM acceleration, kernel-mode networking, IO threading, etc.) to achieve near-native speed.
|
||||
|
||||
* Docker images can be found a docker hub https://hub.docker.com/r/albrechtloh/qemu-openwrt
|
||||
* Weidmueller u-OS apps are currently only available via Github Actions https://github.com/AlbrechtL/openwrt-docker-arm64-build/actions
|
||||
OpenWrt in a docker container utilizing qemu. Tested on Raspberry Pi 5 and Weidmueller UC20-M4000 PLC but should work on any x86_64 and ARM64 (aarch64) based hardware. It uses high-performance QEMU options (like KVM acceleration, kernel-mode networking, IO threading, etc.) to achieve near-native speed.
|
||||
4 and
|
||||
* Docker images can be found a docker hub https://hub.docker.com/r/albrechtloh/openwrt-docker
|
||||
* Weidmueller u-OS apps are currently only available via Github Actions https://github.com/AlbrechtL/openwrt-docker/actions
|
||||
|
||||
## Features
|
||||
|
||||
@@ -41,11 +41,11 @@ docker compose up
|
||||
|
||||
If you like to specify a specific OpenWrt version you can do
|
||||
```bash
|
||||
docker build -t openwrt-docker-arm64 . --build-arg OPENWRT_VERSION="23.05.2" && docker compose up
|
||||
docker build -t openwrt-docker . --build-arg OPENWRT_VERSION="23.05.4" && docker compose up
|
||||
```
|
||||
or for the latest development master. The `--no-cache` option is necessary to get always the newest version.
|
||||
```bash
|
||||
docker build --no-cache -t openwrt-docker-arm64 . --build-arg OPENWRT_VERSION="master" && docker compose up
|
||||
docker build --no-cache -t openwrt-docker . --build-arg OPENWRT_VERSION="master" && docker compose up
|
||||
```
|
||||
|
||||
## Screenshots
|
||||
|
||||
@@ -7,14 +7,18 @@ set -Eeuo pipefail
|
||||
[ "$(id -u)" -ne "0" ] && error "Script must be executed with root privileges." && exit 12
|
||||
|
||||
APP="OpenWrt"
|
||||
SUPPORT="https://github.com/AlbrechtL/openwrt-docker-arm64-build"
|
||||
SUPPORT="https://github.com/AlbrechtL/openwrt-docker"
|
||||
|
||||
echo "❯ Starting $APP for Docker v$(</run/version)..."
|
||||
echo "❯ For support visit $SUPPORT"
|
||||
echo
|
||||
|
||||
# Show alpine version
|
||||
echo "**** Alpine release ****"
|
||||
cat /etc/*release*
|
||||
echo "**** End Alpine release information ****"
|
||||
|
||||
echo "CPU architecture: '$(arch)'"
|
||||
|
||||
# Check system
|
||||
if [ ! -d "/dev/shm" ]; then
|
||||
|
||||
+13
-6
@@ -9,7 +9,10 @@ trap - ERR
|
||||
. /run/install_openwrt_rootfs.sh
|
||||
. /run/migrate_openwrt_rootfs.sh
|
||||
|
||||
VERS=$(qemu-system-aarch64 --version | head -n 1 | cut -d '(' -f 1)
|
||||
# CPU architecture specific
|
||||
CPU_ARCH=$(arch)
|
||||
|
||||
VERS=$(qemu-system-"$CPU_ARCH" --version | head -n 1 | cut -d '(' -f 1)
|
||||
FILE=/storage/rootfs-${OPENWRT_IMAGE_ID}.img
|
||||
|
||||
# Attach physical interfaces to Docker container
|
||||
@@ -119,17 +122,23 @@ attach_veth_if () {
|
||||
fi
|
||||
}
|
||||
|
||||
# Handle dirfferent architectures
|
||||
if [ $CPU_ARCH = "aarch64" ]; then
|
||||
CPU_ARGS="-cpu cortex-a53 -M virt -bios /usr/share/qemu/edk2-aarch64-code.fd -vga none -device ramfb"
|
||||
else
|
||||
CPU_ARGS="-M pc -vga std"
|
||||
fi
|
||||
|
||||
# Check KVM
|
||||
info "Checking for KVM ..."
|
||||
KVM_ERR=""
|
||||
CPU_ARGS="-cpu cortex-a53"
|
||||
if [ ! -e /dev/kvm ]; then
|
||||
KVM_ERR="(device file missing)"
|
||||
else
|
||||
if ! sh -c 'echo -n > /dev/kvm' &> /dev/null; then
|
||||
KVM_ERR="(no write access)"
|
||||
else
|
||||
CPU_ARGS="--enable-kvm -cpu host"
|
||||
CPU_ARGS+=" --enable-kvm -cpu host"
|
||||
info "KVM detected"
|
||||
fi
|
||||
fi
|
||||
@@ -195,13 +204,11 @@ info "Booting image using $VERS..."
|
||||
[[ "$DEBUG" == [Yy1]* ]] && set -x
|
||||
|
||||
#************************ FINAL BOOTING ************************
|
||||
qemu-system-aarch64 -M virt \
|
||||
qemu-system-"$CPU_ARCH" \
|
||||
-m 128 \
|
||||
-nodefaults \
|
||||
$CPU_ARGS -smp $CPU_COUNT \
|
||||
-bios /usr/share/qemu/edk2-aarch64-code.fd \
|
||||
-display vnc=:0,websocket=5700 \
|
||||
-vga none -device ramfb \
|
||||
-kernel /var/vm/kernel.bin -append "root=fe00 console=tty0" \
|
||||
-blockdev driver=raw,node-name=hd0,cache.direct=on,file.driver=file,file.filename=${FILE} \
|
||||
-device virtio-blk-pci,drive=hd0 \
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
"logo": "openwrt_logo_text_vertical_blue_and_dark_blue.svg",
|
||||
"vendor": {
|
||||
"name": "Albrecht Lohofener",
|
||||
"url": "https://github.com/AlbrechtL/openwrt-docker-arm64-build/",
|
||||
"url": "https://github.com/AlbrechtL/openwrt-docker",
|
||||
"email": "albrechtloh@gmx.de",
|
||||
"street": "",
|
||||
"zip": "",
|
||||
@@ -17,7 +17,7 @@
|
||||
"u-link-addon-u-link": {
|
||||
"type": "docker-compose",
|
||||
"config": {
|
||||
"image": "local/qemu-openwrt:latest",
|
||||
"image": "localhost:5000/local/openwrt-docker:latest",
|
||||
"privileged": true,
|
||||
"restart": "no",
|
||||
"volumes": [
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"serveraddress": "localhost:5000",
|
||||
"serveraddress": "",
|
||||
"username": "",
|
||||
"password": ""
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user