diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..9e520788 --- /dev/null +++ b/.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/ diff --git a/.gitignore b/.gitignore index 3f581a07..fb65df67 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,7 @@ node_modules/ dist/ /recordings/* +/init/container/pyca.conf .coverage pyca.db diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..8014deca --- /dev/null +++ b/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" ] diff --git a/Makefile b/Makefile index 7ba735dd..363340e8 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,7 @@ all: lint test +export DOCKER_BUILDKIT=1 + lint: @flake8 $$(find pyca tests -name '*.py') @npm run eslint @@ -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 diff --git a/init/container/README.rst b/init/container/README.rst new file mode 100644 index 00000000..aefc4fa7 --- /dev/null +++ b/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 diff --git a/init/container/docker-compose.postgres.yml b/init/container/docker-compose.postgres.yml new file mode 100644 index 00000000..63c4ffa2 --- /dev/null +++ b/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 diff --git a/init/container/docker-compose.sqlite.yml b/init/container/docker-compose.sqlite.yml new file mode 100644 index 00000000..1052ab7c --- /dev/null +++ b/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"