diff --git a/.gitignore b/.gitignore index 54a8460..9496310 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /node_modules .ds_store -/dist \ No newline at end of file +/dist +*.rdb \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 9109764..773b444 100644 --- a/Dockerfile +++ b/Dockerfile @@ -28,12 +28,12 @@ RUN apk update # Install runtime dependencies including AWS CLI v2 RUN apk add --no-cache bash redis ghostscript graphicsmagick imagemagick libjpeg-turbo libpng libwebp tiff libheif libde265 x265 ffmpeg curl unzip gcompat tzdata -# Install AWS CLI v2 -RUN curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" && \ - unzip awscliv2.zip && \ - ./aws/install && \ - rm -rf awscliv2.zip aws/ && \ - aws --version +# # Install AWS CLI v2 +# RUN curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" && \ +# unzip awscliv2.zip && \ +# ./aws/install && \ +# rm -rf awscliv2.zip aws/ && \ +# aws --version RUN npm install -g pm2 diff --git a/Dockerfile.dev b/Dockerfile.dev new file mode 100644 index 0000000..6d91208 --- /dev/null +++ b/Dockerfile.dev @@ -0,0 +1,51 @@ +### ALPINE MULTI-STAGE +# Build stage for libraries +FROM node:22-alpine AS builder + +# Install build dependencies including AWS CLI v2 +RUN apk add --no-cache bash wget curl unzip gcompat +RUN curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" && \ + unzip awscliv2.zip && \ + ./aws/install && \ + rm -rf awscliv2.zip aws/ + +# Node.js application build stage +WORKDIR /usr/src/app +COPY package*.json ./ +RUN npm install -g typescript +RUN npm install + +COPY . . +RUN npm run build + +# Final stage +FROM node:22-alpine + +# Enable community repository for additional packages +RUN echo "https://dl-cdn.alpinelinux.org/alpine/v$(grep -oE '[0-9]+\.[0-9]+' /etc/alpine-release)/community" >> /etc/apk/repositories +RUN apk update + +# Install runtime dependencies including AWS CLI v2 +RUN apk add --no-cache bash redis ghostscript graphicsmagick imagemagick libjpeg-turbo libpng libwebp tiff libheif libde265 x265 ffmpeg curl unzip gcompat tzdata + +# Install AWS CLI v2 +# RUN curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" && \ +# unzip awscliv2.zip && \ +# ./aws/install && \ +# rm -rf awscliv2.zip aws/ && \ +# aws --version + +RUN npm install -g pm2 + +WORKDIR /usr/src/app + +# Copy built application from builder +COPY --from=builder /usr/src/app/dist ./dist +COPY ./assets /assets +COPY --from=builder /usr/src/app/node_modules ./node_modules +COPY --from=builder /usr/src/app/.env.production ./.env.production +COPY --from=builder /usr/src/app/ecosystem.config.cjs ./ecosystem.config.cjs + +EXPOSE 8000 + +CMD ["sh", "-c", "redis-server --daemonize yes && npm run server"] diff --git a/docker-compose.override.yml b/docker-compose.override.yml new file mode 100644 index 0000000..0cb7e83 --- /dev/null +++ b/docker-compose.override.yml @@ -0,0 +1,24 @@ +# Development override - automatically used by docker compose +# This file enables hot reloading and development features + +services: + ims: + build: + dockerfile: Dockerfile.dev + volumes: + # Mount source code for hot reloading + - .:/usr/src/app + - /usr/src/app/node_modules # Prevent overwriting node_modules + - "/Users/pfic/Desktop/IMS:/media" + - "./logs:/usr/src/app/logs" + environment: + - NODE_ENV=development + - PORT=8000 + - MEDIA_PATH=/media + - DUPLICATE_BILL_TO_VENDOR=false + - IMS_TOKEN= + - CONVERT_QUALITY=0.5 + - KEEP_CONVERTED_ORIGINALS=TRUE + # command: redis-server && npm run server # Use nodemon for hot reloading + stdin_open: true + tty: true \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 0d81fc2..b8b0da3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,12 +1,20 @@ -version: '2' +# Production configuration - use with docker-compose.override.yml for development +version: '3.8' services: ims: + build: + context: . + dockerfile: Dockerfile ports: - - 8000:8000 + - "8000:8000" + - "6379:6379" volumes: - "/Users/pfic/Desktop/IMS:/media" + - "./logs:/usr/src/app/logs" # Mount logs directory for persistence environment: + - NODE_ENV=production + - PORT=8000 - MEDIA_PATH=/media - DUPLICATE_BILL_TO_VENDOR=false - IMS_TOKEN= @@ -18,4 +26,10 @@ services: # - S3_ACCESS_KEY_ID=your-access-key-id # - S3_SECRET_ACCESS_KEY=your-secret-access-key # - S3_KEY_PREFIX=jobs/ - image: imexonline/media-server:beta \ No newline at end of file + restart: unless-stopped + healthcheck: + test: ["CMD", "curl", "-f", "http://localhost:8000/health"] + interval: 30s + timeout: 10s + retries: 3 + start_period: 40s \ No newline at end of file