Spaces:
Running
Running
Upload 4 files
Browse files- Dockerfile +25 -22
- migration.go +7 -5
Dockerfile
CHANGED
@@ -1,35 +1,38 @@
|
|
1 |
-
#
|
2 |
-
FROM golang:1.18
|
3 |
-
|
4 |
-
# 安装必要的工具
|
5 |
-
RUN apt-get update && apt-get install -y \
|
6 |
-
wget \
|
7 |
-
tar \
|
8 |
-
git
|
9 |
-
RUN apt-get update && apt-get install -y aria2 \
|
10 |
-
&& git clone https://github.com/cloudreve/Cloudreve.git /app
|
11 |
-
COPY aria2.conf /app/aria2.conf
|
12 |
-
COPY migration.go /app/models/migration.go
|
13 |
-
# 设置工作目录
|
14 |
WORKDIR /app
|
15 |
|
|
|
|
|
16 |
|
|
|
|
|
17 |
|
18 |
-
#
|
19 |
-
RUN
|
20 |
|
|
|
|
|
21 |
|
22 |
-
#
|
23 |
-
RUN
|
24 |
|
25 |
-
|
|
|
26 |
|
|
|
|
|
27 |
|
28 |
-
|
|
|
|
|
|
|
|
|
|
|
29 |
|
30 |
-
|
31 |
|
|
|
32 |
|
33 |
-
COPY start.sh /app/start.sh
|
34 |
-
RUN chmod +x /app/start.sh
|
35 |
CMD ["/app/start.sh"]
|
|
|
1 |
+
# Build stage
|
2 |
+
FROM golang:1.18 AS builder
|
3 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
WORKDIR /app
|
5 |
|
6 |
+
# Clone the repository
|
7 |
+
RUN git clone https://github.com/cloudreve/Cloudreve.git .
|
8 |
|
9 |
+
# Copy custom files
|
10 |
+
COPY migration.go /app/models/migration.go
|
11 |
|
12 |
+
# Build the application
|
13 |
+
RUN go mod tidy && go build -o cloudreve
|
14 |
|
15 |
+
# Final stage
|
16 |
+
FROM debian:buster-slim
|
17 |
|
18 |
+
# Install aria2
|
19 |
+
RUN apt-get update && apt-get install -y aria2 && rm -rf /var/lib/apt/lists/*
|
20 |
|
21 |
+
# Create necessary directories
|
22 |
+
RUN mkdir -p /app /aria2/data && chmod 777 /aria2/data
|
23 |
|
24 |
+
# Copy the built executable from the builder stage
|
25 |
+
COPY --from=builder /app/cloudreve /app/
|
26 |
|
27 |
+
# Copy configuration files and scripts
|
28 |
+
COPY aria2.conf /app/aria2.conf
|
29 |
+
COPY start.sh /app/start.sh
|
30 |
+
|
31 |
+
# Set permissions
|
32 |
+
RUN chmod +x /app/cloudreve /app/start.sh
|
33 |
|
34 |
+
WORKDIR /app
|
35 |
|
36 |
+
EXPOSE 5212
|
37 |
|
|
|
|
|
38 |
CMD ["/app/start.sh"]
|
migration.go
CHANGED
@@ -2,6 +2,10 @@ package model
|
|
2 |
|
3 |
import (
|
4 |
"context"
|
|
|
|
|
|
|
|
|
5 |
"github.com/cloudreve/Cloudreve/v3/models/scripts/invoker"
|
6 |
"github.com/cloudreve/Cloudreve/v3/pkg/cache"
|
7 |
"github.com/cloudreve/Cloudreve/v3/pkg/conf"
|
@@ -9,8 +13,6 @@ import (
|
|
9 |
"github.com/fatih/color"
|
10 |
"github.com/hashicorp/go-version"
|
11 |
"github.com/jinzhu/gorm"
|
12 |
-
"sort"
|
13 |
-
"strings"
|
14 |
)
|
15 |
|
16 |
// 是否需要迁移
|
@@ -161,12 +163,12 @@ func addDefaultGroups() {
|
|
161 |
|
162 |
func addDefaultUser() {
|
163 |
_, err := GetUserByID(1)
|
164 |
-
password :=
|
165 |
|
166 |
// 未找到初始用户时,则创建
|
167 |
if gorm.IsRecordNotFoundError(err) {
|
168 |
defaultUser := NewUser()
|
169 |
-
defaultUser.Email =
|
170 |
defaultUser.Nick = "admin"
|
171 |
defaultUser.Status = Active
|
172 |
defaultUser.GroupID = 1
|
@@ -215,4 +217,4 @@ func execUpgradeScripts() {
|
|
215 |
for i := 0; i < len(versions); i++ {
|
216 |
invoker.RunDBScript("UpgradeTo"+versions[i].String(), context.Background())
|
217 |
}
|
218 |
-
}
|
|
|
2 |
|
3 |
import (
|
4 |
"context"
|
5 |
+
"os"
|
6 |
+
"sort"
|
7 |
+
"strings"
|
8 |
+
|
9 |
"github.com/cloudreve/Cloudreve/v3/models/scripts/invoker"
|
10 |
"github.com/cloudreve/Cloudreve/v3/pkg/cache"
|
11 |
"github.com/cloudreve/Cloudreve/v3/pkg/conf"
|
|
|
13 |
"github.com/fatih/color"
|
14 |
"github.com/hashicorp/go-version"
|
15 |
"github.com/jinzhu/gorm"
|
|
|
|
|
16 |
)
|
17 |
|
18 |
// 是否需要迁移
|
|
|
163 |
|
164 |
func addDefaultUser() {
|
165 |
_, err := GetUserByID(1)
|
166 |
+
password := os.Getenv("ADMIN_PASSWORD")
|
167 |
|
168 |
// 未找到初始用户时,则创建
|
169 |
if gorm.IsRecordNotFoundError(err) {
|
170 |
defaultUser := NewUser()
|
171 |
+
defaultUser.Email = os.Getenv("ADMIN_EMAIL")
|
172 |
defaultUser.Nick = "admin"
|
173 |
defaultUser.Status = Active
|
174 |
defaultUser.GroupID = 1
|
|
|
217 |
for i := 0; i < len(versions); i++ {
|
218 |
invoker.RunDBScript("UpgradeTo"+versions[i].String(), context.Background())
|
219 |
}
|
220 |
+
}
|