Skip to content

Commit

Permalink
feat: use nginx unit as web server for docker image
Browse files Browse the repository at this point in the history
  • Loading branch information
ramunasd committed Mar 23, 2024
1 parent a25dda6 commit 1dd0db4
Show file tree
Hide file tree
Showing 10 changed files with 91 additions and 99 deletions.
4 changes: 3 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
/config/parameters.yml
/tests
/var
.idea
.git
.gitignore
.php-cs-fixer.dist.php
.phpstorm.meta.php
.travis.yml
.phpunit.cache
docker-compose.yml
ide-twig.json
phpstan.neon.dist
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ config/parameters.yml
/composer.phar
/var/*
/.composer
.phpunit.cache

# Satis default configuration
satis.json
Expand Down
28 changes: 0 additions & 28 deletions .travis.yml

This file was deleted.

31 changes: 9 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,39 +77,26 @@ You can run satisfy using prebuilt docker image. Here is an example how to setup
2. Add parameters.yml file, can be copied from config/parameters.yml.dist
3. Add auth.json with all required composer authentication tokens
4. Add simple satis.json with basic information
5. Add nginx dir with site configuration templates
6. Create docker-compose.yml using example below
7. Start containers `docker-compose up`
8. Access container shell `docker-compose exec php bash`
9. Run initial build `./bin/satis build`
10. Open satis page on `http://localhost:8000`
5. Create docker-compose.yml using example below
6. Start containers `docker-compose up`
7. Access container shell `docker-compose exec php bash`
8. Run initial build `./bin/satis build`
9. Open satis page on `http://localhost:8000`

```
version: '3'
services:
php:
image: ghcr.io/project-satisfy/satisfy:latest
ports:
- "${APP_PORT:-8000}:80"
volumes:
- ./satis.json:/var/www/satisfy/satis.json
- ./parameters.yml:/var/www/satisfy/config/parameters.yml
- ./satis.json:/var/www/html/satis.json
- ./parameters.yml:/var/www/html/config/parameters.yml
- ./auth.json:/var/www/.composer/auth.json:ro
- /var/www/satisfy
environment:
APP_ENV: ${APP_ENV:-dev}
APP_DEBUG: ${APP_DEBUG:-1}
nginx:
image: nginx:1.22-alpine
ports:
- "${APP_PORT:-8000}:80"
volumes:
- ./nginx:/etc/nginx/templates
volumes_from:
- php:ro
environment:
- PHP_SERVICE_NAME=php
depends_on:
- php
```

## Authors
Expand Down
1 change: 1 addition & 0 deletions config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ monolog:
type: fingers_crossed
action_level: '%log.level%'
handler: '%log.handler%'
bubble: false
file_log:
type: rotating_file
path: "%kernel.logs_dir%/%kernel.environment%.log"
Expand Down
23 changes: 7 additions & 16 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,15 @@ services:
build:
context: ./docker/php
container_name: satisfy_php
user: www-data
working_dir: /var/www/satisfy
working_dir: /var/www/html
ports:
- "${APP_PORT:-8000}:80"
volumes:
- .:/var/www/satisfy
- .:/var/www/html
- ./docker/php/unit.json:/docker-entrypoint.d/config.json
- /var/www/.composer
environment:
APP_ENV: ${APP_ENV:-dev}
APP_DEBUG: ${APP_DEBUG:-1}
APP_PATH: /var/www/satisfy

nginx:
image: nginx:1.22-alpine
ports:
- "${APP_PORT:-8000}:80"
volumes:
- .:/var/www/satisfy
- ./docker/nginx/templates:/etc/nginx/templates
environment:
- PHP_SERVICE_NAME=php
depends_on:
- php
APP_PATH: /var/www/html
COMPOSER_HOME: /var/www/.composer
20 changes: 0 additions & 20 deletions docker/nginx/templates/default.conf.template

This file was deleted.

6 changes: 4 additions & 2 deletions docker/php/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
FROM php:8.1-fpm
FROM unit:1.32.0-php8.2

RUN apt update && \
apt install -qy wget curl git zip unzip && \
apt clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

ADD --chmod=0755 https://github.com/mlocati/docker-php-extension-installer/releases/download/2.1.58/install-php-extensions /usr/local/bin/
ADD --chmod=0755 https://github.com/mlocati/docker-php-extension-installer/releases/download/2.2.5/install-php-extensions /usr/local/bin/
RUN install-php-extensions @composer zip

RUN chown -R www-data:www-data /var/www
Expand All @@ -14,3 +14,5 @@ COPY php.ini /usr/local/etc/php/conf.d/satisfy.ini
USER www-data
RUN mkdir -p ~/.ssh && chmod 0700 ~/.ssh && ssh-keyscan -H github.com >> ~/.ssh/known_hosts && \
mkdir -p ~/.composer && chown www-data:www-data ~/.composer

USER root
24 changes: 14 additions & 10 deletions docker/php/package.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,29 +1,33 @@
FROM php:8.2-fpm
FROM unit:1.32.0-php8.2

RUN apt update && \
apt install -qy wget curl git zip unzip && \
apt clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

ADD --chmod=0755 https://github.com/mlocati/docker-php-extension-installer/releases/download/2.1.58/install-php-extensions /usr/local/bin/
ADD --chmod=0755 https://github.com/mlocati/docker-php-extension-installer/releases/download/2.2.5/install-php-extensions /usr/local/bin/
RUN install-php-extensions @composer zip

COPY docker/php/unit.json /docker-entrypoint.d/config.json
COPY docker/php/php.ini /usr/local/etc/php/conf.d/satisfy.ini
RUN chown -R www-data:www-data /var/www

USER www-data
RUN mkdir -p ~/.ssh && chmod 0700 ~/.ssh && ssh-keyscan -H github.com >> ~/.ssh/known_hosts && \
mkdir -p ~/.composer && \
wget -O ~/.composer/keys.dev.pub https://composer.github.io/snapshots.pub && \
wget -O ~/.composer/keys.tags.pub https://composer.github.io/releases.pub && \
mkdir -p /var/www/satisfy/var && \
mkdir -p /var/www/satisfy/public
wget -O ~/.composer/keys.tags.pub https://composer.github.io/releases.pub
VOLUME /var/www/.composer

ENV APP_PATH=/var/www/satisfy
ENV APP_PATH=/var/www/html
ENV APP_ENV=prod
ENV APP_DEBUG=0
WORKDIR /var/www/satisfy
ENV COMPOSER_HOME=/var/www/.composer
ENV COMPOSER_CACHE=/var/www/html/var/cache/composer
WORKDIR /var/www/html

VOLUME /var/www/.composer
VOLUME /var/www/satisfy
COPY --chown=www-data:www-data . /var/www/html/

RUN mkdir /var/www/html/var
VOLUME /var/www/html/var

COPY --chown=www-data:www-data . /var/www/satisfy/
USER root
52 changes: 52 additions & 0 deletions docker/php/unit.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"listeners": {
"*:80": {
"pass": "routes"
}
},
"routes": [
{
"match": {
"uri": [
"*.php",
"*.php/*"
]
},
"action": {
"pass": "applications/satisfy/direct"
}
},
{
"action": {
"share": "/var/www/html/public$uri",
"fallback": {
"pass": "applications/satisfy/index"
}
}
}
],
"applications": {
"satisfy": {
"type": "php",
"processes": {
"max": 16,
"spare": 1,
"idle_timeout": 30
},
"user": "www-data",
"group": "www-data",
"working_directory": "/var/www/html",
"stderr": "/dev/stderr",
"stdout": "/dev/stdout",
"targets": {
"direct": {
"root": "/var/www/html"
},
"index": {
"root": "/var/www/html/public",
"script": "index.php"
}
}
}
}
}

0 comments on commit 1dd0db4

Please sign in to comment.