diff --git a/Dockerfile b/Dockerfile index d754a7d..312a434 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,35 +1,35 @@ -FROM debian:buster-slim - -LABEL author="Fabian Hintringer" \ - name="reminder-bot" \ - version=1.0.0 - -ARG REDIS_PORT \ - REDIS_HOST \ - REDIS_PASSWORD - -ENV REDIS_HOST=$REDIS_HOST \ - REDIS_PORT=$REDIS_PORT \ - REDIS_PASSWORD=${REDIS_PASSWORD} - -RUN mkdir -p /var/reminder-bot - -COPY ./ /var/reminder-bot/ - -RUN cd /var/reminder-bot \ - && apt-get update \ - && apt-get upgrade -y \ - && apt-get install curl unzip -y \ - && curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash \ - && export NVM_DIR="$HOME/.nvm" \ - && [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" \ - && [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" \ - && nvm install 14.4.0 -y\ - && apt-get update \ - && apt-get install npm -y\ - && npm install -g npm@7.20.0 \ - && npm install --global yarn --no-optionals -y \ - && yarn install \ - && chmod +x /var/reminder-bot/entrypoint.sh - -ENTRYPOINT /var/reminder-bot/entrypoint.sh ${REDIS_HOST} ${REDIS_PORT} ${REDIS_PASSWORD} +# Use a Node.js base image +FROM node:20-alpine as builder + +# Set the working directory in the container +WORKDIR /app + +# Copy package management files +COPY package.json yarn.lock ./ + +# Install all dependencies (including devDependencies for building) +RUN yarn install + +# Copy the rest of your application's source code +COPY . . + +# Compile TypeScript to JavaScript +RUN yarn build + +# Start a new stage from scratch for a smaller final image +FROM node:20-alpine + +WORKDIR /app + +# Copy package management files +COPY package.json yarn.lock ./ + +# Install only production dependencies +RUN yarn install --production + +# Copy built JavaScript files and any other necessary files from the builder stage +COPY --from=builder /app/dist ./dist +COPY . . + +# Your application's default command +CMD ["yarn", "start"] diff --git a/docker-compose.yml b/docker-compose.yml index 705b689..543547e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -12,18 +12,26 @@ services: exec redis-server --requirepass ${REDIS_PASSWORD} volumes: - ${DOCKER_REDIS_VOLUME}/:/data:rw - ports: - - ${REDIS_PORT}:6379 + # if that does not work use + # ./data:/data:rw + reminder-bot: - build: - context: . - dockerfile: Dockerfile - args: + # optionally pre-build the image + # image: reminder-bot:2024.02.19 + environment: - REDIS_PORT=${REDIS_PORT} - REDIS_HOST=${REDIS_HOST} - REDIS_PASSWORD=${REDIS_PASSWORD} + # optionally: mount the zuliprc file. First create a volume "reminder-bot_data" and store the file there (or use ./path/to/file) + # volumes: + # - /var/lib/docker/volumes/reminder-bot_data/_data/zuliprc:/app/zuliprc:ro + build: + context: . + dockerfile: Dockerfile container_name: reminder-bot restart: unless-stopped depends_on: - redis-db +volumes: + data: diff --git a/package.json b/package.json index c8568b1..afe68c7 100644 --- a/package.json +++ b/package.json @@ -5,12 +5,12 @@ "license": "MIT", "devDependencies": { "@types/node": "^14.6.0", - "chrono-node": "^2.3.0", "nodemon": "^2.0", "ts-node": "^10", "typescript": "^4.2" }, "dependencies": { + "chrono-node": "^2.3.0", "handy-redis": "^2.2.1", "redis": "^3.1.2", "timezone-support": "^2.0.2",