Skip to content

Commit

Permalink
update action 修改
Browse files Browse the repository at this point in the history
  • Loading branch information
qist committed Jun 24, 2024
1 parent ad07a19 commit 6637985
Show file tree
Hide file tree
Showing 5 changed files with 191 additions and 91 deletions.
78 changes: 44 additions & 34 deletions .github/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,42 +1,52 @@
FROM --platform=$BUILDPLATFORM golang:bullseye AS build
# ========================================================
# Stage: Builder
# ========================================================
FROM golang:bullseye AS build
WORKDIR /app
ARG TARGETARCH

RUN apt update && apt install -y gcc-aarch64-linux-gnu
ARG TARGETOS TARGETARCH
RUN apk --no-cache --update add \
build-base \
gcc \
wget \
unzip

RUN echo "I'm building for $BUILDPLATFORM"
COPY . .
COPY .github/docker/files/DockerInit.sh /app/DockerInit.sh
ENV CGO_ENABLED=1
ENV CGO_CFLAGS="-D_LARGEFILE64_SOURCE"
RUN go build -o build/xray-ui main.go
RUN ./DockerInit.sh "$TARGETARCH"

# ========================================================
# Stage: Final Image of xray-ui
# ========================================================
FROM alpine
ENV TZ=Asia/Shanghai
WORKDIR /app

WORKDIR /src
RUN apk add --no-cache --update \
ca-certificates \
tzdata \
fail2ban \
bash

COPY . .
COPY --from=builder /app/build/ /app/
COPY --from=builder /app/xray-ui.sh /usr/bin/xray-ui

COPY .github/docker/files/cc-name.sh /tmp/cc-name.sh

RUN FILE_NAME=`bash /tmp/cc-name.sh` && echo $FILE_NAME && GOOS=$TARGETOS GOARCH=$TARGETARCH CGO_ENABLED=1 CC="$FILE_NAME" go build -o xray-ui -trimpath -ldflags '-s -w -buildid= -linkmode "external" -extldflags "-static"' main.go

FROM --platform=${TARGETPLATFORM} alpine:latest
# Configure fail2ban
RUN rm -f /etc/fail2ban/jail.d/alpine-ssh.conf \
&& cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local \
&& sed -i "s/^\[ssh\]$/&\nenabled = false/" /etc/fail2ban/jail.local \
&& sed -i "s/^\[sshd\]$/&\nenabled = false/" /etc/fail2ban/jail.local \
&& sed -i "s/#allowipv6 = auto/allowipv6 = auto/g" /etc/fail2ban/fail2ban.conf

ARG TARGETARCH
RUN chmod +x \
/app/DockerEntrypoint.sh \
/app/x-ui \
/usr/bin/x-ui

WORKDIR /root

COPY --from=build /src/xray-ui /root/xray-ui
COPY .github/docker/files/file-name.sh /tmp/file-name.sh

RUN set -ex \
&& FILE_NAME=`sh /tmp/file-name.sh` && echo $FILE_NAME \
&& apk add --no-cache tzdata ca-certificates bash \
&& mkdir -p /root/bin \
&& chmod +x /root/xray-ui \
&& cd /root/bin \
&& wget https://github.com/XTLS/Xray-core/releases/latest/download/Xray-linux-${FILE_NAME}.zip \
&& unzip Xray-linux-${FILE_NAME}.zip \
&& rm -f Xray-linux-${FILE_NAME}.zip geoip.dat geosite.dat \
&& mv xray xray-linux-${TARGETARCH} \
&& rm -f /tmp/file-name.sh \
&& wget -O /root/bin/geosite.dat https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geosite.dat \
&& wget -O /root/bin/geoip.dat https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geoip.dat


