diff --git a/Dockerfile b/Dockerfile index cf7e0a3..e77d422 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,55 +1,44 @@ -# Build stage +# Stage 1: Build the Go application FROM golang:1.24-alpine AS builder -WORKDIR /app +# Install git and certificates +RUN apk add --no-cache git ca-certificates -# Install build dependencies -RUN apk add --no-cache git ca-certificates tzdata && \ - update-ca-certificates +# Set working directory +WORKDIR /app -# Copy go mod and sum files +# Copy go.mod and go.sum, and download dependencies COPY go.mod go.sum ./ - -# Download dependencies RUN go mod download -# Copy source code +# Copy all source code COPY . . -# Build the application with optimizations -RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \ - -ldflags="-w -s -X main.version=$(git describe --tags --always) -X main.buildTime=$(date +%FT%T%z)" \ - -o /app/bin/liveclass ./cmd/api +# Build the application +RUN go build -o liveclass main.go -# Final stage +# Stage 2: Create a minimal runtime container FROM alpine:latest -# Add non-root user -RUN addgroup -S app && adduser -S app -G app - -# Install runtime dependencies -RUN apk add --no-cache ca-certificates tzdata - -# Copy binary from builder -COPY --from=builder /app/bin/liveclass /app/liveclass - -# Copy web assets and configs -COPY --from=builder /app/web /app/web -COPY --from=builder /app/configs /app/configs +# Install certificates (required for HTTPS requests) +RUN apk --no-cache add ca-certificates # Set working directory WORKDIR /app -# Use non-root user -USER app +# Copy binary from builder +COPY --from=builder /app/liveclass . -# Set environment variables -ENV GO_ENV=production \ - TZ=UTC +# Copy templates and any other needed directories +COPY --from=builder /app/template ./template +COPY --from=builder /app/configs ./configs +COPY --from=builder /app/migrations ./migrations -# Expose port -EXPOSE 8080 +# (Optional) Copy static folders if you serve static assets like CSS/JS +# COPY --from=builder /app/static ./static -# Run the application -CMD ["/app/liveclass"] +# Expose the port the app runs on +EXPOSE 8080 +# Run the binary +CMD ["./liveclass"] diff --git a/app/auth/google.go b/app/auth/google.go index 93781b5..5cf39d0 100644 --- a/app/auth/google.go +++ b/app/auth/google.go @@ -4,6 +4,7 @@ import ( "context" "encoding/gob" "encoding/json" + "fmt" "net/http" "github.com/CHINMAYVIVEK/liveClass/configs" @@ -78,15 +79,16 @@ func (a *OAuth) OAuthCallbackHandler(w http.ResponseWriter, r *http.Request) { http.Error(w, err.Error(), http.StatusInternalServerError) return } - // user := UserInfo{ - // ID: jsonResp.Id, - // Email: jsonResp.Email, - // FirstName: jsonResp.GivenName, - // LastName: jsonResp.FamilyName, - // Picture: jsonResp.Picture, - // Locale: jsonResp.Locale, - // } + user := UserInfo{ + ID: jsonResp.Id, + Email: jsonResp.Email, + FirstName: jsonResp.GivenName, + LastName: jsonResp.FamilyName, + Picture: jsonResp.Picture, + Locale: jsonResp.Locale, + } + fmt.Printf("userInfo :==>>v ", user) // Store user data in session http.Redirect(w, r, "/student/dashboard", http.StatusTemporaryRedirect) diff --git a/app/website/courses.go b/app/website/courses.go index b8a567f..9953b83 100644 --- a/app/website/courses.go +++ b/app/website/courses.go @@ -34,7 +34,7 @@ func (r *WebRepository) GetCourses(page, limit string) ([]Course, error) { ctx := context.Background() query := fmt.Sprintf(` - SELECT + SELECT c.course_id, c.title, c.description, @@ -63,7 +63,7 @@ func (r *WebRepository) GetCourses(page, limit string) ([]Course, error) { var course Course typeID := "" typeName := "" - err := rows.Scan( + scanErr := rows.Scan( &course.CourseID, &course.Title, &course.Description, @@ -75,9 +75,9 @@ func (r *WebRepository) GetCourses(page, limit string) ([]Course, error) { &typeID, &typeName, ) - if err != nil { - logger.Error(err) - return nil, fmt.Errorf("failed to scan course: %w", err) + if scanErr != nil { + logger.Error(scanErr) + return nil, fmt.Errorf("failed to scan course: %w", scanErr) } course.CourseType = CourseType{ CourseTypeID: typeID, diff --git a/app/website/web_repository.go b/app/website/web_repository.go index 2aad252..94fd825 100644 --- a/app/website/web_repository.go +++ b/app/website/web_repository.go @@ -17,7 +17,7 @@ func NewRepository(db *helper.PostgresWrapper) *WebRepository { func (r *WebRepository) GetInstructors(page, limit string) ([]Instructors, error) { var ( - limitClause = "8" // default limit + limitClause = "4" // default limit currentPage = "1" // default page offset int ) diff --git a/docker-compose.yml b/docker-compose.yml index 72ae93c..0e037a3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -7,18 +7,20 @@ services: dockerfile: Dockerfile ports: - "8080:8080" - environment: - - LIVECLASS_ENVIRONMENT=production - - LIVECLASS_SERVER_PORT=8080 - - LIVECLASS_DATABASE_HOST=db - - LIVECLASS_DATABASE_PORT=5432 - - LIVECLASS_DATABASE_USER=postgres - - LIVECLASS_DATABASE_PASSWORD=postgres - - LIVECLASS_DATABASE_NAME=liveclass - - LIVECLASS_DATABASE_SSLMODE=disable - - LIVECLASS_LOGGING_LEVEL=info - depends_on: - - db + env_file: + - .env + # environment: + # - LIVECLASS_ENVIRONMENT=production + # - LIVECLASS_SERVER_PORT=8080 + # - LIVECLASS_DATABASE_HOST=db + # - LIVECLASS_DATABASE_PORT=5432 + # - LIVECLASS_DATABASE_USER=postgres + # - LIVECLASS_DATABASE_PASSWORD=postgres + # - LIVECLASS_DATABASE_NAME=liveclass + # - LIVECLASS_DATABASE_SSLMODE=disable + # - LIVECLASS_LOGGING_LEVEL=info + # depends_on: + # - db restart: unless-stopped networks: - app-network @@ -29,41 +31,41 @@ services: retries: 3 start_period: 10s - db: - image: postgres:13-alpine - environment: - - POSTGRES_USER=postgres - - POSTGRES_PASSWORD=postgres - - POSTGRES_DB=liveclass - ports: - - "5432:5432" - volumes: - - postgres_data:/var/lib/postgresql/data - - ./migrations/init.sql:/docker-entrypoint-initdb.d/init.sql - networks: - - app-network - restart: unless-stopped - healthcheck: - test: ["CMD-SHELL", "pg_isready -U postgres"] - interval: 10s - timeout: 5s - retries: 5 +# db: +# image: postgres:13-alpine +# environment: +# - POSTGRES_USER=postgres +# - POSTGRES_PASSWORD=postgres +# - POSTGRES_DB=liveclass +# ports: +# - "5432:5432" +# volumes: +# - postgres_data:/var/lib/postgresql/data +# - ./migrations/init.sql:/docker-entrypoint-initdb.d/init.sql +# networks: +# - app-network +# restart: unless-stopped +# healthcheck: +# test: ["CMD-SHELL", "pg_isready -U postgres"] +# interval: 10s +# timeout: 5s +# retries: 5 - redis: - image: redis:alpine - ports: - - "6379:6379" - networks: - - app-network - restart: unless-stopped - healthcheck: - test: ["CMD", "redis-cli", "ping"] - interval: 10s - timeout: 5s - retries: 5 +# redis: +# image: redis:alpine +# ports: +# - "6379:6379" +# networks: +# - app-network +# restart: unless-stopped +# healthcheck: +# test: ["CMD", "redis-cli", "ping"] +# interval: 10s +# timeout: 5s +# retries: 5 -volumes: - postgres_data: +# volumes: +# postgres_data: networks: app-network: