Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 24 additions & 35 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
18 changes: 10 additions & 8 deletions app/auth/google.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"context"
"encoding/gob"
"encoding/json"
"fmt"
"net/http"

"github.com/CHINMAYVIVEK/liveClass/configs"
Expand Down Expand Up @@ -78,15 +79,16 @@
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)

Check failure on line 91 in app/auth/google.go

View workflow job for this annotation

GitHub Actions / build

fmt.Printf call has arguments but no formatting directives
// Store user data in session

http.Redirect(w, r, "/student/dashboard", http.StatusTemporaryRedirect)
Expand Down
10 changes: 5 additions & 5 deletions app/website/courses.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion app/website/web_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
92 changes: 47 additions & 45 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
Loading