Skip to content

Commit

Permalink
Merge pull request #160 from aipeach/patch-3
Browse files Browse the repository at this point in the history
增加纯后端镜像
  • Loading branch information
AirportR authored Feb 6, 2024
2 parents e07b20d + 533fa5f commit 4b4c91a
Show file tree
Hide file tree
Showing 12 changed files with 154 additions and 48 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/docker-backend-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: docker-backend-image

on:
push:
branches:
- "backend"

jobs:
docker:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
file: ./docker/Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: |
${{ secrets.DOCKERHUB_USERNAME }}/fulltclash:ws
build-args: |
GIT_Branch=${{ github.ref_name }}
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,19 @@ options:

```shell
python3 main.py -t fulltclash -b 0.0.0.0:8765
```
```

### Docker启动
> Docker镜像是基于alpine构建的
```bash
docker run -idt \
--name fulltclash-ws \
-e branch=origin \
-e core=4 \
-e token=114514 \
-e buildtoken=BUILDTOKEN \
-p 8765:8765 \
--restart always \
airportr/fulltclash:ws
```
1 change: 1 addition & 0 deletions bin/.gitkeep
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/
Binary file removed bin/fulltclash-linux-amd64
Binary file not shown.
Binary file removed bin/fulltclash-macos-amd64
Binary file not shown.
Binary file removed bin/fulltclash-windows-amd64.exe
Binary file not shown.
58 changes: 23 additions & 35 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,56 +1,44 @@
FROM golang:1.20.7-bookworm AS build-core
FROM python:3.11.7-alpine3.19 AS compile-image

WORKDIR /app/fulltclash-origin
RUN apt-get update && \
apt-get install --no-install-recommends -y \
git && \
git clone https://github.com/AirportR/FullTCore.git /app/fulltclash-origin && \
go build -ldflags="-s -w" fulltclash.go

WORKDIR /app/fulltclash-meta
RUN git clone -b meta https://github.com/AirportR/FullTCore.git /app/fulltclash-meta && \
go build -tags with_gvisor -ldflags="-s -w" fulltclash.go && \
mkdir /app/FullTCore-file && \
cp /app/fulltclash-origin/fulltclash /app/FullTCore-file/fulltclash-origin && \
cp /app/fulltclash-meta/fulltclash /app/FullTCore-file/fulltclash-meta

FROM python:3.9.18-slim-bookworm AS compile-image

RUN apt-get update && \
apt-get install --no-install-recommends -y \
gcc g++ make ca-certificates
RUN apk add --no-cache \
gcc g++ make libffi-dev libstdc++ gcompat libgcc build-base py3-pybind11-dev abseil-cpp-dev re2-dev ca-certificates

RUN python -m venv /opt/venv

ENV PATH="/opt/venv/bin:$PATH"
ADD https://raw.githubusercontent.com/AirportR/FullTclash/dev/requirements.txt .
ADD https://raw.githubusercontent.com/AirportR/FullTclash/backend/requirements.txt .
RUN pip3 install --no-cache-dir -r requirements.txt && \
pip3 install --no-cache-dir supervisor

FROM python:3.9.18-slim-bookworm
FROM python:3.11.7-alpine3.19

ARG GIT_Branch
ENV GIT_Branch=$GIT_Branch
ENV TZ=Asia/Shanghai
ENV bind=0.0.0.0:8765
ENV token=fulltclash
ENV branch=origin
ENV core=4

WORKDIR /app

RUN apt-get update && \
apt-get install --no-install-recommends -y \
git tzdata curl jq bash nano cron && \
git clone -b dev --single-branch --depth=1 https://github.com/AirportR/FullTclash.git /app && \
cp resources/config.yaml.example resources/config.yaml && \
rm -f /etc/localtime && \
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
echo "Asia/Shanghai" > /etc/timezone && \
RUN apk add --no-cache \
git tzdata curl jq wget bash nano && \
git clone -b $GIT_Branch --single-branch --depth=1 https://github.com/AirportR/FullTclash.git /app && \
ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && \
echo $TZ > /etc/timezone && \
echo "00 6 * * * bash /app/docker/update.sh" >> /var/spool/cron/crontabs/root && \
mkdir /etc/supervisord.d && \
mv /app/docker/supervisord.conf /etc/supervisord.conf && \
mv /app/docker/fulltclash.conf /etc/supervisord.d/fulltclash.conf && \
chmod +x /app/docker/docker-entrypoint.sh && \
rm -rf /var/lib/apt/lists/* && \
rm -f /app/bin/*
chmod +x /app/docker/fulltcore.sh && \
bash /app/docker/fulltcore.sh && \
chmod +x /app/docker/update.sh && \
chmod +x /app/docker/docker-entrypoint.sh

COPY --from=compile-image /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=compile-image /opt/venv /opt/venv
COPY --from=build-core /app/FullTCore-file/* ./bin/

ENV PATH="/opt/venv/bin:$PATH"

ENTRYPOINT ["/app/docker/docker-entrypoint.sh"]
ENTRYPOINT ["/app/docker/docker-entrypoint.sh"]
19 changes: 18 additions & 1 deletion docker/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
#!/bin/bash

if [[ ! -f /app/resources/config.yaml ]]; then
cat > /app/resources/config.yaml <<EOF
clash:
path: './bin/fulltclash-${branch}'
core: ${core}
startup: 1124
branch: ${branch}
websocket:
bindAddress: "${bind}"
token: "${token}"
EOF
fi

if [ ! -z "${buildtoken}" ]; then
echo "buildtoken: ${buildtoken}" >> /app/resources/config.yaml
fi

supervisord -c /etc/supervisord.conf

cron -f > /dev/null 2>&1
crond -f > /dev/null 2>&1
3 changes: 2 additions & 1 deletion docker/fulltclash.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[program:fulltclash]
command=python3 /app/main.py
command=python3 -u /app/main.py
directory=/app
redirect_stderr=true
stdout_logfile=/var/log/fulltclash.log
33 changes: 33 additions & 0 deletions docker/fulltcore.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash

rm -f /app/bin/*

ORIGIN_AMD64_URL=https://github.com/AirportR/FullTCore/releases/download/v1.0/FullTCore_1.0_linux_amd64.tar.gz
META_AMD64_URL=https://github.com/AirportR/FullTCore/releases/download/v1.1-meta/FullTCore_1.1-meta_linux_amd64.tar.gz
ORIGIN_ARM64_URL=https://github.com/AirportR/FullTCore/releases/download/v1.0/FullTCore_1.0_linux_arm64.tar.gz
META_ARM64_URL=https://github.com/AirportR/FullTCore/releases/download/v1.1-meta/FullTCore_1.1-meta_linux_arm64.tar.gz

arch=$(arch)

if [[ $arch == "x86_64" || $arch == "x64" || $arch == "amd64" ]]; then
arch="amd64"
wget -O /app/bin/FullTCore_origin.tar.gz ${ORIGIN_AMD64_URL} > /dev/null 2>&1
wget -O /app/bin/FullTCore_meta.tar.gz ${META_AMD64_URL} > /dev/null 2>&1
elif [[ $arch == "aarch64" || $arch == "arm64" ]]; then
arch="arm64"
wget -O /app/bin/FullTCore_origin.tar.gz ${ORIGIN_ARM64_URL} > /dev/null 2>&1
wget -O /app/bin/FullTCore_meta.tar.gz ${META_ARM64_URL} > /dev/null 2>&1
fi

tar -C /app/bin/ -xvzf /app/bin/FullTCore_origin.tar.gz
mv /app/bin/FullTCore /app/bin/fulltclash-origin

tar -C /app/bin/ -xvzf /app/bin/FullTCore_meta.tar.gz
mv /app/bin/FullTCore /app/bin/fulltclash-meta

find /app/bin/* | egrep -v "fulltclash-origin|fulltclash-meta" | xargs rm -f

chmod +x /app/bin/fulltclash-origin
chmod +x /app/bin/fulltclash-meta

echo "架构: ${arch}下载FullTCore完成"
36 changes: 27 additions & 9 deletions docker/update.sh
Original file line number Diff line number Diff line change
@@ -1,20 +1,38 @@
#!/bin/bash
. /etc/profile

git_version=$(git rev-parse HEAD)
last_version=$(curl -Ls "https://api.github.com/repos/AirportR/FullTclash/commits/dev" | jq .sha | sed -E 's/.*"([^"]+)".*/\1/')
git_branch=$(git --git-dir='/app/.git' --work-tree='/app' rev-parse --abbrev-ref HEAD)
git_version=$(git --git-dir='/app/.git' --work-tree='/app' rev-parse HEAD)

if [[ master == "$git_branch" ]]; then
echo -e "当前分支为 $git_branch"
echo -e "当前commits位于 $git_version"
last_version=$(curl -Ls "https://api.github.com/repos/AirportR/FullTclash/commits/master" | jq .sha | sed -E 's/.*"([^"]+)".*/\1/')
elif [[ dev == "$git_branch" ]]; then
echo -e "当前分支为 $git_branch"
echo -e "当前commits位于 $git_version"
last_version=$(curl -Ls "https://api.github.com/repos/AirportR/FullTclash/commits/dev" | jq .sha | sed -E 's/.*"([^"]+)".*/\1/')
elif [[ backend == "$git_branch" ]]; then
echo -e "当前分支为 $git_branch"
echo -e "当前commits位于 $git_version"
last_version=$(curl -Ls "https://api.github.com/repos/AirportR/FullTclash/commits/backend" | jq .sha | sed -E 's/.*"([^"]+)".*/\1/')
else
echo -e "暂不支持此分支"
exit 1
fi

update() {
git fetch --all
git reset --hard origin/dev
git pull
git --git-dir='/app/.git' --work-tree='/app' fetch --all
git --git-dir='/app/.git' --work-tree='/app' reset --hard origin/$git_branch
git --git-dir='/app/.git' --work-tree='/app' pull
git_version=$(git --git-dir='/app/.git' --work-tree='/app' rev-parse HEAD)
}

cd /app

if [[ $last_version == $git_version ]]; then
if [[ $last_version == "$git_version" ]]; then
echo -e "已是最新版本,无需更新"
else
echo -e "检查到新版本,正在更新"
update
supervisorctl restart fulltclash
echo -e "更新完成,当前commits位于 $git_version"
/opt/venv/bin/supervisorctl restart fulltclash
fi
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ geoip2==4.6.0
cryptography==40.0.2
PySocks==1.7.1
lxml==4.9.2
google-re2
google-re2==1.0

0 comments on commit 4b4c91a

Please sign in to comment.