schej-it / schej.it

schej helps you quickly find the best time for your group to meet. It's like When2meet with Google Calendar integration!
https://schej.it
GNU General Public License v3.0
240 stars 26 forks source link

🚀 Feature Request: A docker-compose file to deploy this amazing project with ease #118

Open gambit-dross opened 3 weeks ago

ppfeister commented 1 week ago

Not being available on Dockerhub or ghcr is the only thing holding me back from even trying it self hosted --- would be great to see

athamour1 commented 1 week ago

Hey, I can help with this feature ! Contact me to start with the docker implementation

athamour1 commented 6 days ago

Upon further inspection it should be straight forward to add the docker implementation with the following files

This is for the backend

# Stage 1: Build the Go server
FROM golang:1.20-alpine AS build

# Set working directory
WORKDIR /app

# Copy the Go module files and download dependencies
COPY server/go.mod server/go.sum ./
RUN go mod download

# Copy the rest of the server source code
COPY server/ .

# Build the Go server for Linux
RUN GOOS=linux GOARCH=amd64 go build -o server -buildvcs=false

# Stage 2: Run the server with a minimal image
FROM alpine:latest

# Set working directory
WORKDIR /app

# Copy the server binary from the build stage
COPY --from=build /app/server .

# Expose the port your server runs on (adjust if needed)
EXPOSE 8080

# Start the server
CMD ["./server", "-release=true"]

This is for the frontend

# Stage 1: Build the frontend
FROM node:18-alpine AS build

# Set working directory
WORKDIR /app

# Copy package files and install dependencies
COPY frontend/package.json frontend/package-lock.json ./
RUN npm install

# Copy the frontend source code
COPY frontend/ .

# Build the frontend
RUN npm run build

# Stage 2: Serve the frontend with Nginx
FROM nginx:alpine

# Define where Nginx will serve the files from
COPY --from=build /app/dist /usr/share/nginx/html

# Expose the default port used by Nginx
EXPOSE 80

# Start Nginx
CMD ["nginx", "-g", "daemon off;"]

And this is to orchestrate the deployment, i also added the mongo db service, if it needs anything else to run, it can be added here.

services:
  frontend:
    build:
      context: .
      dockerfile: Dockerfile.frontend  # Use Dockerfile.frontend for the frontend build
    ports:
      - "80:80"  # Map port 80 of the container to port 80 on the host
    # env_file:
    #   - ./frontend/.env  # Path to the frontend .env file
    networks:
      - app-network

  backend:
    build:
      context: .
      dockerfile: Dockerfile.backend  # Use Dockerfile.backend for the backend build
    ports:
      - "8080:8080"  # Map port 8080 of the container to port 8080 on the host
    # env_file:
    #  - ./server/.env  # Path to the backend .env file
    environment:
      - MONGO_URI=mongodb://mongo:27017/your_database_name  # MongoDB URI for backend connection
    networks:
      - app-network
    depends_on:
      - mongo  # Ensure MongoDB starts before backend
    restart: always

  mongo:
    image: mongo:6.0  # MongoDB image
    container_name: mongo  # Container name for easy reference
    ports:
      - "27017:27017"  # Expose MongoDB's default port
    networks:
      - app-network
    volumes:
      - mongo_data:/data/db  # Persist MongoDB data on a Docker volume

networks:
  app-network:
    driver: bridge

volumes:
  mongo_data:

The only problem I found is with some ENV vars, like mongo db URL, it should be set by an env var to route it to the correct container.