diff --git a/docker/w9gitea/.env b/docker/w9gitea/.env index 45fdfae5..6ebbfe89 100644 --- a/docker/w9gitea/.env +++ b/docker/w9gitea/.env @@ -1,9 +1,7 @@ APP_NAME=gitea APP_VERSION=1.20.4 -# port, APP_PORT is need at leaset -APP_HTTP_PORT=3000 APP_NETWORK=websoft9 -APP_URL=gitea.example.com +APP_URL= INSTALL_LOCK=true DISABLE_SSH=true diff --git a/docker/w9gitea/Dockerfile b/docker/w9gitea/Dockerfile index 1f750a03..c2cff787 100644 --- a/docker/w9gitea/Dockerfile +++ b/docker/w9gitea/Dockerfile @@ -1,15 +1,12 @@ # step1: build hook-api exe FROM docker.io/library/golang:1.21-alpine3.18 as build-hook WORKDIR / -COPY hook.go / -RUN go build -o hook /hook.go + +# 定义构建参数 +ARG GITEA_VERSION=1.20.4 # step2: from gitea image clone library, copy hook, s6 run script ... -FROM gitea/gitea:1.20.4 -RUN cd / && git clone --depth=1 https://github.com/Websoft9/docker-library.git \ - && mv docker-library library -COPY --from=build-hook /hook /usr/local/bin/hook +FROM gitea/gitea:${GITEA_VERSION} COPY init.sh /usr/local/bin/init.sh -COPY ./hook /etc/s6/hook COPY ./init /etc/s6/init -RUN chmod -R 755 /etc/s6/hook /etc/s6/init /usr/local/bin/init.sh +RUN chmod -R 755 /etc/s6/init /usr/local/bin/init.sh diff --git a/docker/w9gitea/README.md b/docker/w9gitea/README.md index dedca70a..f626dca9 100644 --- a/docker/w9gitea/README.md +++ b/docker/w9gitea/README.md @@ -3,7 +3,7 @@ From official Gitea image, and: - Add docker-library to this image -- Complete install wizard automaticlly by enviroment INSTALL_LOC +- Complete install wizard automaticlly by enviroment INSTALL_LOCK - Create admin credential by admin cli - Disable user register - Disable Gravatar diff --git a/docker/w9gitea/docker-compose.yml b/docker/w9gitea/docker-compose.yml index 72ccd741..b192e7a4 100644 --- a/docker/w9gitea/docker-compose.yml +++ b/docker/w9gitea/docker-compose.yml @@ -18,8 +18,6 @@ services: - gitea:/data - /etc/timezone:/etc/timezone:ro - /etc/localtime:/etc/localtime:ro - ports: - - "$APP_HTTP_PORT:3000" networks: default: diff --git a/docker/w9gitea/hook.go b/docker/w9gitea/hook.go deleted file mode 100644 index 71103251..00000000 --- a/docker/w9gitea/hook.go +++ /dev/null @@ -1,26 +0,0 @@ -package main - -import ( - "fmt" - "log" - "net/http" - "net/http/httputil" -) - -func main() { - http.HandleFunc("/", handleRequest) - log.Fatal(http.ListenAndServe(":8080", nil)) -} - -func handleRequest(w http.ResponseWriter, r *http.Request) { - // 打印请求行和头部信息 - requestDump, err := httputil.DumpRequest(r, true) - if err != nil { - log.Println("Error dumping request:", err) - return - } - log.Println(string(requestDump)) - - log.Println("-----------------------接口被调用了一次!---------") - fmt.Fprintf(w, "--Hello, World!") -} \ No newline at end of file diff --git a/docker/w9gitea/hook/run b/docker/w9gitea/hook/run deleted file mode 100644 index 16a5125c..00000000 --- a/docker/w9gitea/hook/run +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash - -s6-svwait -u /etc/s6/gitea - -pushd /root >/dev/null -exec su-exec $USER /usr/local/bin/hook -popd diff --git a/docker/w9gitea/init.sh b/docker/w9gitea/init.sh index d3c4429c..c71133aa 100644 --- a/docker/w9gitea/init.sh +++ b/docker/w9gitea/init.sh @@ -1,43 +1,34 @@ #!/bin/bash -if [ -e "/credential" ]; then - echo "File /credential exists. Exiting script." +set -e + +cred_path="/var/websoft9/credential" +admin_username="websoft9" +admin_email="help@websoft9.com" + +if [ -e "$cred_path" ]; then + echo "File $cred_path exists. Exiting script." exit 1 fi -# Create admin credential by admin cli -su -c ' - gitea admin user create --admin --username websoft9 --random-password --email help@websoft9.com > /tmp/credential -' git +echo "create diretory" +mkdir -p "$(dirname "$cred_path")" -# Read credential from tmp + +# TODO IF admin is exists, echo it to cred_path + +echo "Create admin credential by admin cli" +su -c " + gitea admin user create --admin --username '$admin_username' --random-password --email '$admin_email' > /tmp/credential +" git + +echo "Read credential from tmp" username=$(grep -o "New user '[^']*" /tmp/credential | sed "s/New user '//") if [ -z "$username" ]; then username="websoft9" fi password=$(grep -o "generated random password is '[^']*" /tmp/credential | sed "s/generated random password is '//") -# Create template credential + +echo "Save to credential" json="{\"username\":\"$username\",\"password\":\"$password\"}" -# Save to json -filename="/credential" -echo "$json" > "$filename" - -# Config webhook url at Gitea admin - -# Gitea API URL -api_url="http://localhost:3000/api/v1" -hook_url="http://gitea:8080" - -# Param data -hook_data='{ - "type": "gitea", - "config": { - "url": "'"$hook_url"'", - "content_type": "json" - }, - "events": ["push"], - "active": true -}' - -# Create a hook -curl -s -u "$username:$password" -X POST -H "Content-Type: application/json" -d "$hook_data" "$api_url/user/hooks" \ No newline at end of file +echo "$json" > "$cred_path" diff --git a/docker/w9nginxproxymanager/docker-compose.yml b/docker/w9nginxproxymanager/docker-compose.yml index a3174b55..55705c5c 100644 --- a/docker/w9nginxproxymanager/docker-compose.yml +++ b/docker/w9nginxproxymanager/docker-compose.yml @@ -10,7 +10,6 @@ services: container_name: ${APP_NAME} ports: - "80:80" - - "${APP_HTTP_PORT}:81" - "443:443" volumes: - nginx_data:/data diff --git a/docker/w9portainer/docker-compose.yml b/docker/w9portainer/docker-compose.yml index a8797937..f66d4bd9 100644 --- a/docker/w9portainer/docker-compose.yml +++ b/docker/w9portainer/docker-compose.yml @@ -14,8 +14,6 @@ services: volumes: - portainer:/data - /var/run/docker.sock:/var/run/docker.sock - ports: - - 9091:9000 networks: default: