add and test dockerfile build and run

This commit is contained in:
2024-11-19 17:36:24 -06:00
parent f19645d768
commit 5a2a0ccd9f
5 changed files with 63 additions and 2 deletions

41
Dockerfile Normal file
View File

@@ -0,0 +1,41 @@
# Stage 1: Build
FROM golang:1.23 AS builder
# Set the working directory inside the container
WORKDIR /app
# volume for nkode.db
VOLUME /app/data/sqlite
VOLUME /app/data/icons
# Copy go.mod and go.sum files
COPY go.mod go.sum ./
# Download all dependencies
RUN go mod download
# Copy the rest of the application code
COPY . .
# Build the application
RUN go build
# Stage 2: Runtime
FROM debian:bookworm-slim
#ENV FRONTEND_HOST=https://app.nkode.tech
ENV FRONTEND_HOST=http://localhost:8090
ENV SVG_DIR=/app/data/icons
ENV DB_PATH=/app/data/sqlite/nkode.db
ENV SQLITE_DB=/app/data/sqlite/nkode.db
# Set the working directory inside the runtime container
WORKDIR /app
# Copy the compiled Go binary from the builder stage
COPY --from=builder /app/go-nkode .
# Expose the port the application will run on
EXPOSE 8080
# Command to run the application
CMD ["./go-nkode"]

View File

@@ -1 +1,15 @@
test edit # Go nKode
A golang implementation of nKode
## env var
```.env
LOCAL=true # todo: remove this
FRONTEND_HOST=https://app.nkode.tech # localhost:8080
SVG_DIR=/path/to/go-nkode/core/sqlite-init/flaticon_colored_svgs
DB_PATH=/path/to/nkode.db # todo: remove this
SQLITE_DB=/path/to/nkode.db
JWT_SECRET= # openssl rand -base64 64
```

1
docker_build.sh Normal file
View File

@@ -0,0 +1 @@
docker build -t go-nkode .

5
docker_run.sh Normal file
View File

@@ -0,0 +1,5 @@
docker run --name go-nkode -p 8080:8080 \
-v /Users/donov/databases/:/app/data/sqlite \
-v /Users/donov/Desktop/go-nkode/core/sqlite-init/flaticon_colored_svgs/:/app/data/icons \
-e JWT_SECRET=cab2f6a968c2a11601bb33c41c5940b7 \
go-nkode

View File

@@ -40,7 +40,7 @@ func main() {
mux.Handle(core.RefreshToken, &handler) mux.Handle(core.RefreshToken, &handler)
mux.Handle(core.ResetNKode, &handler) mux.Handle(core.ResetNKode, &handler)
fmt.Println("Running on localhost:8080...") fmt.Println("Running on localhost:8080...")
log.Fatal(http.ListenAndServe("localhost:8080", corsMiddleware(mux))) log.Fatal(http.ListenAndServe(":8080", corsMiddleware(mux)))
} }
func corsMiddleware(next http.Handler) http.Handler { func corsMiddleware(next http.Handler) http.Handler {