Updated to tests.bash, moved config.yaml to config/config.yaml for docker mount in /app/config/config.yaml
This commit is contained in:
parent
94115067c4
commit
7ced1b9e8d
|
@ -1,3 +1,3 @@
|
||||||
|
|
||||||
data/boxes.db
|
data/*
|
||||||
images/*
|
images/*
|
||||||
|
|
39
Dockerfile
39
Dockerfile
|
@ -1,22 +1,39 @@
|
||||||
FROM golang:1.21-alpine AS builder
|
# Stage 1: Build the Go binary
|
||||||
|
FROM golang:1.17-alpine AS builder
|
||||||
|
|
||||||
|
# Install build tools and SQLite development libraries
|
||||||
|
RUN apk add --no-cache gcc musl-dev sqlite-dev
|
||||||
|
|
||||||
|
# Set the working directory inside the container
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# Copy the source code
|
# Copy the Go modules files and download dependencies
|
||||||
|
COPY go.mod go.sum ./
|
||||||
|
RUN go mod download
|
||||||
|
|
||||||
|
# Copy the rest of the application source code
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
# Build the Go application
|
# Build the Go application
|
||||||
RUN go mod tidy
|
RUN go build -o boxes-api
|
||||||
RUN go build -o main .
|
|
||||||
|
|
||||||
# Mount the data directory
|
# Stage 2: Create a minimal image with the Go binary
|
||||||
VOLUME /app/data
|
FROM alpine:latest
|
||||||
|
|
||||||
# Copy config.yaml from the application directory
|
# Install necessary runtime dependencies
|
||||||
COPY config.yaml /app/
|
RUN apk add --no-cache ca-certificates
|
||||||
|
|
||||||
# Expose the port your application listens on
|
# Set the working directory inside the container
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Copy the binary from the builder stage
|
||||||
|
COPY --from=builder /app/boxes-api .
|
||||||
|
|
||||||
|
# Copy any other necessary files (e.g., configuration files)
|
||||||
|
# COPY --from=builder /app/config.yaml .
|
||||||
|
|
||||||
|
# Expose the port your app listens on
|
||||||
EXPOSE 8080
|
EXPOSE 8080
|
||||||
|
|
||||||
# Command to run your application
|
# Command to run the executable
|
||||||
CMD ["/app/main"]
|
CMD ["./boxes-api"]
|
2
go.mod
2
go.mod
|
@ -1,6 +1,6 @@
|
||||||
module boxes-api
|
module boxes-api
|
||||||
|
|
||||||
go 1.21.1
|
go 1.21
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/dgrijalva/jwt-go v3.2.0+incompatible
|
github.com/dgrijalva/jwt-go v3.2.0+incompatible
|
||||||
|
|
14
main.go
14
main.go
|
@ -4,6 +4,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
|
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
"github.com/jinzhu/gorm"
|
"github.com/jinzhu/gorm"
|
||||||
|
@ -16,16 +17,21 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
|
configFile := os.Getenv("CONFIG")
|
||||||
var err error
|
var err error
|
||||||
config, err = LoadConfig("config.yaml")
|
config, err = LoadConfig(configFile)
|
||||||
|
|
||||||
|
// check for errors
|
||||||
|
if err != nil || config == nil {
|
||||||
|
log.Fatalf("Failed to load config: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
fmt.Println(config.DatabasePath)
|
fmt.Println(config.DatabasePath)
|
||||||
fmt.Println(config.ImageStorageDir)
|
fmt.Println(config.ImageStorageDir)
|
||||||
fmt.Println(config.JWTSecret)
|
fmt.Println(config.JWTSecret)
|
||||||
fmt.Println(config.LogFile)
|
fmt.Println(config.LogFile)
|
||||||
fmt.Println(config.ListeningPort)
|
fmt.Println(config.ListeningPort)
|
||||||
if err != nil || config == nil {
|
|
||||||
log.Fatalf("Failed to load config: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Connect to the database
|
// Connect to the database
|
||||||
db, err = ConnectDB(config.DatabasePath)
|
db, err = ConnectDB(config.DatabasePath)
|
||||||
|
|
Loading…
Reference in New Issue