Skip to content

armgit / memos

Public Imported from GitHub
0

Memos is an open-source, self-hosted note-taking app that brings your everyday thoughts together in a personal timeline. Your data stays yours, and you choose what to keep private or share.

add dockerfile

stevenf70ad6891d6c
diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 000000000..73d60c250
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,36 @@
+# Build frontend dist.
+FROM node:14.18.2-alpine3.14 AS frontend
+WORKDIR /frontend-build
+
+COPY ./web/ .
+
+RUN yarn
+RUN yarn build
+
+# Build backend exec file.
+FROM golang:1.16.12-alpine3.15 AS backend
+WORKDIR /backend-build
+
+RUN apk --no-cache add gcc musl-dev
+
+COPY . .
+
+RUN go build \
+ -o memos \
+ ./server/main.go
+
+# Make workspace with above generated files.
+FROM alpine:3.14.3 AS monolithic
+WORKDIR /usr/local/memos
+
+COPY --from=backend /backend-build/memos /usr/local/memos/
+# Copy default resources, like db file.
+COPY --from=backend /backend-build/resources /usr/local/memos/resources
+COPY --from=frontend /frontend-build/dist /usr/local/memos/web/dist
+
+# Directory to store the data, which can be referenced as the mounting point.
+RUN mkdir -p /var/opt/memos/data
+
+CMD ["./memos"]
+
+EXPOSE 8080
diff --git a/scripts/.air.toml b/scripts/.air.toml
index c4ba8a3c7..938539f02 100644
--- a/scripts/.air.toml
+++ b/scripts/.air.toml
@@ -1,11 +1,11 @@
root = "."
-tmp_dir = "tmp"
+tmp_dir = ".air"
[build]
- bin = "./tmp/main"
- cmd = "go build -o ./tmp/main ."
+ bin = "./.air/memos"
+ cmd = "go build -o ./.air/memos ./server/main.go"
delay = 1000
- exclude_dir = ["assets", "tmp", "vendor", "web"]
+ exclude_dir = [".air", "web"]
exclude_file = []
exclude_regex = []
exclude_unchanged = false
diff --git a/main.go b/server/main.go
similarity index 90%
rename from main.go
rename to server/main.go
index a8f2b8b4f..69e903560 100644
--- a/main.go
+++ b/server/main.go
@@ -25,5 +25,5 @@ func main() {
r.PathPrefix("/").Handler(spa)
- http.ListenAndServe("localhost:8080", r)
+ http.ListenAndServe(":8080", r)
}
diff --git a/store/db.go b/store/db.go
index 4f76bf7a3..2d9d596c2 100644
--- a/store/db.go
+++ b/store/db.go
@@ -14,7 +14,7 @@ import (
var DB *sql.DB
func InitDBConn() {
- dbFilePath := "/data/memos.db"
+ dbFilePath := "/var/opt/memos/data/memos.db"
if _, err := os.Stat(dbFilePath); err != nil {
dbFilePath = "./resources/memos.db"
@@ -27,7 +27,7 @@ func InitDBConn() {
db, err := sql.Open("sqlite3", dbFilePath)
if err != nil {
- println("connect failed")
+ panic("db connect failed")
} else {
DB = db
println("connect to sqlite succeed")