Skip to content

Commit

Permalink
update docker compose network
Browse files Browse the repository at this point in the history
  • Loading branch information
zmh-program committed Dec 25, 2023
1 parent ff27fa8 commit 823025e
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 15 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@ chat.exe
reverse
access.json
access/*.json

db
redis
9 changes: 2 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ FROM centos:7.8.2003

# Install dependencies
RUN yum -y update && \
yum install -y epel-release gcc make nginx libgcc libstdc++ wget

COPY nginx.conf /etc/nginx/nginx.conf
yum install -y epel-release gcc make libgcc libstdc++ wget

# Install golang
RUN wget https://go.dev/dl/go1.21.5.linux-amd64.tar.gz && \
Expand Down Expand Up @@ -48,10 +46,7 @@ RUN cd /app && \
rm -rf node_modules

# Expose port
EXPOSE 8000

# Start nginx
CMD ["nginx", "-g", "daemon off;"]
EXPOSE 8094

# Start backend
CMD ["./chat"]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@


## 📦 部署 | Deploy
*部署成功后,管理员账号为 `root`,密码默认为 `123456`*
*部署成功后,管理员账号为 `root`,密码默认为 `chatnio123456`*

1. 编译安装 (自定义性强)
```shell
Expand Down
5 changes: 3 additions & 2 deletions connection/database.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package connection

import (
"chat/utils"
"database/sql"
"fmt"
_ "github.com/go-sql-driver/mysql"
Expand Down Expand Up @@ -60,11 +61,11 @@ func InitRootUser(db *sql.DB) {
}

if count == 0 {
fmt.Println("[service] no user found, creating root user (username: root, password: 123456, email: root@null.com)")
fmt.Println("[service] no user found, creating root user (username: root, password: chatnio123456, email: root@example.com)")
_, err := db.Exec(`
INSERT INTO auth (username, password, email, is_admin, bind_id, token)
VALUES (?, ?, ?, ?, ?, ?)
`, "root", "123456", "root@null.com", true, 0, "root")
`, "root", utils.Sha2Encrypt("chatnio123456"), "root@example.com", true, 0, "root")
if err != nil {
fmt.Println(err)
}
Expand Down
22 changes: 17 additions & 5 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,30 @@ services:
MYSQL_DATABASE: chatnio
MYSQL_USER: chatnio
MYSQL_PASSWORD: chatnio123456!
ports:
- "3306:3306"
expose:
- "3306"
volumes:
- ./db:/var/lib/mysql
networks:
- chatnio-network

redis:
image: redis:latest
container_name: redis
restart: always
ports:
- "6379:6379"
expose:
- "6379"
volumes:
- ./redis:/data
networks:
- chatnio-network

chatnio:
build: .
container_name: chatnio
restart: always
ports:
- "8000:8000"
- "8000:8094"
depends_on:
- mysql
- redis
Expand All @@ -43,3 +49,9 @@ services:
REDIS_PASSWORD: ""
REDIS_DB: 0
SERVE_STATIC: "true"
networks:
- chatnio-network

networks:
chatnio-network:
driver: bridge
2 changes: 2 additions & 0 deletions utils/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,6 @@ func RegisterStaticRoute(engine *gin.Engine) {
engine.NoRoute(func(c *gin.Context) {
c.File("./app/dist/index.html")
})

fmt.Println(`[service] start serving static files from ~/app/dist`)
}

0 comments on commit 823025e

Please sign in to comment.