Skip to content

Commit

Permalink
Introduce Containerization
Browse files Browse the repository at this point in the history
This patch adds a Dockerfile for pyCA and introduces some docker-compose
examples with different databases.

Co-authored-by: Lars Kiesow <lkiesow@uos.de>
  • Loading branch information
mtneug and lkiesow committed Feb 10, 2021
1 parent 43e44a7 commit a5f98b6
Show file tree
Hide file tree
Showing 7 changed files with 224 additions and 1 deletion.
16 changes: 16 additions & 0 deletions .dockerignore
@@ -0,0 +1,16 @@
.git
Dockerfile
venv
*.pyc
*.pyo
*.swp
build/
*.egg-info/
node_modules/
/pyca/ui/static/
.cache/
dist/
/recordings/*
.coverage
pyca.db
.vscode/
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -13,6 +13,7 @@ node_modules/
dist/

/recordings/*
/init/container/pyca.conf

.coverage
pyca.db
Expand Down
73 changes: 73 additions & 0 deletions Dockerfile
@@ -0,0 +1,73 @@
FROM alpine:3.13 AS build

RUN apk --no-cache add \
curl-dev \
gcc \
linux-headers \
make \
musl-dev \
nodejs \
npm \
py3-pip \
python3 \
python3-dev \
util-linux \
&& ln -s /usr/bin/python3 /usr/bin/python

WORKDIR /usr/local/src

COPY requirements.txt package.json package-lock.json ./
RUN pip install -r requirements.txt \
&& npm i

COPY . .
RUN make pypi

FROM alpine:3.13
LABEL maintainer="pyCA team"

ENV FFMPEG_VERSION="20200918044515-N-99257-g01506c290a"

COPY --from=build /usr/local/src/dist/pyca-*.tar.gz /tmp/pyca.tar.gz

RUN apk --no-cache --virtual .run-deps add \
libcurl \
postgresql-libs \
py3-pip \
python3 \
&& apk --no-cache --virtual .build-deps add \
curl \
curl-dev \
gcc \
linux-headers \
make \
musl-dev \
postgresql-dev \
python3-dev \
tar \
xz \
&& ln -s /usr/bin/python3 /usr/bin/python \
&& pip install \
/tmp/pyca.tar.gz \
gunicorn \
psycopg2 \
&& cd /usr/local/bin \
&& curl -sSL "https://pkg.opencast.org/bin/ffmpeg/ffmpeg-${FFMPEG_VERSION}.tar.xz" \
| tar xJf - --strip-components 1 --wildcards '*/ffmpeg' '*/ffprobe' \
&& apk del .build-deps \
&& rm -rf /tmp/pyca.tar.gz

RUN addgroup -S -g 800 pyca \
&& adduser -S -D -h /var/lib/pyca -G pyca -u 800 pyca \
&& addgroup pyca audio \
&& addgroup pyca video

COPY etc/pyca.conf etc/gunicorn.conf.py /etc/pyca/
RUN echo 'bind = "0.0.0.0:8000"' >> /etc/pyca/gunicorn.conf.py

WORKDIR /var/lib/pyca
USER pyca
VOLUME [ "/var/lib/pyca" ]
EXPOSE 8000

ENTRYPOINT [ "pyca" ]
7 changes: 6 additions & 1 deletion Makefile
@@ -1,5 +1,7 @@
all: lint test

export DOCKER_BUILDKIT=1

lint:
@flake8 $$(find pyca tests -name '*.py')
@npm run eslint
Expand All @@ -16,8 +18,11 @@ pypi: clean build
@python setup.py sdist
@printf "\nUpload to PyPI with \"twine upload dist/$$(python setup.py --fullname).tar.gz\"\n"

docker:
@docker build -t quay.io/opencast/pyca .

clean:
@python setup.py clean --all
@rm -rf node_modules pyca/ui/static

