Skip to content

Commit 74be488

Browse files
committed
Create docker images with php 8.4 version
1 parent 3a0bcc3 commit 74be488

File tree

7 files changed

+196
-29
lines changed

7 files changed

+196
-29
lines changed

.docker/docker-symfony-entrypoint.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
# first arg is `-f` or `--some-option`
6+
if [ "${1#-}" != "$1" ]; then
7+
set -- php-fpm "$@"
8+
fi
9+
10+
if [ "$1" = 'php-fpm' ] || [ "$1" = 'bin/console' ]; then
11+
if [ ! -d composer.json ]; then
12+
# copy the created symfony project to the working directory
13+
cp -a "${SYMFONY_BUILD_PROJECT}/${SYMFONY_PROJECT_DIRECTORY_NAME}/." .
14+
fi
15+
16+
if [ "$APP_ENV" != 'prod' ]; then
17+
composer install --prefer-dist --no-progress --no-interaction
18+
fi
19+
20+
#setfacl -R -m u:www-data:rwX -m u:"$(whoami)":rwX var
21+
#setfacl -dR -m u:www-data:rwX -m u:"$(whoami)":rwX var
22+
23+
# start symfony server
24+
if [ "$SG_SERVER_ENABLED" = true ]; then
25+
symfony server:ca:install
26+
symfony server:start
27+
fi
28+
fi
29+
30+
exec docker-php-entrypoint "$@"
File renamed without changes.

.docker/new-symfony.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,13 @@
22

33
set -eu -o pipefail
44

5+
# todo: use env var instead of $1
56
directory="$1"
67

8+
if [ ! -d "$directory" ]; then
9+
mkdir -p "$directory"
10+
fi
11+
712
# Delete existing symfony project
813
rm -rf "$directory/symfony"
914
cd "$directory"

.github/workflows/build.yaml

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,31 @@ jobs:
1818
strategy:
1919
fail-fast: false
2020
matrix:
21-
php: ['8.3']
21+
php: ['8.4']
2222
composer: ['2.5']
23-
symfony: ['5.4', '6.1', '6.2', '6.3', '6.4']
23+
symfony: ['6.4', '7.0', '7.1']
2424
latest: [false]
2525
include:
26-
- php: 8.3
27-
symfony: '7.0'
26+
- php: 8.4
27+
symfony: '7.2'
2828
composer: 2.5
2929
latest: true
30+
- php: 8.3
31+
symfony: '7.2'
32+
composer: 2.5
33+
latest: false
34+
- php: 8.2
35+
symfony: '7.2'
36+
composer: 2.5
37+
latest: false
38+
- php: 8.3
39+
symfony: '7.1'
40+
composer: 2.5
41+
latest: false
42+
- php: 8.2
43+
symfony: '7.1'
44+
composer: 2.5
45+
latest: false
3046
name: "[Package] SF v${{ matrix.symfony }} PHP ${{ matrix.php }}"
3147
runs-on: ubuntu-latest
3248

@@ -75,9 +91,9 @@ jobs:
7591
strategy:
7692
fail-fast: false
7793
matrix:
78-
php: ['8.3']
94+
php: ['8.3', '8.4']
7995
composer: ['2.5']
80-
symfony: ['5.4', '6.1', '6.2', '6.3', '6.4', '7.0']
96+
symfony: ['6.4', '7.0', '7.1', '7.2']
8197
needs: packaging
8298
runs-on: ubuntu-latest
8399
name: "[Run] SF v${{ matrix.symfony }} PHP ${{ matrix.php }}"

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
.idea
2+
symfony
3+
compose.yaml

Dockerfile

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,41 @@
1-
ARG PHP_VERSION=8.2
1+
ARG PHP_VERSION=8.4
22
ARG COMPOSER_VERSION=2.5
33

44
FROM composer:${COMPOSER_VERSION} as composer
55
FROM php:${PHP_VERSION}-fpm-alpine
66

7-
ENV PHP_VERSION $PHP_VERSION
8-
ENV COMPOSER_VERSION $COMPOSER_VERSION
9-
ARG SYMFONY_VERSION=6.4
10-
ENV SYMFONY_VERSION $SYMFONY_VERSION
7+
ARG SG_SERVER_ENABLED=true
8+
ENV SG_SERVER_ENABLED=$SG_SERVER_ENABLED
9+
10+
ENV PHP_VERSION=$PHP_VERSION
11+
ENV COMPOSER_VERSION=$COMPOSER_VERSION
12+
ARG SYMFONY_VERSION=7.2
13+
ENV SYMFONY_VERSION=$SYMFONY_VERSION
14+
ARG SFUSER=symfony
15+
ENV SFUSER=$SFUSER
16+
ARG SYMFONY_BUILD_PROJECT=/home/$SFUSER/build
17+
ENV SYMFONY_BUILD_PROJECT=$SYMFONY_BUILD_PROJECT
18+
ARG SYMFONY_PROJECT_DIRECTORY_NAME=symfony
19+
ENV SYMFONY_PROJECT_DIRECTORY_NAME=$SYMFONY_PROJECT_DIRECTORY_NAME
20+
ARG DOCKER_WORKING_DIRECTORY=/var/www
21+
ENV DOCKER_WORKING_DIRECTORY=$DOCKER_WORKING_DIRECTORY
1122

