Skip to content

Commit

Permalink
优化pixiu容器启动进程 (#569)
Browse files Browse the repository at this point in the history
  • Loading branch information
caoyingjunz authored Jan 15, 2025
1 parent c7c3227 commit 6dd3834
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 56 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build-webshell-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
branches:
- "master"
paths:
- 'docker/Dockerfile'
- 'docker/Dockerfile-toolbox'
- 'Makefile'

env:
Expand Down Expand Up @@ -39,7 +39,7 @@ jobs:
uses: docker/build-push-action@v5
with:
context: .
file: ./docker/Dockerfile
file: ./docker/Dockerfile-toolbox
platforms: linux/amd64,linux/arm64
build-args: |
K8S_VERSION=${{ env.K8S_VERSION }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
file: ./docker/Dockerfile
platforms: linux/amd64,linux/arm64
build-args: |
VERSION=${{ env.COMMIT_HASH }}-${{ env.TIMESTAMP }}
Expand Down
13 changes: 0 additions & 13 deletions Dockerfile

This file was deleted.

64 changes: 24 additions & 40 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,40 +1,24 @@
# 使用 Ubuntu 作为基础镜像
FROM ubuntu:22.04

ARG K8S_VERSION
ARG HELM_VERSION

# 安装vim
RUN apt-get update && apt-get install -y vim

# 安装必要的软件包
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y curl bash-completion

# 安装 kubectl
RUN ARCH=$(uname -m|sed 's|x86_64|amd64|'|sed 's|aarch64|arm64|') && \
curl -LO "https://dl.k8s.io/release/${K8S_VERSION}/bin/linux/${ARCH}/kubectl" && \
install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl && \
rm -rf kubectl

# 安装 helm
RUN ARCH=$(uname -m|sed 's|x86_64|amd64|'|sed 's|aarch64|arm64|') && \
curl -LO "https://get.helm.sh/helm-${HELM_VERSION}-linux-${ARCH}.tar.gz" && \
tar -zxvf helm-${HELM_VERSION}-linux-${ARCH}.tar.gz && \
rm -rf helm-${HELM_VERSION}-linux-${ARCH}.tar.gz && \
mv linux-${ARCH}/helm /usr/local/bin/helm && \
rm -rf linux-${ARCH}

# 配置 bash 补全和自定义的 PS1 提示符
RUN echo 'source /etc/profile.d/bash_completion.sh' >> /root/.bashrc \
&& echo 'source <(kubectl completion bash)' >> /root/.bashrc \
&& echo 'source <(helm completion bash)' >> /root/.bashrc \
&& echo "PS1='[\[\033[0;34m\]\u\[\033[0;37m\]@\[\033[0;35m\]\h\[\033[0;33m\] \w\[\033[0;37m\]]\[\033[0;31m\]\$\[\033[00m\] '" >> /root/.bashrc

# 设置工作目录
WORKDIR /root

# 设置环境变量等(可选)
ENV PATH="/usr/local/bin:${PATH}"

# 启动 bash 终端
CMD ["sleep", "infinity"]
FROM golang:1.17-alpine as builder
WORKDIR /app
ARG VERSION
ENV GOPROXY=https://goproxy.cn
COPY ../go.mod ./
COPY ../go.sum ./
#RUN go mod download
COPY .. .
RUN CGO_ENABLED=0 go build -ldflags "-s -w -X 'main.version=${VERSION}'" -o pixiu ./cmd

FROM node:16.18.0-alpine as dashboard-builder
WORKDIR /build
RUN apk add git
RUN git clone https://github.com/pixiu-io/dashboard.git
RUN cd dashboard && npm install && npm run build

FROM busybox as runner
LABEL MAINTAINER="PIXIU"

COPY --from=builder /app/pixiu /app
COPY --from=dashboard-builder /build/dashboard/dist /static
COPY docker/start.sh /usr/local/bin/pixiu_start

CMD ["pixiu_start"]
40 changes: 40 additions & 0 deletions docker/Dockerfile-toolbox
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# 使用 Ubuntu 作为基础镜像
FROM ubuntu:22.04

ARG K8S_VERSION
ARG HELM_VERSION

# 安装vim
RUN apt-get update && apt-get install -y vim

# 安装必要的软件包
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y curl bash-completion

# 安装 kubectl
RUN ARCH=$(uname -m|sed 's|x86_64|amd64|'|sed 's|aarch64|arm64|') && \
curl -LO "https://dl.k8s.io/release/${K8S_VERSION}/bin/linux/${ARCH}/kubectl" && \
install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl && \
rm -rf kubectl

# 安装 helm
RUN ARCH=$(uname -m|sed 's|x86_64|amd64|'|sed 's|aarch64|arm64|') && \
curl -LO "https://get.helm.sh/helm-${HELM_VERSION}-linux-${ARCH}.tar.gz" && \
tar -zxvf helm-${HELM_VERSION}-linux-${ARCH}.tar.gz && \
rm -rf helm-${HELM_VERSION}-linux-${ARCH}.tar.gz && \
mv linux-${ARCH}/helm /usr/local/bin/helm && \
rm -rf linux-${ARCH}

# 配置 bash 补全和自定义的 PS1 提示符
RUN echo 'source /etc/profile.d/bash_completion.sh' >> /root/.bashrc \
&& echo 'source <(kubectl completion bash)' >> /root/.bashrc \
&& echo 'source <(helm completion bash)' >> /root/.bashrc \
&& echo "PS1='[\[\033[0;34m\]\u\[\033[0;37m\]@\[\033[0;35m\]\h\[\033[0;33m\] \w\[\033[0;37m\]]\[\033[0;31m\]\$\[\033[00m\] '" >> /root/.bashrc

# 设置工作目录
WORKDIR /root

# 设置环境变量等(可选)
ENV PATH="/usr/local/bin:${PATH}"

# 启动 bash 终端
CMD ["sleep", "infinity"]
16 changes: 16 additions & 0 deletions docker/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/sh
set -o errexit
set -o xtrace

if [[ ! -d "/etc/pixiu" ]]; then
mkdir -p /etc/pixiu
fi

if [[ -e "/static/config.json" ]]; then
rm -rf /static/config.json
fi
if [[ -e "/etc/pixiu/config.json" ]]; then
cp /etc/pixiu/config.json /static/config.json
fi

/app

0 comments on commit 6dd3834

Please sign in to comment.