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

add Dockerfile & docker-compose.yml #242

Merged
merged 1 commit into from
Aug 26, 2023
Merged
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
6 changes: 6 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# configuration shouldn't be baked into the image
kippo.cfg
log
data
dl
db/mysql/data/*
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ __pycache__/
env/
env1/
env2/
db/mysql/data/*
54 changes: 54 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
FROM alpine:3.15

VOLUME /app/data /app/log /app/dl /app/kippo.cfg

# Create a non-root user and switch to it
RUN adduser -D -H -g '' app
USER app

# Set the working directory in the container to /app
WORKDIR /app

# Copy the current directory contents into the container at /app
COPY . /app

# Switch back to root to install dependencies
USER root

RUN apk --update-cache add \
python2 \
mariadb-connector-c \
# build-dependencies can be removed at the end to save space
&& apk --update-cache add --virtual build-dependencies \
git \
python2-dev \
musl-dev \
gcc \
mariadb-connector-c-dev \
# hack to make the MySQL-python build succeed
&& wget -q https://raw.githubusercontent.com/paulfitz/mysql-connector-c/8c058fab669d61a14ec23c714e09c8dfd3ec08cd/include/my_config.h -O /usr/include/mysql/my_config.h \
&& sed '/st_mysql_options options;/a unsigned int reconnect;' /usr/include/mysql/mysql.h -i.bkp \
# pip doesn't seem to be available via apk
&& python -m ensurepip --upgrade \
# basic kippo dependencies, including optional MySQL-python
&& pip install --no-cache-dir \
zope.interface==5.5.2 \
Twisted==15.1.0 \
pycrypto==2.6.1 \
pyasn1==0.5.0 \
MySQL-python==1.2.5 \
# dependencies for XMPP support, needs this ancient custom branch
&& pip install --no-cache-dir \
git+https://github.com/ralphm/wokkel/@e0a70e4b5d03a2c1c911bb2bdf5c3ef717049707 \
python-dateutil==2.8.2 \
# clean up
&& apk del build-dependencies

# Switch back to the non-root user
USER app

# Make port 2222 available to the world outside thiscontainer
EXPOSE 2222

# Run twistd command when the container launches
CMD ["twistd", "-n", "-y", "kippo.tac", "--pidfile", "kippo.pid"]
Empty file added db/mysql/data/.gitkeep
Empty file.
9 changes: 9 additions & 0 deletions db/mysql/docker-initdb.d/docker-initdb.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh

set -e

MYSQL="mariadb -u root -p$MARIADB_ROOT_PASSWORD"

echo "GRANT ALL PRIVILEGES ON $MARIADB_DATABASE.* TO $MARIADB_USER;" | $MYSQL

$MYSQL "$MARIADB_DATABASE" < /sql-scripts/mysql.sql
42 changes: 42 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# To run the kippo service, run:
# docker-compose up
#
# The database service belongs to the "with-db" profile, so it's not run by
# default. To run the kippo service with the database service, run:
# docker-compose --profile with-db up
#
version: '3'

services:
kippo:
image: kippo
build:
context: .
dockerfile: ./Dockerfile
container_name: kippo
restart: unless-stopped
ports:
- "2222:2222"
# logs and configuration should be kept outside the image
volumes:
- ./log:/app/log
- ./dl:/app/dl
- ./data:/app/data
- ./kippo.cfg:/app/kippo.cfg
kippodb:
image: mariadb
container_name: kippodb
environment:
MYSQL_ROOT_PASSWORD: rootpw
MYSQL_DATABASE: kippo
MYSQL_USER: kippo
MYSQL_PASSWORD: kippopw
volumes:
- ./db/mysql/data:/var/lib/mysql
- ./db/mysql/docker-initdb.d:/docker-entrypoint-initdb.d
- ./doc/sql:/sql-scripts
profiles:
- with-db

# ports:
# - "3306:3306"
4 changes: 2 additions & 2 deletions kippo.cfg.dist
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,10 @@ interact_port = 5123
# [database_mysql] line.

#[database_mysql]
#host = localhost
#host = kippodb
#database = kippo
#username = kippo
#password = secret
#password = kippopw
#port = 3306

# XMPP Logging
Expand Down