Updated to tests.bash, moved config.yaml to config/config.yaml for docker mount in /app/config/config.yaml

This commit is contained in:
Steve White 2024-10-07 10:28:16 -05:00
parent 94115067c4
commit 7ced1b9e8d
6 changed files with 41 additions and 18 deletions

4
.gitignore vendored
View File

@ -1,3 +1,3 @@
data/boxes.db
images/*
data/*
images/*

View File

@ -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
# 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 . .
# Build the Go application
RUN go mod tidy
RUN go build -o main .
RUN go build -o boxes-api
# Mount the data directory
VOLUME /app/data
# Stage 2: Create a minimal image with the Go binary
FROM alpine:latest
# Copy config.yaml from the application directory
COPY config.yaml /app/
# Install necessary runtime dependencies
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
# Command to run your application
CMD ["/app/main"]
# Command to run the executable
CMD ["./boxes-api"]

BIN
boxes-api Executable file

Binary file not shown.

2
go.mod
View File

@ -1,6 +1,6 @@
module boxes-api
go 1.21.1
go 1.21
require (
github.com/dgrijalva/jwt-go v3.2.0+incompatible

14
main.go
View File

@ -4,6 +4,7 @@ import (
"fmt"
"log"
"net/http"
"os"
"github.com/gorilla/mux"
"github.com/jinzhu/gorm"
@ -16,16 +17,21 @@ var (
)
func main() {
configFile := os.Getenv("CONFIG")
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.ImageStorageDir)
fmt.Println(config.JWTSecret)
fmt.Println(config.LogFile)
fmt.Println(config.ListeningPort)
if err != nil || config == nil {
log.Fatalf("Failed to load config: %v", err)
}
// Connect to the database
db, err = ConnectDB(config.DatabasePath)