1223
COPY --from=composer /usr/bin/composer /usr/bin/composer
1324

1425
### SYMFONY REQUIREMENT
15-
RUN apk add --no-cache icu-dev \
26+
RUN apk add --no-cache icu-dev acl \
1627
&& docker-php-ext-install intl \
1728
&& docker-php-ext-enable intl \
1829
&& docker-php-ext-install opcache \
1930
&& docker-php-ext-enable opcache
2031

21-
COPY .docker/docker-symfony-golden.ini /usr/local/etc/php/conf.d/
32+
COPY .docker/docker-symfony.ini /usr/local/etc/php/conf.d/
2233
### END SYMFONY REQUIREMENT
2334

2435
COPY ./.docker/new-symfony.sh /usr/local/bin/new-symfony
2536
RUN chmod +x /usr/local/bin/new-symfony
37+
COPY ./.docker/docker-symfony-entrypoint.sh /usr/local/bin/docker-symfony-entrypoint
38+
RUN chmod +x /usr/local/bin/docker-symfony-entrypoint
2639

2740
## SYMFONY CLI INSTALL
2841
RUN apk add --no-cache bash git
@@ -34,13 +47,28 @@ RUN apk add symfony-cli
3447
HEALTHCHECK --interval=5s --timeout=3s --retries=3 CMD symfony check:req || exit 1
3548
# END HEALTHCHECK
3649

37-
RUN new-symfony "/var/www"
50+
EXPOSE 8000
3851

39-
WORKDIR /var/www/symfony
52+
## Create container user
53+
ARG UID=1001
54+
ENV UID $UID
55+
ARG GID=1001
56+
ENV GID $GID
4057

41-
EXPOSE 8000
58+
RUN apk add --no-cache sudo
59+
RUN addgroup --system --gid $GID $SFUSER
60+
RUN echo "$SFUSER ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/$SFUSER
61+
RUN chmod 0440 /etc/sudoers.d/$SFUSER
62+
RUN adduser --system --uid $UID --ingroup $SFUSER $SFUSER
63+
64+
USER $SFUSER
65+
66+
RUN new-symfony $SYMFONY_BUILD_PROJECT
67+
68+
WORKDIR $DOCKER_WORKING_DIRECTORY/$SYMFONY_PROJECT_DIRECTORY_NAME
4269

43-
CMD ["symfony", "server:start"]
70+
ENTRYPOINT ["docker-symfony-entrypoint"]
71+
CMD ["php-fpm", "-F"]
4472

4573
ARG BUILD_DATE
4674
ARG VCS_REF
@@ -74,4 +102,4 @@ LABEL org.label-schema.version=$BUILD_VERSION
74102
LABEL org.label-schema.docker.cmd="docker run --rm -ti -v PROJECT_DIR:/var/www/symfony $IMAGE_TAG sh"
75103