VOLUME /etc/xray-ui
ENV TZ=Asia/Shanghai
CMD [ "./xray-ui" ]
VOLUME [ "/etc/xray-ui" ]
CMD [ "./xray-ui" ]
ENTRYPOINT [ "/app/DockerEntrypoint.sh" ]
36 changes: 36 additions & 0 deletions .github/docker/files/DockerInit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/sh
case $1 in
amd64)
ARCH="64"
FNAME="amd64"
;;
i386)
ARCH="32"
FNAME="i386"
;;
armv8 | arm64 | aarch64)
ARCH="arm64-v8a"
FNAME="arm64"
;;
armv7 | arm | arm32)
ARCH="arm32-v7a"
FNAME="arm32"
;;
armv6)
ARCH="arm32-v6"
FNAME="armv6"
;;
*)
ARCH="64"
FNAME="amd64"
;;
esac
mkdir -p build/bin
cd build/bin
wget "https://github.com/XTLS/Xray-core/releases/latest/download/Xray-linux-${ARCH}.zip"
unzip "Xray-linux-${ARCH}.zip"
rm -f "Xray-linux-${ARCH}.zip" geoip.dat geosite.dat
mv xray "xray-linux-${FNAME}"
wget https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geoip.dat
wget https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geosite.dat
cd ../../
2 changes: 1 addition & 1 deletion .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/arm64,linux/amd64
platforms: linux/amd64, linux/arm64/v8, linux/arm/v7, linux/arm/v6, linux/386
file: .github/docker/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
Expand Down
159 changes: 103 additions & 56 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,87 +1,134 @@
name: Release xray-ui

on:
push:
tags:
- "*"
workflow_dispatch:

jobs:
linuxamd64build:
name: build xray-ui amd64 version
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/[email protected]
with:
go-version: "stable"
- name: build linux amd64 version
run: |
CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -o xray-release -trimpath -ldflags '-s -w -buildid= -linkmode "external" -extldflags "-static"' main.go
mkdir xray-ui
cp xray-release xray-ui/xray-release
cp xray-ui.service xray-ui/xray-ui.service
cd xray-ui
mv xray-release xray-ui
mkdir bin
cd bin
wget https://github.com/XTLS/Xray-core/releases/latest/download/Xray-linux-64.zip
unzip Xray-linux-64.zip
rm -f Xray-linux-64.zip geoip.dat geosite.dat
wget https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geoip.dat
wget https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geosite.dat
mv xray xray-linux-amd64
cd ..
cd ..
- name: package
run: tar -zcvf xray-ui-linux-amd64.tar.gz xray-ui
- name: upload
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ github.ref }}
file: xray-ui-linux-amd64.tar.gz
asset_name: xray-ui-linux-amd64.tar.gz
prerelease: true
overwrite: true
linuxarm64build:
name: build xray-ui arm64 version
build:
strategy:
matrix:
platform:
- amd64
- arm64
- armv7
- armv6
- 386
- armv5
- s390x
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v4
- name: Set up Go
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup Go
uses: actions/[email protected]
with:
go-version: "stable"
- name: build linux arm64 version

