Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minify image, optimize build and docker-compose.yml #16

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
70 changes: 35 additions & 35 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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 [email protected] \
&& 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"]
20 changes: 14 additions & 6 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down