Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
canifa_note
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vũ Hoàng Anh
canifa_note
Commits
9cc970a3
Commit
9cc970a3
authored
Jan 21, 2026
by
Steven
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: fix data directory handling
parent
4180613f
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
17 deletions
+21
-17
profile.go
internal/profile/profile.go
+16
-14
Dockerfile
scripts/Dockerfile
+5
-3
No files found.
internal/profile/profile.go
View file @
9cc970a3
...
@@ -37,8 +37,9 @@ type Profile struct {
...
@@ -37,8 +37,9 @@ type Profile struct {
func
checkDataDir
(
dataDir
string
)
(
string
,
error
)
{
func
checkDataDir
(
dataDir
string
)
(
string
,
error
)
{
// Convert to absolute path if relative path is supplied.
// Convert to absolute path if relative path is supplied.
if
!
filepath
.
IsAbs
(
dataDir
)
{
if
!
filepath
.
IsAbs
(
dataDir
)
{
relativeDir
:=
filepath
.
Join
(
filepath
.
Dir
(
os
.
Args
[
0
]),
dataDir
)
// Use current working directory, not the binary's directory
absDir
,
err
:=
filepath
.
Abs
(
relativeDir
)
// This ensures we use the actual working directory where the process runs
absDir
,
err
:=
filepath
.
Abs
(
dataDir
)
if
err
!=
nil
{
if
err
!=
nil
{
return
""
,
err
return
""
,
err
}
}
...
@@ -56,23 +57,24 @@ func checkDataDir(dataDir string) (string, error) {
...
@@ -56,23 +57,24 @@ func checkDataDir(dataDir string) (string, error) {
func
(
p
*
Profile
)
Validate
()
error
{
func
(
p
*
Profile
)
Validate
()
error
{
// Set default data directory if not specified
// Set default data directory if not specified
if
p
.
Data
==
""
{
if
p
.
Data
==
""
{
if
p
.
Demo
{
// In demo mode, use current directory
p
.
Data
=
"."
}
else
{
// In production mode, use system directory
if
runtime
.
GOOS
==
"windows"
{
if
runtime
.
GOOS
==
"windows"
{
p
.
Data
=
filepath
.
Join
(
os
.
Getenv
(
"ProgramData"
),
"memos"
)
p
.
Data
=
filepath
.
Join
(
os
.
Getenv
(
"ProgramData"
),
"memos"
)
}
else
{
}
else
{
// On Linux/macOS, check if /var/opt/memos exists (Docker scenario)
// On Linux/macOS, check if /var/opt/memos exists and is writable (Docker scenario)
// If not, fall back to current directory to avoid permission issues
if
info
,
err
:=
os
.
Stat
(
"/var/opt/memos"
);
err
==
nil
&&
info
.
IsDir
()
{
if
_
,
err
:=
os
.
Stat
(
"/var/opt/memos"
);
err
==
nil
{
// Check if we can write to this directory
testFile
:=
filepath
.
Join
(
"/var/opt/memos"
,
".write-test"
)
if
err
:=
os
.
WriteFile
(
testFile
,
[]
byte
(
"test"
),
0600
);
err
==
nil
{
os
.
Remove
(
testFile
)
p
.
Data
=
"/var/opt/memos"
p
.
Data
=
"/var/opt/memos"
}
else
{
}
else
{
slog
.
Warn
(
"default production data directory /var/opt/memos not accessible, using current directory. "
+
// /var/opt/memos exists but is not writable, use current directory
"Consider using --data flag to specify a data directory.
"
)
slog
.
Warn
(
"/var/opt/memos is not writable, using current directory
"
)
p
.
Data
=
"."
p
.
Data
=
"."
}
}
}
else
{
// /var/opt/memos doesn't exist, use current directory (local development)
p
.
Data
=
"."
}
}
}
}
}
}
...
...
scripts/Dockerfile
View file @
9cc970a3
...
@@ -27,22 +27,24 @@ RUN --mount=type=cache,target=/go/pkg/mod \
...
@@ -27,22 +27,24 @@ RUN --mount=type=cache,target=/go/pkg/mod \
# Use minimal Alpine with security updates
# Use minimal Alpine with security updates
FROM
alpine:3.21 AS monolithic
FROM
alpine:3.21 AS monolithic
WORKDIR
/usr/local/memos
# Install runtime dependencies and create non-root user in single layer
# Install runtime dependencies and create non-root user in single layer
RUN
apk add
--no-cache
tzdata ca-certificates
&&
\
RUN
apk add
--no-cache
tzdata ca-certificates
&&
\
addgroup
-g
10001
-S
nonroot
&&
\
addgroup
-g
10001
-S
nonroot
&&
\
adduser
-u
10001
-S
-G
nonroot
-h
/var/opt/memos nonroot
&&
\
adduser
-u
10001
-S
-G
nonroot
-h
/var/opt/memos nonroot
&&
\
mkdir
-p
/var/opt/memos
&&
\
mkdir
-p
/var/opt/memos
/usr/local/memos
&&
\
chown
-R
nonroot:nonroot /var/opt/memos
chown
-R
nonroot:nonroot /var/opt/memos
# Copy binary and entrypoint
# Copy binary and entrypoint
to /usr/local/memos
COPY
--from=backend /backend-build/memos /usr/local/memos/memos
COPY
--from=backend /backend-build/memos /usr/local/memos/memos
COPY
--from=backend --chmod=755 /backend-build/scripts/entrypoint.sh /usr/local/memos/entrypoint.sh
COPY
--from=backend --chmod=755 /backend-build/scripts/entrypoint.sh /usr/local/memos/entrypoint.sh
# Switch to non-root user
# Switch to non-root user
USER
nonroot:nonroot
USER
nonroot:nonroot
# Set working directory to the writable volume
WORKDIR
/var/opt/memos
# Data directory
# Data directory
VOLUME
/var/opt/memos
VOLUME
/var/opt/memos
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment