Skip to content

Commit

Permalink
Merge pull request #27 from froozeify/pos
Browse files Browse the repository at this point in the history
Point de vente
  • Loading branch information
froozeify authored Jul 24, 2024
2 parents d3a71a0 + 6fdd5e0 commit 119d25b
Showing 67 changed files with 2,556 additions and 151 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -40,10 +40,11 @@ jobs:
run: docker compose up --wait --no-build
-
name: Check HTTP reachability
run: curl -v -o /dev/null http://localhost
run: curl -v --fail-with-body http://localhost
-
name: Check HTTPS reachability
run: curl -vk -o /dev/null https://localhost
if: false # Remove this line when the homepage will be configured, or change the path to check
run: curl -vk --fail-with-body https://localhost
-
name: Create test database
if: false # Remove this line if Doctrine ORM is installed
21 changes: 21 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Loading the fixture
Various commands are available:

- `composer reload-fixture`
- Empty the database then load all the fixtures
- `composer reload-db`
- Completely drop the database and recreate it from scratch, then load all fixtures

# Creating new entity
When creating a new entity, you should do the next steps :

1. Create the Entity (and his linked repository)
- `bin/console make:entity`
2. Add the route in `config/packages/security.yaml`
3. Generate the doctrine migration script
- `bin/console make:migration`
4. Create the matching factory (useful for generating fake data)
- `bin/console make:factory`
5. Optional, Create the matching story
- `bin/console make:story`
6. Add the data generation inside `src/DataFixtures/AppFixtures`
2 changes: 1 addition & 1 deletion compose.yaml
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ services:
DATABASE_URL: postgresql://${POSTGRES_USER:-app}:${POSTGRES_PASSWORD:-!ChangeMe!}@database:5432/${POSTGRES_DB:-app}?serverVersion=${POSTGRES_VERSION:-15}&charset=${POSTGRES_CHARSET:-utf8}
# Run "composer require symfony/mercure-bundle" to install and configure the Mercure integration
MERCURE_URL: ${CADDY_MERCURE_URL:-http://php/.well-known/mercure}
MERCURE_PUBLIC_URL: https://${SERVER_NAME:-localhost}/.well-known/mercure
MERCURE_PUBLIC_URL: ${CADDY_MERCURE_PUBLIC_URL:-https://${SERVER_NAME:-localhost}/.well-known/mercure}
MERCURE_JWT_SECRET: ${CADDY_MERCURE_JWT_SECRET:-!ChangeThisMercureHubJWTSecretKey!}
volumes:
- caddy_data:/data
8 changes: 8 additions & 0 deletions config/packages/security.yaml
Original file line number Diff line number Diff line change
@@ -66,13 +66,21 @@ security:

- { path: ^/external-presences, roles: [ROLE_SUPERVISOR, ROLE_BADGER]}
- { path: ^/global-settings, roles: [ROLE_ADMIN]}

- { path: ^/inventory-categories, roles: [ROLE_SUPERVISOR]}
- { path: ^/inventory-items, roles: [ROLE_SUPERVISOR]}
- { path: ^/inventory-item-histories, roles: [ROLE_SUPERVISOR]}

- { path: ^/members/-/from-itac, roles: [ROLE_ADMIN]}
- { path: ^/members, roles: [ROLE_SUPERVISOR, ROLE_BADGER]}

- { path: ^/member-presences/-/from-cerbere, roles: [ROLE_ADMIN]}
- { path: ^/member-presences, roles: [ROLE_SUPERVISOR, ROLE_BADGER]}
- { path: ^/metrics, roles: [ROLE_SUPERVISOR]}

- { path: ^/sales, roles: [ROLE_SUPERVISOR]}
- { path: ^/sale-payment-modes, roles: [ROLE_SUPERVISOR]}
# - { path: ^/sale-purchased-items, roles: [ROLE_SUPERVISOR]} # Not available in the API

# - { path: ^/admin, roles: ROLE_ADMIN }
# - { path: ^/profile, roles: ROLE_USER }
14 changes: 3 additions & 11 deletions docker/frankenphp/Caddyfile
Original file line number Diff line number Diff line change
@@ -4,11 +4,6 @@
frankenphp {
{$FRANKENPHP_CONFIG}
}

# https://caddyserver.com/docs/caddyfile/directives#sorting-algorithm
order mercure after encode
order vulcain after reverse_proxy
order php_server before file_server
}

{$CADDY_EXTRA_CONFIG}
@@ -17,17 +12,14 @@
log {
# Redact the authorization query parameter that can be set by Mercure
format filter {
wrap console
fields {
uri query {
replace authorization REDACTED
}
request>uri query {
replace authorization REDACTED
}
}
}

root * /app/public
encode zstd gzip
encode zstd br gzip

mercure {
# Transport to use (default to Bolt)
1 change: 0 additions & 1 deletion docker/frankenphp/conf.d/app.ini
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
variables_order = EGPCS
expose_php = 0
date.timezone = UTC
apc.enable_cli = 1
2 changes: 1 addition & 1 deletion docker/frankenphp/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@ if [ "$1" = 'frankenphp' ] || [ "$1" = 'php' ] || [ "$1" = 'bin/console' ]; then
fi

if [ "$( find ./migrations -iname '*.php' -print -quit )" ]; then
php bin/console doctrine:migrations:migrate --no-interaction
php bin/console doctrine:migrations:migrate --no-interaction --all-or-nothing
fi
fi

12 changes: 7 additions & 5 deletions docs/0.README.md
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ with [FrankenPHP](https://frankenphp.dev) and [Caddy](https://caddyserver.com/)

1. If not already done, [install Docker Compose](https://docs.docker.com/compose/install/) (v2.10+)
2. Run `docker compose build --no-cache` to build fresh images
3. Run `docker compose up --pull always -d --wait` to start the project
3. Run `docker compose up --pull always -d --wait` to set up and start a fresh Symfony project
4. Open `https://localhost` in your favorite web browser and [accept the auto-generated TLS certificate](https://stackoverflow.com/a/15076602/1352334)
5. Run `docker compose down --remove-orphans` to stop the Docker containers.

@@ -30,15 +30,17 @@ with [FrankenPHP](https://frankenphp.dev) and [Caddy](https://caddyserver.com/)

## Docs

1. [Build options](docs/build.md)
1. [Options available](docs/options.md)
2. [Using Symfony Docker with an existing project](docs/existing-project.md)
3. [Support for extra services](docs/extra-services.md)
4. [Deploying in production](docs/production.md)
5. [Debugging with Xdebug](docs/xdebug.md)
6. [TLS Certificates](docs/tls.md)
7. [Using a Makefile](docs/makefile.md)
8. [Troubleshooting](docs/troubleshooting.md)
9. [Updating the template](docs/updating.md)
7. [Using MySQL instead of PostgreSQL](docs/mysql.md)
8. [Using Alpine Linux instead of Debian](docs/alpine.md)
9. [Using a Makefile](docs/makefile.md)
10. [Updating the template](docs/updating.md)
11. [Troubleshooting](docs/troubleshooting.md)

## License

29 changes: 29 additions & 0 deletions docs/alpine.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Using Alpine Linux Instead of Debian

By default, Symfony Docker uses Debian-based FrankenPHP Docker images.
This is the recommended solution.

Alternatively, it's possible to use Alpine-based images, which are smaller but
are known to be slower, and have several known issues.

To switch to Alpine-based images, apply the following changes to the `Dockerfile`:

```patch
-FROM dunglas/frankenphp:1-php8.3 AS frankenphp_upstream
+FROM dunglas/frankenphp:1-php8.3-alpine AS frankenphp_upstream

-# hadolint ignore=DL3008
-RUN apt-get update && apt-get install -y --no-install-recommends \
- acl \
- file \
- gettext \
- git \
- && rm -rf /var/lib/apt/lists/*
+# hadolint ignore=DL3018
+RUN apk add --no-cache \
+ acl \
+ file \
+ gettext \
+ git \
+ ;
```
49 changes: 0 additions & 49 deletions docs/build.md

This file was deleted.

12 changes: 8 additions & 4 deletions docs/existing-project.md
Original file line number Diff line number Diff line change
@@ -2,10 +2,14 @@

It's also possible to use Symfony Docker with existing projects!

First, [download this skeleton](https://github.com/dunglas/symfony-docker). If you clone the Git repository, be sure to
remove the `.git` directory to prevent conflicts with the `.git` directory already in your existing project.
First, [download this skeleton](https://github.com/dunglas/symfony-docker).

Then, copy the Docker-related files from the skeleton to your existing project:
If you cloned the Git repository, be sure to not copy the `.git` directory to prevent conflicts with the `.git` directory already in your existing project.
You can copy the contents of the repository using git and tar. This will not contain `.git` or any uncommited changes.

git archive --format=tar HEAD | tar -xC my-existing-project/

If you downloaded the skeleton as a zip you can just copy the extracted files:

cp -Rp symfony-docker/. my-existing-project/

@@ -16,7 +20,7 @@ Enable the Docker support of Symfony Flex:
Re-execute the recipes to update the Docker-related files according to the packages you use

rm symfony.lock
composer symfony:sync-recipes --force --verbose
composer recipes:install --force --verbose

Double-check the changes, revert the changes that you don't want to keep:

8 changes: 7 additions & 1 deletion docs/extra-services.md
Original file line number Diff line number Diff line change
@@ -8,5 +8,11 @@ The currently supported packages are:
* `symfony/orm-pack`: install a PostgreSQL service
* `symfony/mercure-bundle`: use the Mercure.rocks module shipped with Caddy
* `symfony/panther`: install chromium and these drivers
* `symfony/mailer`: install a MailCatcher service
* `symfony/mailer`: install a Mailpit service
* `blackfireio/blackfire-symfony-meta`: install a Blackfire service

> [!NOTE]
> If a recipe modifies the Dockerfile, the container needs to be rebuilt.
> [!WARNING]
> We recommend that you use the `composer require` command inside the container in development mode so that recipes can be applied correctly
3 changes: 3 additions & 0 deletions docs/makefile.md
Original file line number Diff line number Diff line change
@@ -71,6 +71,9 @@ logs: ## Show live logs
sh: ## Connect to the FrankenPHP container
@$(PHP_CONT) sh

bash: ## Connect to the FrankenPHP container via bash so up and down arrows go to previous commands
@$(PHP_CONT) bash

test: ## Start tests with phpunit, pass the parameter "c=" to add options to phpunit, example: make test c="--group e2e --stop-on-failure"
@$(eval c ?=)
@$(DOCKER_COMP) exec -e APP_ENV=test php bin/phpunit $(c)
83 changes: 83 additions & 0 deletions docs/mysql.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Using MySQL

The Docker configuration of this repository is extensible thanks to Flex recipes. By default, the recipe installs PostgreSQL.
If you prefer to work with MySQL, follow these steps:

First, install the `symfony/orm-pack` package as described: `docker compose exec php composer req symfony/orm-pack`

## Docker Configuration
Change the database image to use MySQL instead of PostgreSQL in `compose.yaml`:

```diff
###> doctrine/doctrine-bundle ###
- image: postgres:${POSTGRES_VERSION:-15}-alpine
+ image: mysql:${MYSQL_VERSION:-8}
environment:
- POSTGRES_DB: ${POSTGRES_DB:-app}
+ MYSQL_DATABASE: ${MYSQL_DATABASE:-app}
# You should definitely change the password in production
+ MYSQL_RANDOM_ROOT_PASSWORD: "true"
- POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-!ChangeMe!}
+ MYSQL_PASSWORD: ${MYSQL_PASSWORD:-!ChangeMe!}
- POSTGRES_USER: ${POSTGRES_USER:-app}
+ MYSQL_USER: ${MYSQL_USER:-app}
healthcheck:
- test: ["CMD", "pg_isready", "-d", "${POSTGRES_DB:-app}", "-U", "${POSTGRES_USER:-app}"]
+ test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"]
timeout: 5s
retries: 5
start_period: 60s
volumes:
- - database_data:/var/lib/postgresql/data:rw
+ - database_data:/var/lib/mysql:rw
# You may use a bind-mounted host directory instead, so that it is harder to accidentally remove the volume and lose all your data!
- # - ./docker/db/data:/var/lib/postgresql/data:rw
+ # - ./docker/db/data:/var/lib/mysql:rw
###< doctrine/doctrine-bundle ###
```

Depending on the database configuration, modify the environment in the same file at `services.php.environment.DATABASE_URL`
```
DATABASE_URL: mysql://${MYSQL_USER:-app}:${MYSQL_PASSWORD:-!ChangeMe!}@database:3306/${MYSQL_DATABASE:-app}?serverVersion=${MYSQL_VERSION:-8}&charset=${MYSQL_CHARSET:-utf8mb4}
```

Since we changed the port, we also have to define this in the `compose.override.yaml`:
```diff
###> doctrine/doctrine-bundle ###
database:
ports:
- - "5432"
+ - "3306"
###< doctrine/doctrine-bundle ###
```

Last but not least, we need to install the MySQL driver in `Dockerfile`:
```diff
###> doctrine/doctrine-bundle ###
-RUN install-php-extensions pdo_pgsql
+RUN install-php-extensions pdo_mysql
###< doctrine/doctrine-bundle ###
```

## Change Environment
Change the database configuration in `.env`:

```dotenv
DATABASE_URL=mysql://${MYSQL_USER:-app}:${MYSQL_PASSWORD:-!ChangeMe!}@database:3306/${MYSQL_DATABASE:-app}?serverVersion=${MYSQL_VERSION:-8}&charset=${MYSQL_CHARSET:-utf8mb4}
```

## Final steps
Rebuild the docker environment:
```shell
docker compose down --remove-orphans && docker compose build --pull --no-cache
```

Start the services:
```shell
docker compose up -d
```

Test your setup:
```shell
docker compose exec php bin/console dbal:run-sql -q "SELECT 1" && echo "OK" || echo "Connection is not working"
```
Loading

0 comments on commit 119d25b

Please sign in to comment.