64 lines
2.9 KiB
Docker
64 lines
2.9 KiB
Docker
# ============================================================================
|
|
# DEVELOPERS NOTE:
|
|
# THE PURPOSE OF THIS DOCKERFILE IS TO BUILD THE MAPLEFILE BACKEND
|
|
# EXECUTABLE IN A CONTAINER FOR DEVELOPMENT PURPOSES ON YOUR
|
|
# MACHINE. DO NOT RUN THIS IN PRODUCTION ENVIRONMENT.
|
|
# ============================================================================
|
|
|
|
# Start with the official Golang image
|
|
FROM golang:1.25.4
|
|
|
|
# ============================================================================
|
|
# SETUP PROJECT DIRECTORY STRUCTURE
|
|
# ============================================================================
|
|
# Set the working directory first
|
|
WORKDIR /go/src/codeberg.org/mapleopentech/monorepo/cloud/maplefile-backend
|
|
|
|
# ============================================================================
|
|
# DEPENDENCY MANAGEMENT (DO THIS FIRST FOR BETTER CACHING)
|
|
# ============================================================================
|
|
# Copy dependency files first to take advantage of Docker layer caching
|
|
COPY go.mod go.sum ./
|
|
# Download all dependencies
|
|
RUN go mod download
|
|
|
|
# ============================================================================
|
|
# INSTALL DEVELOPMENT TOOLS
|
|
# ============================================================================
|
|
# Install CompileDaemon for hot reloading
|
|
RUN go install github.com/githubnemo/CompileDaemon@latest
|
|
|
|
# Install curl for healthcheck
|
|
RUN apt-get update && apt-get install -y curl && rm -rf /var/lib/apt/lists/*
|
|
|
|
# ============================================================================
|
|
# CREATE SIMPLIFIED BUILD SCRIPT
|
|
# ============================================================================
|
|
RUN echo '#!/bin/sh\n\
|
|
echo "============================================================"\n\
|
|
echo "BEGINNING BUILD PROCESS"\n\
|
|
echo "============================================================"\n\
|
|
\n\
|
|
echo "[1/1] Building application..."\n\
|
|
go build -o maplefile-backend .\n\
|
|
if [ $? -ne 0 ]; then\n\
|
|
echo "Build failed!"\n\
|
|
exit 1\n\
|
|
fi\n\
|
|
\n\
|
|
echo "Build completed successfully!"\n\
|
|
' > /go/bin/build.sh && chmod +x /go/bin/build.sh
|
|
|
|
# ============================================================================
|
|
# COPY SOURCE CODE (AFTER DEPENDENCIES)
|
|
# ============================================================================
|
|
# Copy all source code
|
|
COPY . .
|
|
|
|
# ============================================================================
|
|
# SET UP CONTINUOUS DEVELOPMENT ENVIRONMENT
|
|
# ============================================================================
|
|
# Use CompileDaemon with simpler configuration
|
|
# Automatically builds and starts the daemon with auto-migration
|
|
# Exclude the binary to prevent infinite rebuild loops
|
|
ENTRYPOINT ["CompileDaemon", "-polling=true", "-log-prefix=false", "-build=/go/bin/build.sh", "-command=./maplefile-backend daemon", "-directory=./", "-exclude-dir=.git", "-exclude=maplefile-backend"]
|