TrueNAS Scale使用Docker编译Openwrt

相关资料文档:
https://github.com/mwarning/docker-openwrt-builder
https://github.com/noonien/docker-openwrt-buildroot
https://blog.mjyai.com/2021/02/12/docker-compile-lede-openwrt/
https://blog.laolilin.com/posts/2020/02/using_docker_to_build_openwrt.html

清理docker残留数据
docker system prune
docker volume prune
docker image prune
构建镜像
docker build -t foxopenwrt . --network host
运行镜像
docker run -it --rm --network host foxopenwrt gosu openwrt bash

TrueNAS Scale相关命令

# 获取全部命名空间的pod
k3s kubectl get pods --all-namespaces
# 获取指定命名空间的pod
k3s kubectl get pods --namespace=ix-foxopenwrt
# 获取指定名称pod的信息
k3s kubectl get pods --namespace=ix-foxopenwrt foxopenwrt-ix-chart-69b58d7b77-lnd76
# 进入指定pod的命令行
k3s kubectl exec -n ix-foxopenwrt -it foxopenwrt-ix-chart-69b58d7b77-lnd76 -- "gosu openwrt bash"
# 直接运行镜像进入命令行
k3s kubectl run  -n ix-foxopenwrt -it foxopenwrt2 --image=foxopenwrt --image-pull-policy=Never -- "gosu openwrt bash"

openwrt编译命令

./scripts/feeds update -a
./scripts/feeds install -a
make menuconfig
# 编译
make -j $(($(nproc)+1)) V=s
# 编译并输出日志到文件
make -j $(($(nproc)+1)) V=s 2>&1 | tee build.log | grep -i -E "^make.*(error|[12345]...Entering dir)"

openwrt编译单独组件

make target/compile
make package/cleanup
make package/compile
make package/install
make package/preconfig
make target/install
make package/index

示例

make toolchain/clean
make toolchain/compile -j $(($(nproc)+1)) V=s
make tools/e2fsprogs/compile -j1 V=s

编译时V=s等相关参数说明

  • s: stdout+stderr (equal to the old V=99)
  • c: commands (for build systems that suppress commands by default, e.g. kbuild, cmake)
  • w: warnings/errors only (equal to the old V=1)

使用支持s6模式的镜像

FROM ghcr.io/linuxserver/baseimage-ubuntu:focal

ARG DEBIAN_FRONTEND=noninteractive

RUN apt-get update && \
    apt-get -y install --no-install-recommends build-essential asciidoc binutils \
    bzip2 gawk gettext git libncurses5-dev libz-dev patch python3 python2.7 \
    unzip zlib1g-dev lib32gcc1 libc6-dev-i386 subversion flex uglifyjs git-core \
    gcc-multilib p7zip p7zip-full msmtp libssl-dev texinfo libglib2.0-dev xmlto \
    qemu-utils upx libelf-dev autoconf automake libtool autopoint device-tree-compiler \
    g++-multilib antlr3 gperf wget curl swig rsync sudo screen vim gosu && \
    apt-get clean all

RUN useradd -m openwrt -s /bin/bash && \
    echo 'openwrt ALL=NOPASSWD: ALL' > /etc/sudoers.d/openwrt && \
    echo 'shell "/bin/bash"' >> /etc/screenrc

WORKDIR /home/openwrt

使用非s6模式的镜像

FROM ubuntu:20.04

ARG DEBIAN_FRONTEND=noninteractive

RUN apt-get update && \
    apt-get -y install --no-install-recommends build-essential asciidoc binutils \
    bzip2 gawk gettext git libncurses5-dev libz-dev patch python3 python2.7 \
    unzip zlib1g-dev lib32gcc1 libc6-dev-i386 subversion flex uglifyjs git-core \
    gcc-multilib p7zip p7zip-full msmtp libssl-dev texinfo libglib2.0-dev xmlto \
    qemu-utils upx libelf-dev autoconf automake libtool autopoint device-tree-compiler \
    g++-multilib antlr3 gperf wget curl swig rsync sudo screen vim && \
    apt-get clean all

RUN useradd -m openwrt &&\
    echo 'openwrt ALL=NOPASSWD: ALL' > /etc/sudoers.d/openwrt

USER openwrt
WORKDIR /home/openwrt

ENTRYPOINT ["/bin/bash", "-c", "sleep infinity"]

execk3s.sh
输入命名空间所需执行命令后自动选择pod执行

