Skip to content

Commit

Permalink
add dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
boojack committed Dec 12, 2021
1 parent 527745a commit f70ad68
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 7 deletions.
36 changes: 36 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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
8 changes: 4 additions & 4 deletions scripts/.air.toml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion main.go → server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ func main() {

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

http.ListenAndServe("localhost:8080", r)
http.ListenAndServe(":8080", r)
}
4 changes: 2 additions & 2 deletions store/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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")
Expand Down

0 comments on commit f70ad68

Please sign in to comment.