Skip to content

Commit

Permalink
新增镜像构建
Browse files Browse the repository at this point in the history
  • Loading branch information
donknap committed Mar 5, 2024
1 parent f5aee0e commit 3b29d0b
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM alpine:3.18

RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories
RUN apk --no-cache add nginx
RUN apk --no-cache add nginx inotify-tools

RUN mkdir -p /dpanel/nginx/default_host /dpanel/nginx/proxy_host \
/dpanel/nginx/redirection_host /dpanel/nginx/dead_host \
Expand Down
16 changes: 11 additions & 5 deletions app/application/http/controller/site.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,13 +297,19 @@ func (self Site) CreateDomain(http *gin.Context) {
if !self.Validate(http, &params) {
return
}
containerRow, err := docker.Sdk.Client.ContainerInspect(docker.Sdk.Ctx, params.ContainerId)
if err != nil {
self.JsonResponseWithError(http, err, 500)
return
}

var asset embed.FS
err := facade.GetContainer().NamedResolve(&asset, "asset")
err = facade.GetContainer().NamedResolve(&asset, "asset")
if err != nil {
self.JsonResponseWithError(http, err, 500)
return
}
confRootPath := "/Users/renchao/Workspace/data/dpanel"
confRootPath := "/Users/renchao/Workspace/data/dpanel/nginx/proxy_host"
vhostFile, err := os.OpenFile(confRootPath+"/"+params.Domain+".conf", os.O_CREATE|os.O_RDWR|os.O_TRUNC, 0666)
defer vhostFile.Close()

Expand All @@ -318,9 +324,9 @@ func (self Site) CreateDomain(http *gin.Context) {
}
parser, err := template.ParseFS(asset, "asset/nginx/*.tpl")
err = parser.ExecuteTemplate(vhostFile, "vhost.tpl", tplParams{
ServerAddress: "127.0.0.1",
Port: 80,
ServerName: "test3.phpeye.net",
ServerAddress: containerRow.NetworkSettings.DefaultNetworkSettings.IPAddress,
Port: params.Port,
ServerName: params.Domain,
EnableBlockCommonExploits: params.EnableBlockCommonExploits,
EnableWs: params.EnableWs,
EnableAssetCache: params.EnableAssetCache,
Expand Down
4 changes: 2 additions & 2 deletions asset/nginx/vhost.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ server {

{{if .EnableAssetCache}}
# Asset Caching
include conf.d/include/assets.conf;
include /dpanel/nginx/include/assets.conf;
{{end}}
{{if .EnableBlockCommonExploits}}
# Block Exploits
include conf.d/include/block-exploits.conf;
include /dpanel/nginx/include/block-exploits.conf;
{{end}}

{{if .EnableWs}}
Expand Down
16 changes: 16 additions & 0 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
#!/bin/sh

NGINX_CONFIG_DIR="/dpanel/nginx"
NGINX_CMD="nginx"

reload_nginx() {
echo "Reloading Nginx configuration..."
$NGINX_CMD -s reload
if [ $? -ne 0 ]; then
echo "Failed to reload Nginx configuration."
fi
}

while true; do
inotifywait -r -e modify,create,delete,move "$NGINX_CONFIG_DIR"
reload_nginx
done &

nginx -g 'daemon off;'
4 changes: 2 additions & 2 deletions docker/nginx/include/assets.conf
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ location ~* ^.*\.(css|js|jpe?g|gif|png|webp|woff|eot|ttf|svg|ico|css\.map|js\.ma
expires @30m;
access_log off;

include conf.d/include/proxy.conf;
}
include /dpanel/nginx/include/proxy.conf;
}
Binary file modified dpanel.db
Binary file not shown.

0 comments on commit 3b29d0b

Please sign in to comment.