- name: Install dependencies
run: |
sudo apt-get update
sudo apt install gcc-aarch64-linux-gnu
CGO_ENABLED=1 GOOS=linux GOARCH=arm64 CC=aarch64-linux-gnu-gcc go build -o xray-release -trimpath -ldflags '-s -w -buildid= -linkmode "external" -extldflags "-static"' main.go
if [ "${{ matrix.platform }}" == "arm64" ]; then
sudo apt install gcc-aarch64-linux-gnu
elif [ "${{ matrix.platform }}" == "armv7" ]; then
sudo apt install gcc-arm-linux-gnueabihf
elif [ "${{ matrix.platform }}" == "armv6" ]; then
sudo apt install gcc-arm-linux-gnueabihf
elif [ "${{ matrix.platform }}" == "386" ]; then
sudo apt install gcc-i686-linux-gnu
elif [ "${{ matrix.platform }}" == "armv5" ]; then
sudo apt install gcc-arm-linux-gnueabi
elif [ "${{ matrix.platform }}" == "s390x" ]; then
sudo apt install gcc-s390x-linux-gnu
fi
- name: Build xray-ui
run: |
export CGO_ENABLED=1
export GOOS=linux
export GOARCH=${{ matrix.platform }}
if [ "${{ matrix.platform }}" == "arm64" ]; then
export GOARCH=arm64
export CC=aarch64-linux-gnu-gcc
elif [ "${{ matrix.platform }}" == "armv7" ]; then
export GOARCH=arm
export GOARM=7
export CC=arm-linux-gnueabihf-gcc
elif [ "${{ matrix.platform }}" == "armv6" ]; then
export GOARCH=arm
export GOARM=6
export CC=arm-linux-gnueabihf-gcc
elif [ "${{ matrix.platform }}" == "386" ]; then
export GOARCH=386
export CC=i686-linux-gnu-gcc
elif [ "${{ matrix.platform }}" == "armv5" ]; then
export GOARCH=arm
export GOARM=5
export CC=arm-linux-gnueabi-gcc
elif [ "${{ matrix.platform }}" == "s390x" ]; then
export GOARCH=s390x
export CC=s390x-linux-gnu-gcc
fi
go build -o xui-release -trimpath -ldflags '-s -w -buildid= -linkmode "external" -extldflags "-static"' main.go
mkdir xray-ui
cp xray-release xray-ui/xray-release
cp xray-ui.service xray-ui/xray-ui.service
cd xray-ui
mv xray-release xray-ui
mkdir bin
cd bin
wget https://github.com/XTLS/Xray-core/releases/latest/download/Xray-linux-arm64-v8a.zip
unzip Xray-linux-arm64-v8a.zip
rm -f Xray-linux-arm64-v8a.zip geoip.dat geosite.dat
# Download dependencies
Xray_URL="https://github.com/XTLS/Xray-core/releases/latest/download/"
if [ "${{ matrix.platform }}" == "amd64" ]; then
wget ${Xray_URL}Xray-linux-64.zip
unzip Xray-linux-64.zip
rm -f Xray-linux-64.zip
elif [ "${{ matrix.platform }}" == "arm64" ]; then
wget ${Xray_URL}Xray-linux-arm64-v8a.zip
unzip Xray-linux-arm64-v8a.zip
rm -f Xray-linux-arm64-v8a.zip
elif [ "${{ matrix.platform }}" == "armv7" ]; then
wget ${Xray_URL}Xray-linux-arm32-v7a.zip
unzip Xray-linux-arm32-v7a.zip
rm -f Xray-linux-arm32-v7a.zip
elif [ "${{ matrix.platform }}" == "armv6" ]; then
wget ${Xray_URL}Xray-linux-arm32-v6.zip
unzip Xray-linux-arm32-v6.zip
rm -f Xray-linux-arm32-v6.zip
elif [ "${{ matrix.platform }}" == "386" ]; then
wget ${Xray_URL}Xray-linux-32.zip
unzip Xray-linux-32.zip
rm -f Xray-linux-32.zip
elif [ "${{ matrix.platform }}" == "armv5" ]; then
wget ${Xray_URL}Xray-linux-arm32-v5.zip
unzip Xray-linux-arm32-v5.zip
rm -f Xray-linux-arm32-v5.zip
elif [ "${{ matrix.platform }}" == "s390x" ]; then
wget ${Xray_URL}Xray-linux-s390x.zip
unzip Xray-linux-s390x.zip
rm -f Xray-linux-s390x.zip
fi
rm -f geoip.dat geosite.dat
wget https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geoip.dat
wget https://github.com/Loyalsoldier/v2ray-rules-dat/releases/latest/download/geosite.dat
mv xray xray-linux-arm64
cd ..
cd ..
- name: package
run: tar -zcvf xray-ui-linux-arm64.tar.gz xray-ui
- name: upload
mv xray xray-linux-${{ matrix.platform }}
cd ../..
- name: Package
run: tar -zcvf xray-ui-linux-${{ matrix.platform }}.tar.gz xray-ui

- name: Upload files to GH release
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ github.ref }}
file: xray-ui-linux-arm64.tar.gz
asset_name: xray-ui-linux-arm64.tar.gz
file: xray-ui-linux-${{ matrix.platform }}.tar.gz
asset_name: xray-ui-linux-${{ matrix.platform }}.tar.gz
prerelease: true
overwrite: true
- name: Release Changelog Builder
Expand Down
7 changes: 7 additions & 0 deletions DockerEntrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh

# Start fail2ban
fail2ban-client -x start

# Run xray-ui
exec /app/xray-ui

0 comments on commit 6637985

Please sign in to comment.