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

Docker #1170

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open

Docker #1170

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
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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
squatica marked this conversation as resolved.
Show resolved Hide resolved

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]([email protected]) and it is licensed under the GPLv3 license.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

"install-dependencies:server": "composer install",
"lint:client": "npm run --prefix assets/ lint",
"lint:server": "composer run-script lint",
"test:server": "composer run-script test",
Expand Down
2 changes: 2 additions & 0 deletions utils/docker/.env.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
UID=1000
GID=1000
31 changes: 31 additions & 0 deletions utils/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -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" ]
30 changes: 30 additions & 0 deletions utils/docker/Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -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" ]
33 changes: 33 additions & 0 deletions utils/docker/Readme.md
Original file line number Diff line number Diff line change
@@ -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!
17 changes: 17 additions & 0 deletions utils/docker/docker-compose.dev.yml
Original file line number Diff line number Diff line change
@@ -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"
17 changes: 17 additions & 0 deletions utils/docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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:
6 changes: 6 additions & 0 deletions utils/docker/entrypoint.dev.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

# Start the server and dev watcher
(
apache2-foreground & su node -c "npm run dev"
)
21 changes: 21 additions & 0 deletions utils/docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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