#!/bin/bash

blue(){
    echo -e "\033[36;1m${@}\033[0m"
}
green(){
    echo -e "\033[32;1m${@}\033[0m"
}
red(){
    echo -e "\033[31;1m${@}\033[0m"
}
yellow(){
    echo -e "\033[33;1m${@}\033[0m"
}

if [ $# -lt 2 ] ; then
    green "未输入完整参数";
else
    PODCOUNT=`k3s kubectl get pods --no-headers --namespace=$1 | wc -l`;
    if [ ${PODCOUNT} -gt 1 ] ; then
        green "发现多个pod";
        exit 1;
    elif [ ${PODCOUNT} -lt 1 ] ; then
        green "未发现pod";
        exit 1;
    else
        PODNAME=`k3s kubectl get pods --no-headers --namespace=$1 | awk '{print $1}'`;
        green "发现pod --- $PODNAME";
        k3s kubectl exec -n $1 -it $PODNAME -- $2
    fi
fi

TrueNas Scale安装portainer
portainer.yaml

---
# Source: portainer/templates/namespace.yaml
apiVersion: v1
kind: Namespace
metadata:
  name: portainer
---
# Source: portainer/templates/serviceaccount.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
  name: portainer-sa-clusteradmin
  namespace: portainer
  labels:
    app.kubernetes.io/name: portainer
    app.kubernetes.io/instance: portainer
    app.kubernetes.io/version: "ce-latest-ee-2.10.0"
---
# Source: portainer/templates/rbac.yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: portainer
  labels:
    app.kubernetes.io/name: portainer
    app.kubernetes.io/instance: portainer
    app.kubernetes.io/version: "ce-latest-ee-2.10.0"
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: cluster-admin
subjects:
- kind: ServiceAccount
  namespace: portainer
  name: portainer-sa-clusteradmin
---
# Source: portainer/templates/service.yaml
apiVersion: v1
kind: Service
metadata:
  name: portainer
  namespace: portainer
  labels:
    io.portainer.kubernetes.application.stack: portainer
    app.kubernetes.io/name: portainer
    app.kubernetes.io/instance: portainer
    app.kubernetes.io/version: "ce-latest-ee-2.10.0"
spec:
  type: NodePort
  ports:
    - port: 9000
      targetPort: 9000
      protocol: TCP
      name: http
      nodePort: 30777  
    - port: 9443
      targetPort: 9443
      protocol: TCP
      name: https
      nodePort: 30779      
    - port: 30776
      targetPort: 30776
      protocol: TCP
      name: edge
      nodePort: 30776
  selector:
    app.kubernetes.io/name: portainer
    app.kubernetes.io/instance: portainer
---
# Source: portainer/templates/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: portainer
  namespace: portainer
  labels:
    io.portainer.kubernetes.application.stack: portainer
    app.kubernetes.io/name: portainer
    app.kubernetes.io/instance: portainer
    app.kubernetes.io/version: "ce-latest-ee-2.10.0"
spec:
  replicas: 1
  strategy:
    type: "Recreate"
  selector:
    matchLabels:
      app.kubernetes.io/name: portainer
      app.kubernetes.io/instance: portainer
  template:
    metadata:
      labels:
        app.kubernetes.io/name: portainer
        app.kubernetes.io/instance: portainer
    spec:
      nodeSelector:
        {}
      serviceAccountName: portainer-sa-clusteradmin
      containers:
        - name: portainer
          image: "portainer/portainer-ce:latest"
          imagePullPolicy: Always
          args:
          - '--tunnel-port=30776'          
          volumeMounts:
            - name: data
              mountPath: /data              
            - name: docker
              mountPath: /var/run/docker.sock              
          ports:
            - name: http
              containerPort: 9000
              protocol: TCP
            - name: https
              containerPort: 9443
              protocol: TCP                
            - name: tcp-edge
              containerPort: 8000
              protocol: TCP              
          livenessProbe:
            httpGet:
              path: /
              port: 9443
              scheme: HTTPS
          readinessProbe:
            httpGet:
              path: /
              port: 9443
              scheme: HTTPS        
          resources:
            {}
      volumes:
        - name: "data"
          hostPath:
            # directory location on host
            path: /mnt/ssd-storage/ix-applications/portainer
            # this field is optional
            type: Directory
        - name: "docker"
          hostPath:
            path: /var/run/docker.sock
上一篇
下一篇