diff --git a/.docker/docker-symfony-entrypoint.sh b/.docker/docker-symfony-entrypoint.sh new file mode 100644 index 0000000..b6b91f9 --- /dev/null +++ b/.docker/docker-symfony-entrypoint.sh @@ -0,0 +1,30 @@ +#!/bin/sh + +set -e + +# first arg is `-f` or `--some-option` +if [ "${1#-}" != "$1" ]; then + set -- php-fpm "$@" +fi + +if [ "$1" = 'php-fpm' ] || [ "$1" = 'bin/console' ]; then + if [ ! -d composer.json ]; then + # copy the created symfony project to the working directory + cp -a "${SYMFONY_BUILD_PROJECT}/${SYMFONY_PROJECT_DIRECTORY_NAME}/." . + fi + + if [ "$APP_ENV" != 'prod' ]; then + composer install --prefer-dist --no-progress --no-interaction + fi + + #setfacl -R -m u:www-data:rwX -m u:"$(whoami)":rwX var + #setfacl -dR -m u:www-data:rwX -m u:"$(whoami)":rwX var + + # start symfony server + if [ "$SG_SERVER_ENABLED" = true ]; then + symfony server:ca:install + symfony server:start + fi +fi + +exec docker-php-entrypoint "$@" diff --git a/.docker/docker-symfony-golden.ini b/.docker/docker-symfony.ini similarity index 100% rename from .docker/docker-symfony-golden.ini rename to .docker/docker-symfony.ini diff --git a/.docker/new-symfony.sh b/.docker/new-symfony.sh index f1fc844..fc72c1d 100644 --- a/.docker/new-symfony.sh +++ b/.docker/new-symfony.sh @@ -2,8 +2,13 @@ set -eu -o pipefail +# todo: use env var instead of $1 directory="$1" +if [ ! -d "$directory" ]; then + mkdir -p "$directory" +fi + # Delete existing symfony project rm -rf "$directory/symfony" cd "$directory" diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 62ffe7d..5a9d4dc 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -18,15 +18,31 @@ jobs: strategy: fail-fast: false matrix: - php: ['8.3'] + php: ['8.4'] composer: ['2.5'] - symfony: ['5.4', '6.1', '6.2', '6.3', '6.4'] + symfony: ['6.4', '7.0', '7.1'] latest: [false] include: - - php: 8.3 - symfony: '7.0' + - php: 8.4 + symfony: '7.2' composer: 2.5 latest: true + - php: 8.3 + symfony: '7.2' + composer: 2.5 + latest: false + - php: 8.2 + symfony: '7.2' + composer: 2.5 + latest: false + - php: 8.3 + symfony: '7.1' + composer: 2.5 + latest: false + - php: 8.2 + symfony: '7.1' + composer: 2.5 + latest: false name: "[Package] SF v${{ matrix.symfony }} PHP ${{ matrix.php }}" runs-on: ubuntu-latest @@ -75,9 +91,9 @@ jobs: strategy: fail-fast: false matrix: - php: ['8.3'] + php: ['8.3', '8.4'] composer: ['2.5'] - symfony: ['5.4', '6.1', '6.2', '6.3', '6.4', '7.0'] + symfony: ['6.4', '7.0', '7.1', '7.2'] needs: packaging runs-on: ubuntu-latest name: "[Run] SF v${{ matrix.symfony }} PHP ${{ matrix.php }}" diff --git a/.gitignore b/.gitignore index 485dee6..fd543c3 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ .idea +symfony +compose.yaml diff --git a/Dockerfile b/Dockerfile index e41def0..d859114 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,28 +1,41 @@ -ARG PHP_VERSION=8.2 +ARG PHP_VERSION=8.4 ARG COMPOSER_VERSION=2.5 FROM composer:${COMPOSER_VERSION} as composer FROM php:${PHP_VERSION}-fpm-alpine -ENV PHP_VERSION $PHP_VERSION -ENV COMPOSER_VERSION $COMPOSER_VERSION -ARG SYMFONY_VERSION=6.4 -ENV SYMFONY_VERSION $SYMFONY_VERSION +ARG SG_SERVER_ENABLED=true +ENV SG_SERVER_ENABLED=$SG_SERVER_ENABLED + +ENV PHP_VERSION=$PHP_VERSION +ENV COMPOSER_VERSION=$COMPOSER_VERSION +ARG SYMFONY_VERSION=7.2 +ENV SYMFONY_VERSION=$SYMFONY_VERSION +ARG SFUSER=symfony +ENV SFUSER=$SFUSER +ARG SYMFONY_BUILD_PROJECT=/home/$SFUSER/build +ENV SYMFONY_BUILD_PROJECT=$SYMFONY_BUILD_PROJECT +ARG SYMFONY_PROJECT_DIRECTORY_NAME=symfony +ENV SYMFONY_PROJECT_DIRECTORY_NAME=$SYMFONY_PROJECT_DIRECTORY_NAME +ARG DOCKER_WORKING_DIRECTORY=/var/www +ENV DOCKER_WORKING_DIRECTORY=$DOCKER_WORKING_DIRECTORY COPY --from=composer /usr/bin/composer /usr/bin/composer ### SYMFONY REQUIREMENT -RUN apk add --no-cache icu-dev \ +RUN apk add --no-cache icu-dev acl \ && docker-php-ext-install intl \ && docker-php-ext-enable intl \ && docker-php-ext-install opcache \ && docker-php-ext-enable opcache -COPY .docker/docker-symfony-golden.ini /usr/local/etc/php/conf.d/ +COPY .docker/docker-symfony.ini /usr/local/etc/php/conf.d/ ### END SYMFONY REQUIREMENT COPY ./.docker/new-symfony.sh /usr/local/bin/new-symfony RUN chmod +x /usr/local/bin/new-symfony +COPY ./.docker/docker-symfony-entrypoint.sh /usr/local/bin/docker-symfony-entrypoint +RUN chmod +x /usr/local/bin/docker-symfony-entrypoint ## SYMFONY CLI INSTALL RUN apk add --no-cache bash git @@ -34,13 +47,28 @@ RUN apk add symfony-cli HEALTHCHECK --interval=5s --timeout=3s --retries=3 CMD symfony check:req || exit 1 # END HEALTHCHECK -RUN new-symfony "/var/www" +EXPOSE 8000 -WORKDIR /var/www/symfony +## Create container user +ARG UID=1001 +ENV UID $UID +ARG GID=1001 +ENV GID $GID -EXPOSE 8000 +RUN apk add --no-cache sudo +RUN addgroup --system --gid $GID $SFUSER +RUN echo "$SFUSER ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/$SFUSER +RUN chmod 0440 /etc/sudoers.d/$SFUSER +RUN adduser --system --uid $UID --ingroup $SFUSER $SFUSER + +USER $SFUSER + +RUN new-symfony $SYMFONY_BUILD_PROJECT + +WORKDIR $DOCKER_WORKING_DIRECTORY/$SYMFONY_PROJECT_DIRECTORY_NAME -CMD ["symfony", "server:start"] +ENTRYPOINT ["docker-symfony-entrypoint"] +CMD ["php-fpm", "-F"] ARG BUILD_DATE ARG VCS_REF @@ -74,4 +102,4 @@ LABEL org.label-schema.version=$BUILD_VERSION LABEL org.label-schema.docker.cmd="docker run --rm -ti -v PROJECT_DIR:/var/www/symfony $IMAGE_TAG sh" ## ClEAN -RUN rm -rf /tmp/* /var/cache/apk/* /var/tmp/* +RUN sudo rm -rf /tmp/* /var/cache/apk/* /var/tmp/* diff --git a/README.md b/README.md index 8eb917b..2d8a092 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,10 @@ ## About This repository is a docker image based on official php, composer and alpine docker images.
This image contains symfony framework installed with all its required extensions.
+It's useful to easily set symfony project up + +## Image details +### Available versions Below is the list of all the available images by Symfony and PHP versions: @@ -21,10 +25,54 @@ Below is the list of all the available images by Symfony and PHP versions: - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -35,7 +83,13 @@ Below is the list of all the available images by Symfony and PHP versions: - + + + + +
7.07.28.4 + ghcr.io/devgine/symfony-golden:latest + ghcr.io/devgine/symfony-golden:v7.2-php8.4-alpine +
8.3 + ghcr.io/devgine/symfony-golden:v7.2-php8.3-alpine +
8.2 + ghcr.io/devgine/symfony-golden:v7.2-php8.2-alpine +
7.18.4 + ghcr.io/devgine/symfony-golden:v7.1-php8.4-alpine +
8.3 + ghcr.io/devgine/symfony-golden:v7.1-php8.3-alpine +
8.2 + ghcr.io/devgine/symfony-golden:v7.1-php8.2-alpine +
7.08.4 + ghcr.io/devgine/symfony-golden:v7.0-php8.4-alpine +
8.3 - ghcr.io/devgine/symfony-golden:latest
ghcr.io/devgine/symfony-golden:v7.0-php8.3-alpine
6.46.48.4 + ghcr.io/devgine/symfony-golden:v6.4-php8.4-alpine +
8.3 ghcr.io/devgine/symfony-golden:v6.4-php8.3-alpine @@ -126,10 +180,13 @@ Below is the list of all the available images by Symfony and PHP versions:
+### Environment variables +TODO + ## Usage ### Install from the command line ```shell -docker run --rm -ti -p 8000:8000 ghcr.io/devgine/symfony-golden:latest sh +docker run -d -p 8000:8000 -v HOST_DIRECTORY:/var/www/symfony ghcr.io/devgine/symfony-golden:latest ``` > You can change latest by a specific tag
> [Available versions](https://github.com/devgine/symfony-golden-image/pkgs/container/symfony-golden/versions) @@ -137,6 +194,11 @@ docker run --rm -ti -p 8000:8000 ghcr.io/devgine/symfony-golden:latest sh After the built-in, server will be started.
Visit http://localhost:8000 in your web browser. +**Connect to the container** +```shell +docker exec -ti CONTAINER_ID sh +``` + ### Use as base image in Dockerfile ```dockerfile FROM ghcr.io/devgine/symfony-golden:latest @@ -149,22 +211,46 @@ RUN set -xe \ #... ``` -### Use with docker-compose +### Use with docker compose ```yaml +# localhost:8000 services: symfony: image: ghcr.io/devgine/symfony-golden:latest + volumes: + - HOST_DIRECTORY:/var/www/symfony ports: - 8000:8000 ``` -Be careful, if you bind the symfony project as a volume, it will be erased by the local directory.
-To fix that, after your service running you can launch the below command inside the container. -```bash -new-symfony $DIRECTORY -# example -new-symfony /var/www + +**Access :** http://localhost:8000 + +### Use with nginx +First of all, configure nginx as recommended by symfony community + +https://symfony.com/doc/current/setup/web_server_configuration.html#nginx + +```yaml +# compose.yaml +services: + nginx: + image: nginx:latest + volumes: + - HOST_DIRECTORY/public:/var/www/symfony/public + - ./nginx.conf:/etc/nginx/conf.d/default.conf + ports: + - 80:80 + + symfony: + image: ghcr.io/devgine/symfony-golden:latest + environment: + SG_SERVER_ENABLED: false # do not run symfony server + volumes: + - HOST_DIRECTORY:/var/www/symfony ``` +**Access :** http://localhost + ## References * [Symfony releases](https://symfony.com/releases)