Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(major): Add Debian support #10

Merged
merged 54 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
a888de5
WIP
jokesterfr Oct 11, 2023
2cd608f
Fix build script
jokesterfr Oct 12, 2023
d1c22b0
Fix paths
jokesterfr Oct 12, 2023
0c5c4f5
Enhance documentation and support
jokesterfr Oct 12, 2023
d38fa1d
Ignore local modules dir
jokesterfr Oct 12, 2023
569c7f8
Fix up debian release dependant script
jokesterfr Oct 12, 2023
02d1b5c
Pipefail not yet supported on debian sh
jokesterfr Oct 12, 2023
262170d
Add a pr github action workflow
jokesterfr Oct 12, 2023
f64bfbe
Enhance documentation and lint
jokesterfr Oct 12, 2023
2615ae3
Add hadolint support in github action
jokesterfr Oct 12, 2023
999a43a
Clarify php flavours
jokesterfr Oct 12, 2023
75a67f7
Test it out
jokesterfr Oct 12, 2023
78e8115
A bit better
jokesterfr Oct 12, 2023
fd8911a
Fix build and lint
jokesterfr Oct 12, 2023
aeada28
Add build test in CI
jokesterfr Oct 12, 2023
f6614ee
checkout was missing
jokesterfr Oct 12, 2023
c178811
Testing
jokesterfr Oct 12, 2023
e360efb
Quick fix
jokesterfr Oct 12, 2023
9948799
Update basic tools
jokesterfr Oct 12, 2023
881aa9e
Update docker/debian.Dockerfile
jokesterfr Oct 13, 2023
3ef1cc9
Update docker/debian.Dockerfile
jokesterfr Oct 13, 2023
936a31a
Update php-flavours.json
jokesterfr Oct 13, 2023
1537d6f
Switch to a table
jokesterfr Oct 13, 2023
ddf354a
Remove useless clean
jokesterfr Oct 13, 2023
9c92337
ci: Update actions
Venatum Oct 17, 2023
34e4792
fix: Mysql & php upload size
Venatum Oct 18, 2023
e938afd
A more generic mysql configuration
jokesterfr Oct 24, 2023
eab2d8c
swap from runuser to a more generic sudo
jokesterfr Oct 25, 2023
4eeeb76
Better configuration of gd
jokesterfr Oct 25, 2023
e01e345
Installation with error logs if any and avoid bin/console issue on PS1.6
jokesterfr Oct 25, 2023
d5b1930
New version dimension to the CI Matrix
jokesterfr Oct 25, 2023
c246b62
Fix linting issue
jokesterfr Oct 25, 2023
e066a50
Merge branch 'main' into fea/debian-flavour
jokesterfr Oct 25, 2023
92792fc
Handle both php7.1 and upper
jokesterfr Oct 25, 2023
0b6999e
Merge branch 'toto' into fea/debian-flavour
jokesterfr Oct 25, 2023
3078145
Try again
jokesterfr Oct 25, 2023
f9da2c5
Lint fix
jokesterfr Oct 25, 2023
36822eb
fix
jokesterfr Oct 25, 2023
a89da80
Fixes it all back again
jokesterfr Oct 25, 2023
a4e8371
d
jokesterfr Oct 25, 2023
e7b5eb1
Adds dry run mode
jokesterfr Oct 25, 2023
ef2ccf9
Should make this all work hopefully
jokesterfr Oct 25, 2023
a1c0ec4
Naming accuracy
jokesterfr Oct 25, 2023
196dcc6
Adds an extra tag
jokesterfr Oct 25, 2023
7383fa5
Dry run testing FTW
jokesterfr Oct 25, 2023
80c34a9
Cosmetic
jokesterfr Oct 25, 2023
f64d112
Last bafouille
jokesterfr Oct 25, 2023
f459418
attempt
jokesterfr Oct 26, 2023
132e9bb
Fix multiline
jokesterfr Oct 26, 2023
31166bb
Enhance env
jokesterfr Oct 26, 2023
428e5b8
Add mention for PS 1.6
jokesterfr Oct 26, 2023
b5537d9
Disclaimer notice on 1.6
jokesterfr Oct 26, 2023
6ea71d5
Patch 1.6 FTW
jokesterfr Oct 26, 2023
c96c8e8
lint bim
jokesterfr Oct 26, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 19 additions & 17 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,24 @@ on:
tags: ["v*.*.*"]
workflow_dispatch:
inputs:
# flavour:
# description: 'PrestaShop flavour'
# required: true
# default: 'alpine'
# type: choice
# options:
# - debian
# - alpine
# server:
# description: 'PrestaShop server'
# required: true
# default: 'nginx'
# type: choice
# options:
# - nginx
# - apache
flavour:
description: "OS flavour"
required: false
default: "alpine"
type: choice
options:
- alpine
- debian

server:
description: "Server flavour"
required: false
default: "nginx"
type: choice
options:
- nginx
- apache

