Skip to content

Commit

Permalink
Merge pull request #25 from weiwiegeng/main
Browse files Browse the repository at this point in the history
feat: 增加开源版docker编排一键部署
  • Loading branch information
xinjiayu authored Nov 28, 2023
2 parents 1210b53 + 6caa6c3 commit d8c1d02
Show file tree
Hide file tree
Showing 248 changed files with 2,396 additions and 770,548 deletions.
31 changes: 24 additions & 7 deletions manifest/docker-compose/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,30 +1,36 @@
services:
redis:
image: redis:7.0.11
container_name: redis-server
container_name: redis
restart: always
volumes:
- "./redis/conf/redis.conf:/usr/local/etc/redis/redis.conf"
- "./redis/data:/data"
- "./redis/logs:/logs"
command: ["redis-server","/usr/local/etc/redis/redis.conf"]
environment:
- TZ=Asia/Shanghai
ports:
- 6379:6379
tdengine:
image: tdengine/tdengine:3.0.1.4
container_name: tdengine-server
image: tdengine/tdengine:3.1.1.0
container_name: tdengine
restart: always
environment:
- TZ=Asia/Shanghai
volumes:
- "./taos/dnode/data:/var/lib/taos"
- "./taos/dnode/log:/var/log/taos"
ports:
- 6030:6030
- 6041:6041
emqx:
image: emqx/emqx:5.0.26
container_name: emqx-server
restart: always
container_name: emqx
environment:
- TZ=Asia/Shanghai
volumes:
- ./emqx/data:/opt/emqx/data
- ./emqx/log:/opt/emqx/log
ports:
- 1883:1883
- 8083:8083
Expand All @@ -33,13 +39,24 @@ services:
- 18083:18083
mysql:
image: mysql:8.0.25
container_name: mysql-server
container_name: mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: DbyTYGu3s4WuAF4TTq7
MYSQL_DATABASE: sagoo_iot_open
volumes:
- ./mysql/init:/docker-entrypoint-initdb.d
- ./mysql/data:/var/lib/mysql
- ./mysql/logs:/var/log
ports:
- "3306:3306"
nginx:
extends:
file: ./nginx/nginx.yaml
service: nginx

sagoo-iot-open:
extends:
file: ./iot-open/iot-open.yaml
service: sagoo-iot-open

19 changes: 19 additions & 0 deletions manifest/docker-compose/iot-open/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM golang:alpine

WORKDIR /opt/sagoo-iot-server/

COPY ./config/ /opt/sagoo-iot-server/config

COPY ./curl.sh /opt/sagoo-iot-server/
COPY ./entrypoint.sh /opt/sagoo-iot-server/
COPY ./sagoo-admin /opt/sagoo-iot-server/

COPY ./entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
RUN chmod +x /opt/sagoo-iot-server/sagoo-admin

COPY ./resource/public /opt/sagoo-iot-server/resource/public/

EXPOSE 8200

CMD ["/bin/sh", "-c", "sleep 50 && /entrypoint.sh"]
96 changes: 96 additions & 0 deletions manifest/docker-compose/iot-open/curl.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#!/bin/bash

WORKSPACE=$(cd "$(dirname "$0")" || exit; pwd)
cd "$WORKSPACE" || exit

readonly app='sagoo-admin'
readonly pidfile="var/$app.pid"
readonly logfile="var/$app.log"

mkdir -p var

check_pid() {
if [[ -f $pidfile ]]; then
local pid=$(cat "$pidfile")
if [[ -n $pid ]]; then
local running=$(ps -p "$pid" | grep -c -v "PID TTY")
return "$running"
fi
fi
return 0
}

start() {
check_pid
local running=$?
if [[ $running -gt 0 ]]; then
printf "%s now is running already, pid: %s\n" "$app" "$(cat "$pidfile")"
return 1
fi

nohup "./$app" >> "$logfile" 2>&1 &
sleep 1
running=$(ps -p $! | grep -c -v "PID TTY")
if [[ $running -gt 0 ]]; then
echo $! > "$pidfile"
printf "%s started... pid: %s\n" "$app" "$!"
else
printf "%s failed to start.\n" "$app"
return 1
fi
}

stop() {
check_pid
local running=$?
if [[ $running -gt 0 ]]; then
local pid=$(cat "$pidfile")
kill "$pid"
rm -f "$pidfile"
printf "%s stopped.\n" "$app"
else
printf "%s is not running.\n" "$app"
fi
}

restart() {
stop
sleep 1
start
}

status() {
check_pid
local running=$?
if [[ $running -gt 0 ]]; then
printf "%s is started.\n" "$app"
else
printf "%s is stopped.\n" "$app"
fi
}

tailf() {
tail -f "var/*"
}

print_help() {
printf "Usage: %s {start|stop|restart|status|tail|pid}.\n" "$0"
}

print_pid() {
cat "$pidfile"
}

main() {
case "$1" in
"start") start ;;
"stop") stop ;;
"restart") restart ;;
"status") status ;;
"tail") tailf ;;
"pid") print_pid ;;
*) print_help ;;
esac
}

main "$@"
4 changes: 4 additions & 0 deletions manifest/docker-compose/iot-open/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh

# 这里是其他的启动逻辑或命令
/opt/sagoo-iot-server/sagoo-admin
19 changes: 19 additions & 0 deletions manifest/docker-compose/iot-open/iot-open.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
services:
sagoo-iot-open:
image: sagoo-iot-open:1.0.0
restart: always
container_name: sagoo-iot-open
build:
dockerfile: ./Dockerfile
depends_on:
- mysql
- redis
- emqx
- tdengine
environment:
- TZ=Asia/Shanghai
ports:
- 8200:8200
volumes:
- "./resource/public/upload_file/:/opt/sagoo-iot-server/resource/public/upload_file"
- "./resource/log/:/opt/sagoo-iot-server/resource/log"
Binary file added manifest/docker-compose/iot-open/sagoo-admin
Binary file not shown.
113 changes: 113 additions & 0 deletions manifest/docker-compose/nginx/conf/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
#user nobody;
worker_processes 1;

#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;

#pid logs/nginx.pid;


events {
worker_connections 1024;
}



http {
include 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 logs/access.log main;

sendfile on;
#tcp_nopush on;

#keepalive_timeout 0;
keepalive_timeout 65;

gzip on;
gzip_min_length 10k;
gzip_buffers 4 16k;
gzip_comp_level 6;
gzip_types text/plain application/javascript application/x-javascript text/javascript text/css application/xml;
gzip_vary on;
gzip_proxied expired no-cache no-store private auth;
gzip_disable "MSIE [1-6]\.";

server {
listen 80;
server_name localhost;

# ssl_certificate /data/nginx/conf/vhost/cert/localhost/fullchain.pem;
# ssl_certificate_key /data/nginx/conf/vhost/cert/localhost/privkey.pem;

location / {
root /usr/share/nginx/html/iot-ui;
}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}

#sagoo-iot路由
location /base-api/ {
proxy_set_header Connection upgrade;
proxy_set_header Upgrade $http_upgrade;
proxy_http_version 1.1;
chunked_transfer_encoding off;
proxy_pass http://sagoo-iot-open:8200/;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

#⼝⽂档路由
location /base-api/swagger/api.json {
proxy_pass http://sagoo-iot-open:8200/base-api/swagger/api.json;
}
}


# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;

# location / {
# root html;
# index index.html index.htm;
# }
#}


# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;

# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;

# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;

# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;

# location / {
# root html;
# index index.html index.htm;
# }
#}

}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit d8c1d02

Please sign in to comment.