Skip to content

Commit

Permalink
deploy via docker #20
Browse files Browse the repository at this point in the history
  • Loading branch information
0xJacky committed Jul 22, 2022
1 parent 1aa4e70 commit 9851fe8
Show file tree
Hide file tree
Showing 16 changed files with 121 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ app.ini
dist
*.exe
*.po~
nginx-ui-server
nginx-ui
22 changes: 12 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# CGO_ENABLED=1 GOOS=linux CC=x86_64-unknown-linux-gnu-gcc CXX=x86_64-unknown-linux-gnu-g++ GOARCH=amd64 go build -ldflags "-X 'github.com/0xJacky/Nginx-UI/server/settings.buildTime=$(date +%s)'" -o nginx-ui-server -v main.go
FROM --platform=linux/amd64 uozi/nginx-ui-demo-debian-base-slim:latest
# CGO_ENABLED=1 GOOS=linux CC=x86_64-unknown-linux-gnu-gcc CXX=x86_64-unknown-linux-gnu-g++ GOARCH=amd64 go build -ldflags "-X 'github.com/0xJacky/Nginx-UI/server/settings.buildTime=$(date +%s)'" -o nginx-ui -v main.go
FROM --platform=linux/amd64 uozi/nginx-ui-base:latest
WORKDIR /app
EXPOSE 80
COPY ./resources/demo/nginx.conf /etc/nginx/sites-available/default
COPY ./resources/demo/app.ini /app/app.ini
COPY ./resources/demo/demo.db /app/database.db
COPY ./resources/demo/start.sh /app/start.sh
COPY ./nginx-ui-server /app/nginx-ui
RUN cd /app && chmod a+x start.sh
CMD ["./start.sh"]
EXPOSE 80 443

COPY resources/docker/start.sh /app/start.sh
COPY resources/docker/nginx.conf /usr/etc/nginx/nginx.conf
COPY resources/docker/nginx-ui.conf /usr/etc/nginx/conf.d/default.conf
COPY ./nginx-ui /app/nginx-ui

RUN cd /app && chmod a+x /app/start.sh

ENTRYPOINT ["./start.sh"]
21 changes: 21 additions & 0 deletions README-zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Nginx 网络管理界面,由 [0xJacky](https://jackyu.cn/) 与 [Hintay](https
<ul>
<li><a href="#通过执行文件运行">通过执行文件运行</a></li>
<li><a href="#使用-systemd">使用 Systemd</a></li>
<li><a href="#使用-Docker">使用 Docker</a></li>
</ul>
</li>
</ul>
Expand Down Expand Up @@ -158,6 +159,26 @@ systemctl stop nginx-ui
```shell
systemctl restart nginx-ui
```

## 使用 Docker

Docker 示例
- `nginx-ui:latest` 镜像基于 `nginx:latest` 构建,
您可以直接将该镜像监听到 80 和 443 端口以取代宿主机上的 Nginx

- 映射到 `/etc/nginx` 的文件夹应该为一个空目录

```
docker run -dit \
--name=nginx-ui \
--restart=always \
-e TZ=Asia/Shanghai \
-v /mnt/user/appdata/nginx:/etc/nginx \
-v /mnt/user/appdata/nginx-ui:/etc/nginx-ui \
-p 8080:80 -p 8443:443 \
nginx-ui:latest
```

## 手动构建

对于没有官方构建版本的平台,可以尝试手动构建。
Expand Down
8 changes: 8 additions & 0 deletions build-demo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
CGO_ENABLED=1 GOOS=linux CC=x86_64-unknown-linux-gnu-gcc \
CXX=x86_64-unknown-linux-gnu-g++ GOARCH=amd64 go build -ldflags \
"-X 'github.com/0xJacky/Nginx-UI/server/settings.buildTime=$(date +%s)'" -o nginx-ui -v main.go

docker build -t nginx-ui-demo .
docker tag nginx-ui-demo uozi/nginx-ui-demo
docker push uozi/nginx-ui-demo
11 changes: 7 additions & 4 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/bin/bash
CGO_ENABLED=1 GOOS=linux CC=x86_64-unknown-linux-gnu-gcc CXX=x86_64-unknown-linux-gnu-g++ GOARCH=amd64 go build -ldflags "-X 'github.com/0xJacky/Nginx-UI/server/settings.buildTime=$(date +%s)'" -o nginx-ui-server -v main.go
docker build -t nginx-ui-demo .
docker tag nginx-ui-demo uozi/nginx-ui-demo
docker push uozi/nginx-ui-demo
CGO_ENABLED=1 GOOS=linux CC=x86_64-unknown-linux-gnu-gcc \
CXX=x86_64-unknown-linux-gnu-g++ GOARCH=amd64 go build -ldflags \
"-X 'github.com/0xJacky/Nginx-UI/server/settings.buildTime=$(date +%s)'" -o nginx-ui -v main.go

docker build -t nginx-ui .
docker tag nginx-ui uozi/nginx-ui
docker push uozi/nginx-ui
16 changes: 16 additions & 0 deletions demo.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# CGO_ENABLED=1 GOOS=linux CC=x86_64-unknown-linux-gnu-gcc CXX=x86_64-unknown-linux-gnu-g++ GOARCH=amd64 go build -ldflags "-X 'github.com/0xJacky/Nginx-UI/server/settings.buildTime=$(date +%s)'" -o nginx-ui -v main.go
FROM --platform=linux/amd64 uozi/nginx-ui-base:latest
WORKDIR /app
EXPOSE 80

COPY resources/demo/app.ini /etc/nginx-ui/app.ini
COPY resources/demo/demo.db /etc/nginx-ui/database.db
COPY resources/docker/nginx.conf /etc/nginx/nginx.conf
COPY resources/docker/nginx-ui.conf /etc/nginx/conf.d/nginx-ui.conf
COPY resources/docker/start.sh /app/start.sh
COPY nginx-ui /app/nginx-ui

RUN cd /app && chmod a+x start.sh


ENTRYPOINT ["./start.sh"]
2 changes: 1 addition & 1 deletion frontend/version.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"version":"1.4.1","build_id":3,"total_build":66}
{"version":"1.4.1","build_id":4,"total_build":67}
Binary file added nginx-ui
Binary file not shown.
4 changes: 0 additions & 4 deletions resources/demo/sources.list