ps_version:
description: "The target PrestaShop version (defaults to 'latest')"
required: false
Expand Down Expand Up @@ -77,4 +79,4 @@ jobs:
PS_VERSION: ${{ inputs.ps_version }}
PHP_VERSION: ${{ inputs.php_version }}
TAG: ${{ inputs.tag }}
PUSH: true
PUSH: "true"
38 changes: 38 additions & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Pull Request
on:
pull_request:
types: [opened, reopened, synchronize]

jobs:
lint_shell:
name: "Lint: shell"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Run ShellCheck
uses: ludeeus/action-shellcheck@master

lint_dockerfile:
name: "Lint: dockerfile"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: hadolint/hadolint-action@v3.1.0
with:
recursive: true
dockerfile: "*.Dockerfile"

docker_build:
runs-on: ubuntu-latest
strategy:
matrix:
os_flavour: ["alpine", "debian"]
name: "Docker build: ${{ matrix.os_flavour }}"
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Call the docker build chain
run: ./build.sh
env:
OS_FLAVOUR: ${{ matrix.os_flavour }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
.DS_Store
.*.swp
*.sql
modules/

# Sonar
.scannerwork
Expand Down
6 changes: 6 additions & 0 deletions .hadolint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
ignored:
- DL3006
- DL3008
- DL3009
- DL3018
- SC1091
104 changes: 57 additions & 47 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,34 @@

Spin a Prestashop testing instance in seconds!

> **⚠️ Disclaimer**: the following tool is provided in the sole purpose of bootstraping a PrestaShop testing environment. <br>If you look for a production grade image, please refer to https://github.com/PrestaShop/docker.

> **Note**: no MySQL server is shipped in the resulting image, you have to provide your own instance for the backup to be dumped during the first connection.
PrestaShop FlashLight is fast: the installation process with default content for a PrestaShop is tackled at build time, compiling the result to a single database dump.

Compatible with these architecture:
Supported architectures:

- linux/amd64 (akka `x86_64`)
- linux/arm64/v8 (akka `arm64`)

The resulting image is based on this tech stack:

- An [Alpine](https://www.alpinelinux.org/) linux image
- An [Nginx](https://www.nginx.com/) server
At runtime the dump is tweaked and consumed, providing a fast instance bootstrap.

## How fast is it?

On a Mac M1 (_linux/arm64_) computer:

```
❯ docker compose up -d
[+] Building 0.0s (0/0)
[+] Running 3/3
✔ Container phpmyadmin Running 0.0s
✔ Container mysql Healthy 10.8s
✔ Container prestashop Started 11.1s
```
> **⚠️ Disclaimer**: the following tool is provided in the sole purpose of bootstraping a PrestaShop testing environment. <br>If you look for a production grade image, please refer to https://github.com/PrestaShop/docker.

VS the official production image (_linux/amd64_ only) with `AUTO_INSTALL=1`: 2mn 15s.
> **Note**: no MySQL server is shipped in the resulting image, you have to provide your own instance for the backup to be dumped during the first connection.

## Where do I find pre-built images?

Here: https://hub.docker.com/r/prestashop/prestashop-flashlight

## Use

Start the environment
Start the environment:

```sh
cp .env.dist .env
edit .env
docker compose up
```

Add init scripts
You can also tweak the provided `docker-compose.yml` file, and for example, add init scripts:

```yaml
services:
Expand All @@ -55,28 +39,9 @@ services:
- ./init-scripts:/tmp/init-scripts:ro
```

## Build

Requirements:
* [jq](https://jqlang.github.io/jq/)
| **⚠️ Note:** your scripts **MUST** be executable, and have a [shebang](<https://en.wikipedia.org/wiki/Shebang_(Unix)>) to be run by flashlight at startup. Otherwise they would be ignored.

To build the latest PrestaShop version, simply:

```sh
./build.sh
```

For a custom multiplatform build & push:

```sh
PS_VERSION=8.1.0 \
PLATFORM=linux/amd64,linux/arm64 \
PUSH=true \
TARGET_IMAGE=my-own-repo/testing:latest \
./build.sh
```

## Container environment variables
## Run environment variables

- **`PS_DOMAIN`**
- Description: the public domain (and port) to reach your PrestaShop instance
Expand Down Expand Up @@ -111,9 +76,54 @@ TARGET_IMAGE=my-own-repo/testing:latest \
- If set to `continue`, PrestaShop Flashlight will continue the boot process even if an init script failed
- Default to `fail`

## Api calls within a docker network
# Develop

## Build

Requirements:

- [jq](https://jqlang.github.io/jq/)

To build the latest PrestaShop version, simply:

```sh
./build.sh
```

For a custom multiplatform build & push:

```sh
PS_VERSION=8.1.0 \
PLATFORM=linux/amd64,linux/arm64 \
PUSH=true \
TARGET_IMAGE=my-own-repo/testing:latest \
./build.sh
```

The `OS_FLAVOUR` defaults to `alpine` (see [Alpine Linux](https://www.alpinelinux.org/)) and `SERVER_FLAVOUR` to `nginx` (see [Nginx](https://www.nginx.com/)).
jokesterfr marked this conversation as resolved.
Show resolved Hide resolved

For more documentation about available build variables, please see [./build.sh](./build.sh).

## Lint

Requirements:

- [shellcheck](https://github.com/koalaman/shellcheck)
- [hadolint](https://github.com/hadolint/hadolint)

```sh
# Lint bash scripts
find . -type f \( -name '*.sh' \) | xargs shellcheck -x -s bash;

# Lint docker files
find . -type f \( -name '*.Dockerfile' \) | xargs hadolint;
```

## Q&A

### Let's talk about API calls within a docker network

**Disclaimer**: PrestaShop is sensitive to the `Host` header of your client, and can behave surprisingly. In fact, since the Multi-shop feature is available, you cannot just call any front controller from any endpoint, unless... You set the ` Host` or the `id_shop` you are targeting.
**Disclaimer**: PrestaShop is sensitive to the `Host` header of your client, and can behave surprisingly. In fact, since the Multi-shop feature is available, you cannot just call any front controller from any endpoint, unless... You set the ` Host` or the `id_shop` you are targeting.

Let's explain this subtle - rather mandatory - knowledge:

Expand Down Expand Up @@ -187,7 +197,7 @@ server {
}
```

## Credits
# Credits

- https://github.com/PrestaShop/PrestaShop
- https://github.com/PrestaShop/performance-project
Expand Down
27 changes: 19 additions & 8 deletions assets/hydrate.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#!/bin/sh
set -euo pipefail
#!/bin/bash
set -eu

# 1. ENV vars configuration
# 1. Settings
PS_FOLDER=${PS_FOLDER:?missing PS_FOLDER}
PS_CACHE_DIR="${PS_FOLDER}/var/cache"
PS_LOGS_DIR="${PS_FOLDER}/var/logs"
DUMP_FILE="/dump.sql"

export PS_DOMAIN="replace-me.com" \
DB_SERVER=127.0.0.1 \
DB_PORT=3306 \
Expand All @@ -21,7 +25,7 @@ mkdir -p /run/mysqld /var/lib/mysql/;
mysql_install_db \
--user=root \
--ldata=/var/lib/mysql/ > /dev/null;
nohup /usr/bin/mysqld --user=root --skip-networking=0 --port=${DB_PORT} --socket=${DB_SOCKET} &
nohup mysqld --user=root --skip-networking=0 --port=${DB_PORT} --socket=${DB_SOCKET} &
while [ ! -S ${DB_SOCKET} ]; do sleep 0.1; done
while ! nc -z localhost ${DB_PORT}; do sleep 0.1; done
echo "✅ MySQL started"
Expand All @@ -31,14 +35,14 @@ mysqladmin --no-defaults --protocol=socket --user=root --password= password ${DB
mysqladmin --no-defaults --protocol=socket --user=root --password=${DB_PASSWD} create ${DB_NAME}

# 4. Connectivity test (both the unix socket file and DB_SERVER:DB_PORT)
php -r "new PDO('mysql:unix_socket="${DB_SOCKET}";dbname="${DB_NAME}"', '"${DB_USER}"', '"${DB_PASSWD}"');"
php -r "new PDO('mysql:host="${DB_SERVER}";port="${DB_PORT}";dbname="${DB_NAME}"', '"${DB_USER}"', '"${DB_PASSWD}"');"
php -r "new PDO('mysql:unix_socket=""$DB_SOCKET"";dbname=""$DB_NAME""', '""$DB_USER""', '""$DB_PASSWD""');"
php -r "new PDO('mysql:host=""$DB_SERVER"";port=""$DB_PORT"";dbname=""$DB_NAME""', '""$DB_USER""', '""$DB_PASSWD""');"
echo "✅ PHP PDO connectivity test"

# 5. Run the PrestaShop installer
# see: https://devdocs.prestashop-project.org/8/basics/installation/install-from-cli/
runuser -g www-data -u www-data -- \
php -d memory_limit=-1 ${PS_FOLDER}/install/index_cli.php \
php -d memory_limit=-1 "${PS_FOLDER}/install/index_cli.php" \
--domain=$PS_DOMAIN \
--db_create=1 \
--db_server=${DB_SERVER}:${DB_PORT} \
Expand Down Expand Up @@ -71,4 +75,11 @@ php -d memory_limit=-1 bin/console cache:clear
killall mysqld;

# 9. Some clean up
mv ${PS_FOLDER}/admin ${PS_FOLDER}/${PS_FOLDER_ADMIN}
mv "${PS_FOLDER}/admin" "${PS_FOLDER}/${PS_FOLDER_ADMIN}"
rm -rf \
"$PS_FOLDER/install" \
"$PS_FOLDER/Install_PrestaShop.html" \
"$PS_CACHE_DIR" \
"$PS_LOGS_DIR"
mkdir -p "$PS_CACHE_DIR" "$PS_LOGS_DIR"
chown -R www-data:www-data "$PS_CACHE_DIR" "$PS_LOGS_DIR"
2 changes: 1 addition & 1 deletion assets/php.ini
Original file line number Diff line number Diff line change
@@ -1 +1 @@
memory_limit=512M
memory_limit=-1