-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit a85492e
Showing
10 changed files
with
562 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
name: Build and Push Docker Image | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
build-and-push: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Check Out Repo | ||
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 DockerHub | ||
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: | ||
push: true | ||
tags: yanhao98/frp-http-server:latest | ||
platforms: linux/amd64,linux/arm64 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
FROM --platform=$BUILDPLATFORM fatedier/frps:v0.53.2 as origin-frps | ||
|
||
FROM nginx:1 | ||
COPY --from=origin-frps /usr/bin/frps /usr/bin/frps | ||
|
||
COPY ./src/nginx/templates /etc/nginx/templates | ||
COPY ./src/html /usr/share/nginx/html | ||
|
||
COPY ./src/dl-frpc.sh /dl-frpc.sh | ||
|
||
RUN set -xe \ | ||
&& mv /docker-entrypoint.sh /docker-entrypoint-nginx.sh \ | ||
&& apt-get update \ | ||
&& apt-get install --no-install-recommends --no-install-suggests -y unzip zip wget \ | ||
&& bash /dl-frpc.sh && rm /dl-frpc.sh \ | ||
&& apt-get remove --purge --auto-remove -y unzip zip wget && rm -rf /var/lib/apt/lists/* && apt-get purge -y --auto-remove | ||
|
||
COPY ./src/nginx/templates /etc/nginx/templates | ||
COPY ./src/entry.sh /entry.sh | ||
# STOPSIGNAL SIGINT | ||
ENTRYPOINT ["/entry.sh"] | ||
EXPOSE 80 7000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# frp-http | ||
|
||
## Server | ||
```bash | ||
docker run -it --rm --name frp-http-server \ | ||
-e FRP_SUBDOMAIN_HOST=domain.com \ | ||
-p 80:80 \ | ||
-p 7000:7000 \ | ||
yanhao98/frp-http-server | ||
``` | ||
|
||
### Update | ||
```bash | ||
docker run --rm \ | ||
-v /var/run/docker.sock:/var/run/docker.sock \ | ||
containrrr/watchtower \ | ||
--cleanup --run-once \ | ||
frp-http-server | ||
``` | ||
|
||
<!-- ## Client | ||
### Mac | ||
```bash | ||
bash <(curl -s domain.com/client.sh) --local=127.0.0.1:80 | ||
``` --> | ||
|
||
## Reference | ||
- [Dockerfile for ngx](https://github.com/nginxinc/docker-nginx/blob/master/mainline/alpine-slim/Dockerfile) | ||
- [Dockerfile-for-frps](https://github.com/fatedier/frp/blob/dev/dockerfiles/Dockerfile-for-frps) | ||
- [Multi-arch frps's docker image](https://github.com/cloverzrg/frps-docker/blob/master/Dockerfile) | ||
- https://github.com/snowdreamtech/frp/blob/master/frps/amd64/Dockerfile | ||
- [VBScript](https://www.w3school.com.cn/vbscript/index.asp) | ||
- https://stackoverflow.com/questions/4888197/how-To-show-dos-output-when-using-vbscript-exec/4888791#4888791 | ||
|
||
``` | ||
rm /var/log/nginx/access.log /var/log/nginx/error.log | ||
https://github.com/nginxinc/docker-nginx/blob/4bf0763f4977fff7e9648add59e0540088f3ca9f/mainline/debian/Dockerfile#L102 | ||
the nginx log is already redirected to stdout/stderr by default (see Dockerfile#L102) | ||
if we delete the log file, nginx will create a new one, but the new one is not redirected to stdout/stderr | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
version: '3' | ||
services: | ||
frp-http-server: | ||
build: . | ||
environment: | ||
- FRP_SUBDOMAIN_HOST=yhfrp.tk | ||
# volumes: | ||
# - ./src/html/client.sh:/usr/share/nginx/html/client.sh | ||
ports: | ||
- "80:80" | ||
- "7000:7000" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!/bin/bash | ||
# | ||
# Description: 只保留frpc | ||
# | ||
set -e | ||
|
||
cd /usr/share/nginx/html | ||
|
||
FRPS_VER=$(frps -v) | ||
|
||
declare -a URLS | ||
URLS[0]="https://github.com/fatedier/frp/releases/download/v${FRPS_VER}/frp_${FRPS_VER}_darwin_arm64.tar.gz" | ||
URLS[1]="https://github.com/fatedier/frp/releases/download/v${FRPS_VER}/frp_${FRPS_VER}_darwin_amd64.tar.gz" | ||
URLS[2]="https://github.com/fatedier/frp/releases/download/v${FRPS_VER}/frp_${FRPS_VER}_windows_amd64.zip" | ||
URLS[3]="https://github.com/fatedier/frp/releases/download/v${FRPS_VER}/frp_${FRPS_VER}_windows_arm64.zip" | ||
|
||
mkdir ./temp | ||
cd ./temp | ||
|
||
declare -a FILENAMES | ||
declare -a OUTPUTS_FILENAMES | ||
for i in "${!URLS[@]}"; do | ||
echo "----------------------------------------" | ||
FILENAMES[i]=$(basename "${URLS[$i]}") # >>> frp_0.0.0_darwin_arm64.tar.gz | ||
OUTPUTS_FILENAMES[i]=${FILENAMES[$i]//frp/frpc} # >>> frpc_0.0.0_darwin_arm64.tar.gz | ||
echo "Downloading ${FILENAMES[$i]} ..." | ||
wget --quiet "${URLS[$i]}" | ||
|
||
echo "Packing frpc ..." | ||
if [[ "${FILENAMES[$i]}" =~ \.zip$ ]]; then | ||
unzip -q "./${FILENAMES[$i]}" | ||
zip -q -j "./${OUTPUTS_FILENAMES[$i]}" "./${FILENAMES[$i]//.zip/}/frpc.exe" | ||
rm -rf "./${FILENAMES[$i]//.zip/}" | ||
else | ||
# [tar命令详解](https://www.cnblogs.com/duanweishi/p/16899404.html) | ||
tar -xzf "./${FILENAMES[$i]}" | ||
tar -czf "./${OUTPUTS_FILENAMES[$i]}" -C "./${FILENAMES[$i]//.tar.gz/}" frpc | ||
rm -rf "./${FILENAMES[$i]//.tar.gz/}" | ||
fi | ||
rm -rf "./${FILENAMES[$i]}" | ||
|
||
done | ||
|
||
cd .. | ||
|
||
mv ./temp ./download | ||
|
||
echo "Done." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
print_title() { | ||
local title="$1" # 将传入的参数赋值给 title 变量 | ||
|
||
# ANSI 颜色代码 | ||
local red='\033[0;31m' # 红色 | ||
local no_color='\033[0m' # 无颜色(用于重置颜色) | ||
|
||
# 打印彩色标题 | ||
echo -e "${red}${title}${no_color}" | ||
} | ||
|
||
if [ -z "${FRP_SUBDOMAIN_HOST}" ] || [ "${FRP_SUBDOMAIN_HOST}" = "domain.com" ]; then | ||
echo "FRP_SUBDOMAIN_HOST is not set" | ||
exit 1 | ||
fi | ||
|
||
FRPS_VER=$(frps -v) | ||
SERVER_IP=$(curl -fsSL ip.sb) | ||
|
||
print_title "confirm environment variables" | ||
printf "FRP_SUBDOMAIN_HOST: %s\n" "${FRP_SUBDOMAIN_HOST}" | ||
printf "SERVER_IP: %s\n" "${SERVER_IP}" | ||
printf "FRPS_VER: %s\n" "${FRPS_VER}" | ||
|
||
sed -i "s/REPLACE_MAIN_DOMAIN/${FRP_SUBDOMAIN_HOST}/g" /usr/share/nginx/html/client.sh | ||
sed -i "s/REPLACE_SERVER_IP/${SERVER_IP}/g" /usr/share/nginx/html/client.sh | ||
sed -i "s/REPLACE_VERSION/${FRPS_VER}/g" /usr/share/nginx/html/client.sh | ||
sed -i "s/REPLACE_MAIN_DOMAIN/${FRP_SUBDOMAIN_HOST}/g" /usr/share/nginx/html/client.vbs | ||
sed -i "s/REPLACE_SERVER_IP/${SERVER_IP}/g" /usr/share/nginx/html/client.vbs | ||
sed -i "s/REPLACE_VERSION/${FRPS_VER}/g" /usr/share/nginx/html/client.vbs | ||
|
||
print_title "the download folder" | ||
ls -l /usr/share/nginx/html/download | ||
|
||
print_title "start nginx" | ||
/docker-entrypoint-nginx.sh nginx -g "daemon on;" | ||
|
||
sleep 0.1 | ||
print_title "start frps" | ||
exec frps \ | ||
--bind_port="7000" \ | ||
--subdomain_host="${FRP_SUBDOMAIN_HOST}" \ | ||
--vhost_http_port="7080" \ | ||
--dashboard_port="7500" \ | ||
--dashboard_user="" \ | ||
--dashboard_pwd="" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
MAIN_DOMAIN="REPLACE_MAIN_DOMAIN" | ||
SERVER_IP="REPLACE_SERVER_IP" | ||
version='REPLACE_VERSION' | ||
|
||
# Get options | ||
for i in "$@"; do | ||
case $i in | ||
--local=*) | ||
LOCAL="${i#*=}" | ||
;; | ||
-sd=* | --subdomain=*) | ||
SUBDOMAIN="${i#*=}" | ||
;; | ||
*) | ||
# unknown option | ||
echo "Unknown option: $i" | ||
;; | ||
esac | ||
done | ||
|
||
USERNAME=$(whoami) | ||
|
||
# Check options | ||
if [[ -z "$LOCAL" ]]; then | ||
echo "Missing required option: --local." | ||
exit 1 | ||
fi | ||
|
||
# Split local | ||
IFS=':' read -r -a LOCAL_ARRAY <<<"$LOCAL" | ||
LOCAL_IP=${LOCAL_ARRAY[0]} | ||
LOCAL_PORT=${LOCAL_ARRAY[1]} | ||
|
||
if [[ -z "$SUBDOMAIN" ]]; then | ||
UUID="$(system_profiler SPHardwareDataType | awk '/UUID/ { print $3; }')" | ||
UUID=$(echo "$UUID" | tr '[:upper:]' '[:lower:]') | ||
SUBDOMAIN="${UUID}-${LOCAL_PORT}" | ||
fi | ||
|
||
# ############################### Ready to run ############################### | ||
# https://www.ruanyifeng.com/blog/2019/12/mktemp.html | ||
TEMP_DIR=$(mktemp -d) || exit 1 | ||
declare -r TEMP_DIR | ||
echo "Working in $TEMP_DIR" | ||
cleanup() { | ||
echo "" | ||
echo "Cleaning up..." | ||
local target="$1" | ||
rm -vr "$target" | ||
} | ||
trap 'cleanup "$TEMP_DIR"' EXIT | ||
|
||
|
||
download_frpc() { | ||
local os=$(echo "$(uname -s)" | sed 's/Darwin/darwin/g') # Darwin => darwin | ||
local arch=$(echo "$(uname -m)" | sed 's/x86_64/amd64/g') # x86_64 => amd64 | ||
local filename="frpc_${version}_${os}_${arch}.tar.gz" | ||
local url="${MAIN_DOMAIN}/download/${filename}" | ||
cd "$TEMP_DIR" || exit 1 | ||
echo "Downloading $filename from $url..." | ||
curl -s -L "$url" -o "./$filename" | ||
echo "Unpacking $filename..." | ||
tar -xzf "./$filename" | ||
} | ||
download_frpc | ||
|
||
echo "Running frpc v$(./frpc -v)..." | ||
|
||
for i in {1..3}; do echo -ne "\033[1A\033[K"; done | ||
|
||
# ############################################################################## | ||
url="https://$SUBDOMAIN.$MAIN_DOMAIN" | ||
spaces_needed=$((69 - ${#url})) | ||
padding=$(printf '%*s' $spaces_needed) | ||
|
||
cat <<"EOF" | sed "s|URL|$url$padding|g" | ||
___________________________________________________________________________ | ||
/ _ _ \ | ||
|| | | (_) || | ||
|| | |_ _ __ _ ___ _ __ || | ||
|| | __| |/ _` |/ _ \ '__| || | ||
|| | |_| | (_| | __/ | || | ||
|| \__|_|\__, |\___|_|. || | ||
|| __/ | || | ||
|| |___/ || | ||
||___________________________________________________________________________|| | ||
|| || | ||
|| You can access your service through the following address: || | ||
|| URL|| | ||
|| || | ||
|| to stop frpc, please press ^C. || | ||
|| || | ||
|| Enjoy! || | ||
\___________________________________________________________________________/ | ||
EOF | ||
|
||
|
||
|
||
./frpc http \ | ||
--server_addr=${SERVER_IP} \ | ||
--server_port=7000 \ | ||
--local_ip="${LOCAL_IP}" \ | ||
--local_port="${LOCAL_PORT}" \ | ||
--sd="${SUBDOMAIN}" \ | ||
--proxy_name="${USERNAME}|${LOCAL}|${SUBDOMAIN}" |
Oops, something went wrong.