diff --git a/README.md b/README.md index 53a97b423b..fde4c70a76 100644 --- a/README.md +++ b/README.md @@ -16,8 +16,8 @@ For more information visit our [web site](https://selfoss.aditu.de). 1. Upload all files of this folder (IMPORTANT: also upload the invisible .htaccess files) 2. Make the directories data/cache, data/favicons, data/logs, data/thumbnails and data/sqlite writeable 3. Insert database access data in config.ini (see below -- you don't have to change anything if you want to use sqlite) -3. You don't have to install the database, it will be created automatically (ensure that your database has enought rights for creating triggers) -4. Create cronjob for updating feeds and point it to https://yourselfossurl.com/update via wget or curl. You can also execute the cliupdate.php from commandline. +4. You don't have to install the database, it will be created automatically (ensure that your database has enought rights for creating triggers) +5. Create cronjob for updating feeds and point it to https://yourselfossurl.com/update via wget or curl. You can also execute the cliupdate.php from commandline. If you obtained selfoss using Git, some more steps will be required. See the [development](#development) section. @@ -77,6 +77,10 @@ If you want to create a package with all the dependencies bundled, you can run ` Every patch is expected to adhere to our coding style, which is checked automatically by Travis. You can install the checkers locally using `npm run install-dependencies`, and then run the checks using `npm run check` before submitting a pull request. There is also `npm run fix`, that will attempt to fix the formatting. +## Dockerizing selfoss + +For instructions how to use Selfoss inside docker container, both for production deployment and for development, see the separate [Readme](utils/docker/Readme.md). + ## Credits selfoss was created by [Tobias Zeising](tobias.zeising@aditu.de) and it is licensed under the GPLv3 license. diff --git a/package.json b/package.json index cfb550fad9..92ab47507a 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "fix:server": "composer run-script fix", "install-dependencies": "npm run install-dependencies:client && npm run install-dependencies:server", "install-dependencies:client": "npm install --production=false --prefix assets/", - "install-dependencies:server": "composer install --dev", + "install-dependencies:server": "composer install", "lint:client": "npm run --prefix assets/ lint", "lint:server": "composer run-script lint", "test:server": "composer run-script test", diff --git a/utils/docker/.env.dist b/utils/docker/.env.dist new file mode 100644 index 0000000000..32471050bc --- /dev/null +++ b/utils/docker/.env.dist @@ -0,0 +1,2 @@ +UID=1000 +GID=1000 diff --git a/utils/docker/Dockerfile b/utils/docker/Dockerfile new file mode 100644 index 0000000000..1a2b309d97 --- /dev/null +++ b/utils/docker/Dockerfile @@ -0,0 +1,31 @@ +FROM composer:1.9 as composer + +ADD . /selfoss + +RUN cd /selfoss && git reset HEAD && git checkout . && git clean -xdf && rm -fr .git \ + && composer install --ignore-platform-reqs --optimize-autoloader --no-dev + + + +FROM node:12-stretch as npm + +COPY --from=composer /selfoss /selfoss + +RUN cd /selfoss && npm i && npm install --prefix assets/ && npm run build + + + +FROM php:7.4-apache-buster + +COPY --from=npm /selfoss /var/www/html/ + +RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y libpng-dev \ + && docker-php-ext-install -j$(nproc) gd \ + && apt-get clean && rm -rf /var/lib/apt/lists/* + +WORKDIR /var/www/html/ + +RUN mkdir config && ln -s config/config.ini config.ini \ + && a2enmod rewrite + +CMD [ "/var/www/html/utils/docker/entrypoint.sh" ] diff --git a/utils/docker/Dockerfile.dev b/utils/docker/Dockerfile.dev new file mode 100644 index 0000000000..c2ccfee6ce --- /dev/null +++ b/utils/docker/Dockerfile.dev @@ -0,0 +1,30 @@ +FROM php:7.4-apache-buster + +# TODO: basically this image should be built on top of the production image +# replacing the source dir with mounted volume + +ARG gid +ARG uid + +RUN curl -sL https://deb.nodesource.com/setup_13.x | bash - \ + && DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y libpng-dev nodejs gcc g++ make unzip \ + && docker-php-ext-install -j$(nproc) gd \ + && apt-get clean && rm -rf /var/lib/apt/lists/* \ + && a2enmod rewrite + +RUN curl -o /tmp/composer-setup.php "https://getcomposer.org/installer"; \ + EXPECTED_SIGNATURE="$(curl https://composer.github.io/installer.sig)"; \ + ACTUAL_SIGNATURE="$(sha384sum /tmp/composer-setup.php | cut -d ' ' -f 1)"; \ + if [ "$EXPECTED_SIGNATURE" != "$ACTUAL_SIGNATURE" ]; then \ + >&2 echo 'ERROR: Invalid installer signature'; \ + rm /tmp/composer-setup.php && exit 1; \ + fi \ + && php /tmp/composer-setup.php --install-dir=/bin --filename=composer \ + && groupadd --gid ${gid} node \ + && useradd --uid ${uid} --gid node --shell /bin/bash --create-home node + +ENV APACHE_RUN_USER=node APACHE_RUN_GROUP=node + +VOLUME /var/www/html/ + +CMD [ "/var/www/html/utils/docker/entrypoint.dev.sh" ] diff --git a/utils/docker/Readme.md b/utils/docker/Readme.md new file mode 100644 index 0000000000..f2c07181f4 --- /dev/null +++ b/utils/docker/Readme.md @@ -0,0 +1,33 @@ +## Dockerizing selfoss + +There are two Dockerfiles bundled in the repository - one for development, one for production deployment. + +### Production + +To build the production container first go to utils/docker directory, then use: +``` +docker-compose build --no-cache --pull +``` + +Then run it with: +``` +docker-compose up +``` + +Selfoss web interface will be available at http://localhost:8390 + +Selfoss config is mounted in a separate volume, so your custom settings should survive reboot. + +### Development + +To run the development container first make sure you are in utils/docker directory, then copy .env.dist into .env and make sure the UID and GID matches your own user and group ID, otherwise the dev scripts will create files with wrong access rights. +``` +cat .env.dist | sed 's/UID=1000/UID='$(id -u)'/' | sed 's/GID=1000/GID='$(id -g)'/' > .env +``` +Then build and run the dev container: +``` +docker-compose -f docker-compose.dev.yml build --no-cache --pull +docker-compose -f docker-compose.dev.yml run --rm -u node app npm run postinstall +docker-compose -f docker-compose.dev.yml up +``` +Dev Selfoss web interface will be available at http://localhost:8391, and you can run all the dev scripts like this: `docker-compose exec -u node npm run check` or simply jump into bash inside the container: `docker-compose exec -u node bash`. That's it, you can start developing! diff --git a/utils/docker/docker-compose.dev.yml b/utils/docker/docker-compose.dev.yml new file mode 100644 index 0000000000..439d05c4fb --- /dev/null +++ b/utils/docker/docker-compose.dev.yml @@ -0,0 +1,17 @@ +version: "3" + +services: + # clean build with `docker-compose -f docker-compose.dev.yml build --no-cache --pull app` + app: + image: selfoss/selfoss-dev + build: + args: + uid: ${UID} + gid: ${GID} + context: ../.. + dockerfile: ./utils/docker/Dockerfile.dev + volumes: + - .:/var/www/html/ + restart: unless-stopped + ports: + - "8391:80" diff --git a/utils/docker/docker-compose.yml b/utils/docker/docker-compose.yml new file mode 100644 index 0000000000..3325de5847 --- /dev/null +++ b/utils/docker/docker-compose.yml @@ -0,0 +1,17 @@ +version: "3" + +services: + # clean build with `docker-compose build --no-cache --pull app` + app: + image: selfoss/selfoss + build: + context: ../.. + dockerfile: ./utils/docker/Dockerfile + volumes: + - config:/var/www/html/config/ + restart: unless-stopped + ports: + - "8390:80" + +volumes: + config: diff --git a/utils/docker/entrypoint.dev.sh b/utils/docker/entrypoint.dev.sh new file mode 100755 index 0000000000..0b12eec01f --- /dev/null +++ b/utils/docker/entrypoint.dev.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +# Start the server and dev watcher +( + apache2-foreground & su node -c "npm run dev" +) diff --git a/utils/docker/entrypoint.sh b/utils/docker/entrypoint.sh new file mode 100755 index 0000000000..c757dc4320 --- /dev/null +++ b/utils/docker/entrypoint.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +# Make data directories owned by Apache +chown -R www-data:www-data \ + /var/www/html/data/cache \ + /var/www/html/data/favicons \ + /var/www/html/data/logs \ + /var/www/html/data/thumbnails \ + /var/www/html/data/sqlite + +# Create a config file when one does not exist +if [[ ! -f config/config.ini ]]; then + sed 's#^logger_destination=.*#logger_destination=file:php://stderr#' defaults.ini > config/config.ini +fi + +# Run updater process periodically +su www-data -s /bin/bash -c 'php /var/www/html/cliupdate.php' >/dev/null 2>&1 +(while true; do su www-data -s /bin/bash -c 'php /var/www/html/cliupdate.php'; sleep 900; done;) & + +# Start the server +apache2-foreground