76104
## ClEAN
77-
RUN rm -rf /tmp/* /var/cache/apk/* /var/tmp/*
105+
RUN sudo rm -rf /tmp/* /var/cache/apk/* /var/tmp/*

README.md

Lines changed: 97 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
## About
1010
This repository is a docker image based on official php, composer and alpine docker images.<br>
1111
This image contains symfony framework installed with all its required extensions.<br>
12+
It's useful to easily set symfony project up
13+
14+
## Image details
15+
### Available versions
1216
Below is the list of all the available images by Symfony and PHP versions:
1317

1418
<table>
@@ -21,10 +25,54 @@ Below is the list of all the available images by Symfony and PHP versions:
2125
</thead>
2226
<tbody>
2327
<tr>
24-
<td rowspan="2">7.0</td>
28+
<td rowspan="3">7.2</td>
29+
<td>8.4</td>
30+
<td>
31+
<code>ghcr.io/devgine/symfony-golden:latest</code>
32+
<code>ghcr.io/devgine/symfony-golden:v7.2-php8.4-alpine</code>
33+
</td>
34+
</tr>
35+
<tr>
36+
<td>8.3</td>
37+
<td>
38+
<code>ghcr.io/devgine/symfony-golden:v7.2-php8.3-alpine</code>
39+
</td>
40+
</tr>
41+
<tr>
42+
<td>8.2</td>
43+
<td>
44+
<code>ghcr.io/devgine/symfony-golden:v7.2-php8.2-alpine</code>
45+
</td>
46+
</tr>
47+
<tr>
48+
<td rowspan="3">7.1</td>
49+
<td>8.4</td>
50+
<td>
51+
<code>ghcr.io/devgine/symfony-golden:v7.1-php8.4-alpine</code>
52+
</td>
53+
</tr>
54+
<tr>
55+
<td>8.3</td>
56+
<td>
57+
<code>ghcr.io/devgine/symfony-golden:v7.1-php8.3-alpine</code>
58+
</td>
59+
</tr>
60+
<tr>
61+
<td>8.2</td>
62+
<td>
63+
<code>ghcr.io/devgine/symfony-golden:v7.1-php8.2-alpine</code>
64+
</td>
65+
</tr>
66+
<tr>
67+
<td rowspan="3">7.0</td>
68+
<td>8.4</td>
69+
<td>
70+
<code>ghcr.io/devgine/symfony-golden:v7.0-php8.4-alpine</code>
71+
</td>
72+
</tr>
73+
<tr>
2574
<td>8.3</td>
2675
<td>
27-
<code>ghcr.io/devgine/symfony-golden:latest</code><br />
2876
<code>ghcr.io/devgine/symfony-golden:v7.0-php8.3-alpine</code>
2977
</td>
3078
</tr>
@@ -35,7 +83,13 @@ Below is the list of all the available images by Symfony and PHP versions:
3583
</td>
3684
</tr>
3785
<tr>
38-
<td rowspan="3">6.4</td>
86+
<td rowspan="4">6.4</td>
87+
<td>8.4</td>
88+
<td>
89+
<code>ghcr.io/devgine/symfony-golden:v6.4-php8.4-alpine</code>
90+
</td>
91+
</tr>
92+
<tr>
3993
<td>8.3</td>
4094
<td>
4195
<code>ghcr.io/devgine/symfony-golden:v6.4-php8.3-alpine</code>
@@ -126,17 +180,25 @@ Below is the list of all the available images by Symfony and PHP versions:
126180
</tbody>
127181
</table>
128182

183+
### Environment variables
184+
TODO
185+
129186
## Usage
130187
### Install from the command line
131188
```shell
132-
docker run --rm -ti -p 8000:8000 ghcr.io/devgine/symfony-golden:latest sh
189+
docker run -d -p 8000:8000 -v HOST_DIRECTORY:/var/www/symfony ghcr.io/devgine/symfony-golden:latest
133190
```
134191
> You can change latest by a specific tag<br>
135192
> [Available versions](https://github.com/devgine/symfony-golden-image/pkgs/container/symfony-golden/versions)
136193
137194
After the built-in, server will be started.<br>
138195
Visit http://localhost:8000 in your web browser.
139196

197+
**Connect to the container**
198+
```shell
199+
docker exec -ti CONTAINER_ID sh
200+
```
201+
140202
### Use as base image in Dockerfile
141203
```dockerfile
142204
FROM ghcr.io/devgine/symfony-golden:latest
@@ -149,22 +211,46 @@ RUN set -xe \
149211
#...
150212
```
151213

152-
### Use with docker-compose
214+
### Use with docker compose
153215
```yaml
216+
# localhost:8000
154217
services:
155218
symfony:
156219
image: ghcr.io/devgine/symfony-golden:latest
220+
volumes:
221+
- HOST_DIRECTORY:/var/www/symfony
157222
ports:
158223
- 8000:8000
159224
```
160-
Be careful, if you bind the symfony project as a volume, it will be erased by the local directory.<br>
161-
To fix that, after your service running you can launch the below command inside the container.
162-
```bash
163-
new-symfony $DIRECTORY
164-
# example
165-
new-symfony /var/www
225+
226+
**Access :** http://localhost:8000
227+
228+
### Use with nginx
229+
First of all, configure nginx as recommended by symfony community
230+
231+
https://symfony.com/doc/current/setup/web_server_configuration.html#nginx
232+
233+
```yaml
234+
# compose.yaml
235+
services:
236+
nginx:
237+
image: nginx:latest
238+
volumes:
239+
- HOST_DIRECTORY/public:/var/www/symfony/public
240+
- ./nginx.conf:/etc/nginx/conf.d/default.conf
241+
ports:
242+
- 80:80
243+
244+
symfony:
245+
image: ghcr.io/devgine/symfony-golden:latest
246+
environment:
247+
SG_SERVER_ENABLED: false # do not run symfony server
248+
volumes:
249+
- HOST_DIRECTORY:/var/www/symfony
166250
```
167251
252+
**Access :** http://localhost
253+
168254
## References
169255
170256
* [Symfony releases](https://symfony.com/releases)

0 commit comments

Comments
 (0)