fix-dockerfile #5

Closed
alexios wants to merge 2 commits from fix-dockerfile into main
3 changed files with 94 additions and 30 deletions
Showing only changes of commit b922e06827 - Show all commits

View File

@@ -17,14 +17,16 @@ jobs:
run: | run: |
sudo apt-get update sudo apt-get update
sudo apt-get install -y autoconf automake build-essential cmake curl file libtool sudo apt-get install -y autoconf automake build-essential cmake curl file libtool
- name: Cross build multi-arch binary
run: | ## 在dockerfile内编译的话应该不需要在这里交叉编译了
mkdir dist # - name: Cross build multi-arch binary
for arch in amd64 armv7 arm64 s390x; do # run: |
env BUILD_TARGET=$arch ./scripts/cross-build.sh # mkdir dist
[ "$arch" = "armv7" ] && arch="arm" # for arch in amd64 armv7 arm64 s390x; do
mkdir -p dist/$arch && cp build/ttyd dist/$arch/ttyd # env BUILD_TARGET=$arch ./scripts/cross-build.sh
done # [ "$arch" = "armv7" ] && arch="arm"
# mkdir -p dist/$arch && cp build/ttyd dist/$arch/ttyd
# done
- uses: docker/setup-qemu-action@v3 - uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3 - uses: docker/setup-buildx-action@v3
- uses: docker/login-action@v3 - uses: docker/login-action@v3
@@ -49,22 +51,24 @@ jobs:
echo "DOCKER_TAG=tsl0922/ttyd:latest" >> $GITHUB_ENV echo "DOCKER_TAG=tsl0922/ttyd:latest" >> $GITHUB_ENV
echo "ALPINE_TAG=tsl0922/ttyd:alpine" >> $GITHUB_ENV echo "ALPINE_TAG=tsl0922/ttyd:alpine" >> $GITHUB_ENV
esac esac
- name: build/push docker image
- name: Build and Push Ubuntu
uses: docker/build-push-action@v6 uses: docker/build-push-action@v6
with: with:
context: . context: .
file: ./Dockerfile file: ./Dockerfile # 指向刚才修改的 Ubuntu 版文件
platforms: linux/amd64,linux/arm/v7,linux/arm64,linux/s390x platforms: linux/amd64,linux/arm64
push: true push: true
tags: | tags: |
${{ env.DOCKER_TAG }} ${{ env.DOCKER_TAG }}
ghcr.io/${{ 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 uses: docker/build-push-action@v6
with: with:
context: . context: .
file: ./Dockerfile.alpine file: ./Dockerfile.alpine # 指向精简版文件
platforms: linux/amd64,linux/arm/v7,linux/arm64,linux/s390x platforms: linux/amd64,linux/arm64
push: true push: true
tags: | tags: |
${{ env.ALPINE_TAG }} ${{ env.ALPINE_TAG }}

View File

@@ -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 && \
RUN apt-get update && apt-get install -y --no-install-recommends tini && rm -rf /var/lib/apt/lists/* apt-get install -y \
git \
build-essential \
cmake \
libjson-c-dev \
libwebsockets-dev
# Application RUN git clone https://devstar.cn/devstar/webTerminal.git /home/webTerminal
COPY ./dist/${TARGETARCH}/ttyd /usr/bin/ttyd # 设置工作目录并构建
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", "--"] 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

View File

@@ -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 git clone https://devstar.cn/devstar/webTerminal.git /home/webTerminal
RUN apk add --no-cache bash tini
# Application WORKDIR /home/webTerminal/build
COPY ./dist/${TARGETARCH}/ttyd /usr/bin/ttyd 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 EXPOSE 7681
WORKDIR /root WORKDIR /root
ENTRYPOINT ["/sbin/tini", "--"] ENTRYPOINT ["/sbin/tini", "--"]
CMD ["ttyd", "-W", "bash"]
# 启动命令
CMD ["/home/webTerminal/build/ttyd", "-W", "bash"]