From b922e06827c22484240879f358ab325883017434 Mon Sep 17 00:00:00 2001 From: jiaojm <13763605353@163.com> Date: Mon, 5 Jan 2026 17:10:12 +0800 Subject: [PATCH 1/2] fix a bug --- .github/workflows/docker.yml | 32 ++++++++++++---------- Dockerfile | 53 ++++++++++++++++++++++++++++++------ Dockerfile.alpine | 39 +++++++++++++++++++++----- 3 files changed, 94 insertions(+), 30 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 65db4f2..bc7fdae 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -17,14 +17,16 @@ jobs: run: | sudo apt-get update sudo apt-get install -y autoconf automake build-essential cmake curl file libtool - - name: Cross build multi-arch binary - run: | - mkdir dist - for arch in amd64 armv7 arm64 s390x; do - env BUILD_TARGET=$arch ./scripts/cross-build.sh - [ "$arch" = "armv7" ] && arch="arm" - mkdir -p dist/$arch && cp build/ttyd dist/$arch/ttyd - done + + ## 在dockerfile内编译的话应该不需要在这里交叉编译了 + # - name: Cross build multi-arch binary + # run: | + # mkdir dist + # for arch in amd64 armv7 arm64 s390x; do + # env BUILD_TARGET=$arch ./scripts/cross-build.sh + # [ "$arch" = "armv7" ] && arch="arm" + # mkdir -p dist/$arch && cp build/ttyd dist/$arch/ttyd + # done - uses: docker/setup-qemu-action@v3 - uses: docker/setup-buildx-action@v3 - uses: docker/login-action@v3 @@ -49,22 +51,24 @@ jobs: echo "DOCKER_TAG=tsl0922/ttyd:latest" >> $GITHUB_ENV echo "ALPINE_TAG=tsl0922/ttyd:alpine" >> $GITHUB_ENV esac - - name: build/push docker image + + - name: Build and Push Ubuntu uses: docker/build-push-action@v6 with: context: . - file: ./Dockerfile - platforms: linux/amd64,linux/arm/v7,linux/arm64,linux/s390x + file: ./Dockerfile # 指向刚才修改的 Ubuntu 版文件 + platforms: linux/amd64,linux/arm64 push: true tags: | ${{ env.DOCKER_TAG }} ghcr.io/${{ env.DOCKER_TAG }} - - name: build/push docker image (alpine) + + - name: Build and Push Alpine uses: docker/build-push-action@v6 with: context: . - file: ./Dockerfile.alpine - platforms: linux/amd64,linux/arm/v7,linux/arm64,linux/s390x + file: ./Dockerfile.alpine # 指向精简版文件 + platforms: linux/amd64,linux/arm64 push: true tags: | ${{ env.ALPINE_TAG }} diff --git a/Dockerfile b/Dockerfile index d312df1..560106b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,15 +1,50 @@ -FROM ubuntu:20.04 +FROM docker.io/library/ubuntu:24.04 AS build-env -ARG TARGETARCH -# Dependencies -RUN apt-get update && apt-get install -y --no-install-recommends tini && rm -rf /var/lib/apt/lists/* +RUN apt-get update && \ + apt-get install -y \ + git \ + build-essential \ + cmake \ + libjson-c-dev \ + libwebsockets-dev -# Application -COPY ./dist/${TARGETARCH}/ttyd /usr/bin/ttyd +RUN git clone https://devstar.cn/devstar/webTerminal.git /home/webTerminal +# 设置工作目录并构建 +WORKDIR /home/webTerminal/build +RUN cmake .. +RUN make && make install -EXPOSE 7681 -WORKDIR /root + +FROM ubuntu:24.04 + +# 从构建阶段复制编译好的程序 +COPY --from=build-env /home/webTerminal/build/ttyd /home/webTerminal/build/ttyd + +# 只安装运行时需要的库 +RUN apt-get update && \ + apt-get install -y \ + curl && \ + curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc && \ + apt-get install -y tini \ + libjson-c-dev \ + libwebsockets-dev && \ + echo \ + "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/ \ + $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \ + tee /etc/apt/sources.list.d/docker.list > /dev/null && \ + apt-get update && apt-get install -y docker-ce-cli && \ + apt remove --purge curl -y && apt autoremove -y && apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* ENTRYPOINT ["/usr/bin/tini", "--"] -CMD ["ttyd", "-W", "bash"] +CMD ["/home/webTerminal/build/ttyd", "-W", "bash"] + +# To acquire devstar.cn/devstar/webterminal:latest: +# $ docker build --no-cache -t devstar.cn/devstar/webterminal:v1.0 -f docker/Dockerfile.webTerminal . +# $ docker login devstar.cn +# $ docker push devstar.cn/devstar/webterminal:v1.0 +# $ docker tag devstar.cn/devstar/webterminal:v1.0 devstar.cn/devstar/webterminal:latest +# $ docker push devstar.cn/devstar/webterminal:latest + +# Release Notes: +# v1.0 - Initial release \ No newline at end of file diff --git a/Dockerfile.alpine b/Dockerfile.alpine index 141d56f..4b6ea77 100644 --- a/Dockerfile.alpine +++ b/Dockerfile.alpine @@ -1,15 +1,40 @@ -FROM alpine +FROM alpine:3.19 AS build-env -ARG TARGETARCH +RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories +# 安装依赖 +RUN apk add --no-cache \ + git \ + build-base \ + cmake \ + linux-headers \ + json-c-dev \ + libwebsockets-dev -# Dependencies -RUN apk add --no-cache bash tini +RUN git clone https://devstar.cn/devstar/webTerminal.git /home/webTerminal -# Application -COPY ./dist/${TARGETARCH}/ttyd /usr/bin/ttyd +WORKDIR /home/webTerminal/build +RUN cmake .. \ + -DCMAKE_BUILD_TYPE=Release \ + && make \ + && make install + +FROM alpine:3.19 + +# 安装依赖 +RUN apk add --no-cache \ + bash \ + tini \ + docker-cli \ + json-c \ + libwebsockets + +COPY --from=build-env /home/webTerminal/build/ttyd /home/webTerminal/build/ttyd EXPOSE 7681 + WORKDIR /root ENTRYPOINT ["/sbin/tini", "--"] -CMD ["ttyd", "-W", "bash"] + +# 启动命令 +CMD ["/home/webTerminal/build/ttyd", "-W", "bash"] \ No newline at end of file -- 2.49.1 From 06a9374493a6b98a68cb75d40aee61718eea4f84 Mon Sep 17 00:00:00 2001 From: jiaojm <13763605353@163.com> Date: Mon, 5 Jan 2026 17:14:51 +0800 Subject: [PATCH 2/2] fix --- .github/workflows/docker.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index bc7fdae..ff22728 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -56,8 +56,8 @@ jobs: uses: docker/build-push-action@v6 with: context: . - file: ./Dockerfile # 指向刚才修改的 Ubuntu 版文件 - platforms: linux/amd64,linux/arm64 + file: ./Dockerfile + platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/s390x push: true tags: | ${{ env.DOCKER_TAG }} @@ -67,8 +67,8 @@ jobs: uses: docker/build-push-action@v6 with: context: . - file: ./Dockerfile.alpine # 指向精简版文件 - platforms: linux/amd64,linux/arm64 + file: ./Dockerfile.alpine + platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/s390x push: true tags: | ${{ env.ALPINE_TAG }} -- 2.49.1