This file was deleted.

3 changes: 0 additions & 3 deletions resources/demo/start.sh

This file was deleted.

7 changes: 6 additions & 1 deletion resources/demo/nginx.conf → resources/docker/nginx-ui.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}

server {
listen 80;
server_name localhost; # your domain here
Expand All @@ -10,7 +15,7 @@ server {
proxy_set_header X-Forwarded-Proto $scheme;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_pass http://127.0.0.1:9000/;
}
}
32 changes: 32 additions & 0 deletions resources/docker/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
user nginx;
worker_processes auto;

error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid;


events {
worker_connections 1024;
}


http {
include /etc/nginx/mime.types;
default_type application/octet-stream;

log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

access_log /var/log/nginx/access.log main;

sendfile on;
#tcp_nopush on;

keepalive_timeout 65;

gzip on;

include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
10 changes: 10 additions & 0 deletions resources/docker/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

if [ "$(ls -A /etc/nginx)" = "" ]; then
echo "Initialing Nginx config dir"
cp -rp /usr/etc/nginx/* /etc/nginx/
echo "Initialed Nginx config dir"
fi

nginx
/app/nginx-ui --config /etc/nginx-ui/app.ini
5 changes: 3 additions & 2 deletions server/api/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"net/http"
"os"
"path/filepath"
"strings"
)

func GetConfigs(c *gin.Context) {
Expand Down Expand Up @@ -101,7 +102,7 @@ func AddConfig(c *gin.Context) {

output := nginx.ReloadNginx()

if output != "" {
if output != "" && strings.Contains(output, "error") {
c.JSON(http.StatusInternalServerError, gin.H{
"message": output,
})
Expand Down Expand Up @@ -147,7 +148,7 @@ func EditConfig(c *gin.Context) {

output := nginx.ReloadNginx()

if output != "" {
if output != "" && strings.Contains(output, "error") {
c.JSON(http.StatusInternalServerError, gin.H{
"message": output,
})
Expand Down
5 changes: 3 additions & 2 deletions server/api/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"net/http"
"os"
"path/filepath"
"strings"
)

func GetDomains(c *gin.Context) {
Expand Down Expand Up @@ -120,7 +121,7 @@ func EditDomain(c *gin.Context) {

output := nginx.ReloadNginx()

if output != "" {
if output != "" && strings.Contains(output, "error") {
c.JSON(http.StatusInternalServerError, gin.H{
"message": output,
})
Expand Down Expand Up @@ -161,7 +162,7 @@ func EnableDomain(c *gin.Context) {

output := nginx.ReloadNginx()

if output != "" {
if output != "" && strings.Contains(output, "error") {
c.JSON(http.StatusInternalServerError, gin.H{
"message": output,
})
Expand Down
1 change: 1 addition & 0 deletions server/tool/nginx/nginx.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func ReloadNginx() string {

if err != nil {
log.Println(err)
return err.Error()
}

output := string(out)
Expand Down

0 comments on commit 9851fe8

Please sign in to comment.