diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..0a4bca2 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,22 @@ +# Generated files +**/__pycache__ +tags +/.cache/ +.idea/ +env +venv/ +.venv/ +**/*.py[cod] + +**/*.db +**/repo +**/data + +.git +.gitignore +.gitattributes + +# Editor and other backup files +**/*.swp +**/*~ +**/~* diff --git a/README.adoc b/README.adoc index 1f4315c..2f53b75 100644 --- a/README.adoc +++ b/README.adoc @@ -357,20 +357,50 @@ where all repositories are found. = Building Docker images -Docker files are provided in the `docker/` directory. To generate a Docker image -for indexing the sources of a project, first fetch the Elixir repository. Then -pick the project you want to index (Musl is nice test data being not too slow -to index) and your target distribution (`debian` currently), and -run: +Dockerfiles are provided in the `docker/` directory. To build the image, run the following commands: - $ docker build -t elixir-debian --build-arg GIT_REPO_URL=git://git.musl-libc.org/musl --build-arg PROJECT=musl ./docker/debian/ + # git clone https://github.com/bootlin/elixir.git ./elixir + # docker build -t elixir -f ./elixir/docker/Dockerfile ./elixir -Then you can use your new container as follows (you get the container id from the output of `docker build`): +You can then run the image using `docker run`. +It is recommended to mount a volume or a host directory into the Elixir data directory. +This allows you to easily replace the container with a new version without losing indexing data. - $ docker run + # mkdir ./elixir-data + # docker run -v ./elixir-data/:/srv/elixir-data -d --name elixir-container elixir -You can the open the below URL in a browser on your host: http://172.17.0.2/musl/latest/source -(change the container IP address if you don't get the default one) +The Docker image does not contain any repositories. To index a repository, you can use a utility script - index-repository. +For example, to add musl repository, run: + + # docker exec -it elixir-container /usr/local/elixir/utils/index-repository musl https://git.musl-libc.org/git/musl + +Or, to run indexing in a separate container: + + # docker run -v ./elixir-data/:/srv/elixir-data --entrypoint /usr/local/elixir/utils/index-repository elixir musl https://git.musl-libc.org/git/musl + +You can also use utils/index-all-repositories to start indexing all officially supported repositories. + +After indexing is done, Elixir should be available under the following URL on your host: +http://172.17.0.2/musl/latest/source + +If 172.17.0.2 does not answer, you can check the IP address of the container by running: + + # docker inspect elixir-container | grep IPAddress + +== Automatic repository updates + +The Docker image does not automatically update repositories by itself. +You can, for example, start `utils/update-elixir-data` in the container (or in a separate container, with Elixir data volume/directory mounted) +from cron on the host to periodically update repositories. + +== Using Docker image as a development server + +You can easily use the Docker image as a development server by following the steps above, but mounting Elixir source directory from the host +into `/usr/local/elixir/` in the container when running `docker run elixir`. + +Changes in the code made on the host should be automatically reflected in the container. +You can use `apache2ctl` to restart Apache. +Error logs are available in `/var/log/apache2/error.log` and `/tmp/elixir-errors` within the container. = Hardware requirements diff --git a/docker/debian/000-default.conf b/docker/000-default.conf similarity index 100% rename from docker/debian/000-default.conf rename to docker/000-default.conf diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000..3e41403 --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,41 @@ +FROM debian:bookworm + +RUN \ + apt-get update && \ + apt-get --no-install-recommends -y install \ + python3 \ + python3-pip \ + python3-falcon \ + python3-jinja2 \ + python3-bsddb3 \ + python3-pytest \ + python3-pygments \ + perl \ + git \ + apache2 \ + libapache2-mod-wsgi-py3 \ + libjansson4 \ + libyaml-0-2 \ + wget + +RUN \ + wget https://bootlin.com/pub/elixir/universal-ctags_0+git20200526-0ubuntu1_amd64.deb + +RUN \ + dpkg -i universal-ctags_0+git20200526-0ubuntu1_amd64.deb + +COPY . /usr/local/elixir/ + +RUN mkdir -p /srv/elixir-data/ + +# apache elixir config, see elixir README +# make apache less stricter about cgitb spam headers +COPY ./docker/000-default.conf /etc/apache2/sites-available/000-default.conf + +RUN \ + echo -e "\nHttpProtocolOptions Unsafe" >> /etc/apache2/apache.conf && \ + a2enmod cgi rewrite + +EXPOSE 80 + +ENTRYPOINT ["/usr/sbin/apache2ctl", "-D", "FOREGROUND"] diff --git a/docker/debian/Dockerfile b/docker/debian/Dockerfile deleted file mode 100644 index d5c0cc5..0000000 --- a/docker/debian/Dockerfile +++ /dev/null @@ -1,79 +0,0 @@ -FROM debian:bookworm -ARG GIT_REPO_URL -ARG PROJECT - -RUN \ - : "${GIT_REPO_URL:?set GIT_REPO_URL to the repo git url}" - -RUN \ - : "${PROJECT:?set PROJECT to set the project name}" - -RUN \ - echo "repo url to index: ${GIT_REPO_URL}" - - -RUN \ - apt-get update && \ - apt-get --no-install-recommends -y install \ - python3 \ - python3-pip \ - python3-falcon \ - python3-jinja2 \ - python3-bsddb3 \ - python3-pytest \ - python3-pygments- \ - pipx \ - perl \ - git \ - apache2 \ - libapache2-mod-wsgi-py3 \ - libjansson4 \ - libyaml-0-2 \ - wget - -RUN \ - wget https://bootlin.com/pub/elixir/universal-ctags_0+git20200526-0ubuntu1_amd64.deb - -RUN \ - dpkg -i universal-ctags_0+git20200526-0ubuntu1_amd64.deb - -RUN \ - wget https://bootlin.com/pub/elixir/Pygments-2.6.1.elixir-py3-none-any.whl - -RUN \ - pip3 install ./Pygments-2.6.1.elixir-py3-none-any.whl --break-system-packages - -RUN \ - git config --global user.email 'elixir@dummy.com' && \ - git config --global user.name 'elixir' - -RUN \ - git clone https://github.com/bootlin/elixir.git /usr/local/elixir/ - -RUN \ - mkdir -p /srv/elixir-data/ && \ - mkdir -p /srv/elixir-data/$PROJECT/repo && \ - mkdir -p /srv/elixir-data/$PROJECT/data && \ - git clone --bare "${GIT_REPO_URL}" /srv/elixir-data/$PROJECT/repo/ && \ - git config --global --add safe.directory /srv/elixir-data/$PROJECT/repo - -ENV LXR_REPO_DIR /srv/elixir-data/$PROJECT/repo -ENV LXR_DATA_DIR /srv/elixir-data/$PROJECT/data - -RUN \ - cd /usr/local/elixir/ && \ - ./script.sh list-tags && \ - python3 -u ./update.py && \ - chown -R www-data:www-data /srv/elixir-data/$PROJECT/repo - -# apache elixir config, see elixir README -# make apache less stricter about cgitb spam headers -COPY ./000-default.conf /etc/apache2/sites-available/000-default.conf - -RUN \ - echo -e "\nHttpProtocolOptions Unsafe" >> /etc/apache2/apache.conf && \ - a2enmod cgi rewrite - -EXPOSE 80 - -ENTRYPOINT ["/usr/sbin/apache2ctl", "-D", "FOREGROUND"] diff --git a/utils/index-repository b/utils/index-repository new file mode 100755 index 0000000..a73f0ef --- /dev/null +++ b/utils/index-repository @@ -0,0 +1,16 @@ +#!/bin/sh + +if [ "$#" -ne 2 ]; then + echo "Usage: $0 repo_name repo_url" + exit 1 +fi + +dir=/srv/elixir-data/$1 + +mkdir -p $dir/data +git clone --bare $2 $dir/repo +git config --system --add safe.directory $dir/repo + +export LXR_REPO_DIR=$dir/repo +export LXR_DATA_DIR=$dir/data +python3 /usr/local/elixir/update.py