diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..5e1e1c9 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,38 @@ +# Git +.git +.gitignore +.gitattributes + +# Documentation +README.md +*.md + +# IDE +.vscode +.idea +*.swp +*.swo +*~ + +# Build artifacts +backend/main +*.exe + +# Logs +*.log + +# OS files +.DS_Store +Thumbs.db + +# Node modules (if any) +node_modules + +# Test files +*_test.go + +# Bruno API client +backend/API-Projet-CAL + +# Makefile +Makefile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..af3e3fd --- /dev/null +++ b/Dockerfile @@ -0,0 +1,46 @@ +# Multi-stage build for optimized image size +FROM golang:1.23-alpine AS backend-builder + +# Install build dependencies +RUN apk add --no-cache git + +# Set working directory for backend +WORKDIR /app/backend + +# Copy go mod files +COPY backend/go.mod backend/go.sum ./ + +# Download dependencies +RUN go mod download + +# Copy backend source code +COPY backend/ ./ + +# Build the application +RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o main . + +# Final stage - minimal image +FROM alpine:latest + +# Install ca-certificates for HTTPS requests +RUN apk --no-cache add ca-certificates tzdata + +# Set timezone (adjust as needed) +ENV TZ=Europe/Paris + +WORKDIR /app + +# Copy the built binary from builder +COPY --from=backend-builder /app/backend/main . + +# Copy frontend files +COPY frontend/ ./frontend/ + +# Copy backend data file +COPY backend/date_link.txt ./ + +# Expose port +EXPOSE 8080 + +# Run the application +CMD ["./main"] diff --git a/backend/.env.example b/backend/.env.example new file mode 100644 index 0000000..2734d84 --- /dev/null +++ b/backend/.env.example @@ -0,0 +1 @@ +FILE_NAME=date_link.txt diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..9b101c5 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,17 @@ +version: "3.8" + +services: + calendrier-avent: + build: + context: . + dockerfile: Dockerfile + container_name: calendrier-avent-isen + ports: + - "8080:8080" + environment: + - FILE_NAME=date_link.txt + - GIN_MODE=release + volumes: + # Mount date_link.txt so you can update it without rebuilding + - ./backend/date_link.txt:/app/date_link.txt:ro + restart: unless-stopped diff --git a/frontend/index.html b/frontend/index.html index f215b2b..cd1cd17 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -1,19 +1,44 @@ +