Skip to content

Commit f70ad68

Browse files
committed
add dockerfile
1 parent 527745a commit f70ad68

4 files changed

Lines changed: 43 additions & 7 deletions

File tree

Dockerfile

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Build frontend dist.
2+
FROM node:14.18.2-alpine3.14 AS frontend
3+
WORKDIR /frontend-build
4+
5+
COPY ./web/ .
6+
7+
RUN yarn
8+
RUN yarn build
9+
10+
# Build backend exec file.
11+
FROM golang:1.16.12-alpine3.15 AS backend
12+
WORKDIR /backend-build
13+
14+
RUN apk --no-cache add gcc musl-dev
15+
16+
COPY . .
17+
18+
RUN go build \
19+
-o memos \
20+
./server/main.go
21+
22+
# Make workspace with above generated files.
23+
FROM alpine:3.14.3 AS monolithic
24+
WORKDIR /usr/local/memos
25+
26+
COPY --from=backend /backend-build/memos /usr/local/memos/
27+
# Copy default resources, like db file.
28+
COPY --from=backend /backend-build/resources /usr/local/memos/resources
29+
COPY --from=frontend /frontend-build/dist /usr/local/memos/web/dist
30+
31+
# Directory to store the data, which can be referenced as the mounting point.
32+
RUN mkdir -p /var/opt/memos/data
33+
34+
CMD ["./memos"]
35+
36+
EXPOSE 8080

scripts/.air.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
root = "."
2-
tmp_dir = "tmp"
2+
tmp_dir = ".air"
33

44
[build]
5-
bin = "./tmp/main"
6-
cmd = "go build -o ./tmp/main ."
5+
bin = "./.air/memos"
6+
cmd = "go build -o ./.air/memos ./server/main.go"
77
delay = 1000
8-
exclude_dir = ["assets", "tmp", "vendor", "web"]
8+
exclude_dir = [".air", "web"]
99
exclude_file = []
1010
exclude_regex = []
1111
exclude_unchanged = false

main.go renamed to server/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ func main() {
2525

2626
r.PathPrefix("/").Handler(spa)
2727

28-
http.ListenAndServe("localhost:8080", r)
28+
http.ListenAndServe(":8080", r)
2929
}

store/db.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
var DB *sql.DB
1515

1616
func InitDBConn() {
17-
dbFilePath := "/data/memos.db"
17+
dbFilePath := "/var/opt/memos/data/memos.db"
1818

1919
if _, err := os.Stat(dbFilePath); err != nil {
2020
dbFilePath = "./resources/memos.db"
@@ -27,7 +27,7 @@ func InitDBConn() {
2727
db, err := sql.Open("sqlite3", dbFilePath)
2828

2929
if err != nil {
30-
println("connect failed")
30+
panic("db connect failed")
3131
} else {
3232
DB = db
3333
println("connect to sqlite succeed")

0 commit comments

Comments
 (0)