PHONY: all lint test build pypi clean
PHONY: all lint test build pypi docker clean
23 changes: 23 additions & 0 deletions init/container/README.rst
@@ -0,0 +1,23 @@
PyCA Container Images
=====================

This directory contains example docker-compose files for various scenarios.

PyCA + SQLite
-------------

.. code-block:: bash
cp etc/pyca.conf init/container/pyca.conf
sed -i "s|#name .*|name = pyca-container|g" init/container/pyca.conf
docker-compose -f init/container/docker-compose.sqlite.yml up
PyCA + PostgreSQL
-------------

.. code-block:: bash
cp etc/pyca.conf init/container/pyca.conf
sed -i "s|#name .*|name = pyca-container|g" init/container/pyca.conf
sed -i "s|#database .*|database = postgresql://pyca:pyca@database/pyca|g" init/container/pyca.conf
docker-compose -f init/container/docker-compose.postgres.yml up
58 changes: 58 additions & 0 deletions init/container/docker-compose.postgres.yml
@@ -0,0 +1,58 @@
version: '3'

volumes:
pyca: {}
database: {}

services:
pyca-schedule:
command: schedule
image: quay.io/opencast/pyca
restart: always
volumes:
- ./pyca.conf:/etc/pyca/pyca.conf:ro
- pyca:/var/lib/pyca

pyca-ingest:
command: ingest
image: quay.io/opencast/pyca
restart: always
volumes:
- ./pyca.conf:/etc/pyca/pyca.conf:ro
- pyca:/var/lib/pyca

pyca-capture:
command: capture
image: quay.io/opencast/pyca
restart: always
volumes:
- ./pyca.conf:/etc/pyca/pyca.conf:ro
- pyca:/var/lib/pyca

pyca-agentstate:
command: agentstate
image: quay.io/opencast/pyca
restart: always
volumes:
- ./pyca.conf:/etc/pyca/pyca.conf:ro
- pyca:/var/lib/pyca

pyca-ui:
entrypoint: ["gunicorn", "--config=/etc/pyca/gunicorn.conf.py", "pyca.ui:app"]
image: quay.io/opencast/pyca
restart: always
volumes:
- ./pyca.conf:/etc/pyca/pyca.conf:ro
- pyca:/var/lib/pyca
ports:
- "8000:8000"

database:
image: postgres:12.3
restart: always
environment:
- POSTGRES_PASSWORD=pyca
- POSTGRES_USER=pyca
- POSTGRES_DB=pyca
volumes:
- database:/var/lib/postgresql/data
47 changes: 47 additions & 0 deletions init/container/docker-compose.sqlite.yml
@@ -0,0 +1,47 @@
version: '3'

volumes:
pyca: {}

services:
pyca-schedule:
command: schedule
image: quay.io/opencast/pyca
restart: always
volumes:
- ./pyca.conf:/etc/pyca/pyca.conf:ro
- pyca:/var/lib/pyca

pyca-ingest:
command: ingest
image: quay.io/opencast/pyca
restart: always
volumes:
- ./pyca.conf:/etc/pyca/pyca.conf:ro
- pyca:/var/lib/pyca

pyca-capture:
command: capture
image: quay.io/opencast/pyca
restart: always
volumes:
- ./pyca.conf:/etc/pyca/pyca.conf:ro
- pyca:/var/lib/pyca

pyca-agentstate:
command: agentstate
image: quay.io/opencast/pyca
restart: always
volumes:
- ./pyca.conf:/etc/pyca/pyca.conf:ro
- pyca:/var/lib/pyca

pyca-ui:
entrypoint: ["gunicorn", "--config=/etc/pyca/gunicorn.conf.py", "pyca.ui:app"]
image: quay.io/opencast/pyca
restart: always
volumes:
- ./pyca.conf:/etc/pyca/pyca.conf:ro
- pyca:/var/lib/pyca
ports:
- "8000:8000"

0 comments on commit a5f98b6

Please sign in to comment.