Skip to content

Commit

Permalink
Create docker images with php 8.4 version
Browse files Browse the repository at this point in the history
  • Loading branch information
yosrib committed Dec 1, 2024
1 parent 3a0bcc3 commit 74be488
Show file tree
Hide file tree
Showing 7 changed files with 196 additions and 29 deletions.
30 changes: 30 additions & 0 deletions .docker/docker-symfony-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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 "$@"
File renamed without changes.
5 changes: 5 additions & 0 deletions .docker/new-symfony.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
28 changes: 22 additions & 6 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 }}"
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
.idea
symfony
compose.yaml
52 changes: 40 additions & 12 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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/*
108 changes: 97 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
## About
This repository is a docker image based on official php, composer and alpine docker images.<br>
This image contains symfony framework installed with all its required extensions.<br>
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:

<table>
Expand All @@ -21,10 +25,54 @@ Below is the list of all the available images by Symfony and PHP versions:
</thead>
<tbody>
<tr>
<td rowspan="2">7.0</td>
<td rowspan="3">7.2</td>
<td>8.4</td>
<td>
<code>ghcr.io/devgine/symfony-golden:latest</code>
<code>ghcr.io/devgine/symfony-golden:v7.2-php8.4-alpine</code>
</td>
</tr>
<tr>
<td>8.3</td>
<td>
<code>ghcr.io/devgine/symfony-golden:v7.2-php8.3-alpine</code>
</td>
</tr>
<tr>
<td>8.2</td>
<td>
<code>ghcr.io/devgine/symfony-golden:v7.2-php8.2-alpine</code>
</td>
</tr>
<tr>
<td rowspan="3">7.1</td>
<td>8.4</td>
<td>
<code>ghcr.io/devgine/symfony-golden:v7.1-php8.4-alpine</code>
</td>
</tr>
<tr>
<td>8.3</td>
<td>
<code>ghcr.io/devgine/symfony-golden:v7.1-php8.3-alpine</code>
</td>
</tr>
<tr>
<td>8.2</td>
<td>
<code>ghcr.io/devgine/symfony-golden:v7.1-php8.2-alpine</code>
</td>
</tr>
<tr>
<td rowspan="3">7.0</td>
<td>8.4</td>
<td>
<code>ghcr.io/devgine/symfony-golden:v7.0-php8.4-alpine</code>
</td>
</tr>
<tr>
<td>8.3</td>
<td>
<code>ghcr.io/devgine/symfony-golden:latest</code><br />
<code>ghcr.io/devgine/symfony-golden:v7.0-php8.3-alpine</code>
</td>
</tr>
Expand All @@ -35,7 +83,13 @@ Below is the list of all the available images by Symfony and PHP versions:
</td>
</tr>
<tr>
<td rowspan="3">6.4</td>
<td rowspan="4">6.4</td>
<td>8.4</td>
<td>
<code>ghcr.io/devgine/symfony-golden:v6.4-php8.4-alpine</code>
</td>
</tr>
<tr>
<td>8.3</td>
<td>
<code>ghcr.io/devgine/symfony-golden:v6.4-php8.3-alpine</code>
Expand Down Expand Up @@ -126,17 +180,25 @@ Below is the list of all the available images by Symfony and PHP versions:
</tbody>
</table>

### 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<br>
> [Available versions](https://github.com/devgine/symfony-golden-image/pkgs/container/symfony-golden/versions)
After the built-in, server will be started.<br>
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
Expand All @@ -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.<br>
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)
Expand Down

0 comments on commit 74be488

Please sign in to comment.