From 9b0cee94dfee8c7c4b5820f76284e647b67d7961 Mon Sep 17 00:00:00 2001 From: Sven <34579211+sutidor@users.noreply.github.com> Date: Tue, 20 Feb 2024 00:27:08 +0100 Subject: [PATCH 1/4] rewrite alpine, environment instead of ARG --- Dockerfile | 43 +++++++++++++++---------------------------- 1 file changed, 15 insertions(+), 28 deletions(-) diff --git a/Dockerfile b/Dockerfile index d754a7d..135d3e7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,35 +1,22 @@ -FROM debian:buster-slim +FROM alpine:latest LABEL author="Fabian Hintringer" \ - name="reminder-bot" \ - version=1.0.0 + name="reminder-bot" \ + version="1.0.0" -ARG REDIS_PORT \ - REDIS_HOST \ - REDIS_PASSWORD +# Install dependencies, Node.js, and Yarn +RUN apk add --no-cache curl bash nodejs npm && npm install -g yarn -ENV REDIS_HOST=$REDIS_HOST \ - REDIS_PORT=$REDIS_PORT \ - REDIS_PASSWORD=${REDIS_PASSWORD} +# Set work directory and copy application code +WORKDIR /app +COPY . . -RUN mkdir -p /var/reminder-bot +# Install Node.js dependencies +RUN yarn install -COPY ./ /var/reminder-bot/ +# If you have an entrypoint script, ensure it's executable +# Uncomment the next line if your entrypoint script is used +# RUN chmod +x ./entrypoint.sh -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} +# Start the application +CMD ["yarn", "dev"] From e8c1cec92a975643c9350c3aa364472571010d18 Mon Sep 17 00:00:00 2001 From: Sven <34579211+sutidor@users.noreply.github.com> Date: Tue, 20 Feb 2024 00:35:25 +0100 Subject: [PATCH 2/4] patch redis data, add environments, add zuliprc --- docker-compose.yml | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) 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: From e0548afa749a1ee95766875c9e565cce04939271 Mon Sep 17 00:00:00 2001 From: Sven <34579211+sutidor@users.noreply.github.com> Date: Tue, 20 Feb 2024 01:09:54 +0100 Subject: [PATCH 3/4] chrono-node to dependencies --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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", From 70d643db53d0f11a42d9a79a7b67c3d2b7874d54 Mon Sep 17 00:00:00 2001 From: Sven <34579211+sutidor@users.noreply.github.com> Date: Tue, 20 Feb 2024 01:12:31 +0100 Subject: [PATCH 4/4] alpine, builder, production build --- Dockerfile | 43 ++++++++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/Dockerfile b/Dockerfile index 135d3e7..312a434 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,22 +1,35 @@ -FROM alpine:latest +# Use a Node.js base image +FROM node:20-alpine as builder -LABEL author="Fabian Hintringer" \ - name="reminder-bot" \ - version="1.0.0" +# Set the working directory in the container +WORKDIR /app -# Install dependencies, Node.js, and Yarn -RUN apk add --no-cache curl bash nodejs npm && npm install -g yarn +# Copy package management files +COPY package.json yarn.lock ./ -# Set work directory and copy application code -WORKDIR /app +# Install all dependencies (including devDependencies for building) +RUN yarn install + +# Copy the rest of your application's source code COPY . . -# Install Node.js dependencies -RUN yarn install +# Compile TypeScript to JavaScript +RUN yarn build + +# Start a new stage from scratch for a smaller final image +FROM node:20-alpine -# If you have an entrypoint script, ensure it's executable -# Uncomment the next line if your entrypoint script is used -# RUN chmod +x ./entrypoint.sh +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 . . -# Start the application -CMD ["yarn", "dev"] +# Your application's default command +CMD ["yarn", "start"]