Skip to content

Commit 515faa6

Browse files
Merge pull request #426 from Quetzacoalt91/multi-platform
Enable build of multi-platform images (amd64, arm32 & arm64)
2 parents a7039c0 + b980460 commit 515faa6

12 files changed

Lines changed: 172 additions & 136 deletions

File tree

.github/workflows/publish.yml

Lines changed: 47 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,32 @@
11
---
2-
name: Publish containers
2+
name: Publish images
33

44
on:
55
push:
66
branches:
77
- master
88

99
jobs:
10-
publish_base:
10+
list_base_images:
11+
runs-on: ubuntu-latest
12+
outputs:
13+
versions: ${{ steps.set-versions.outputs.versions }}
14+
base_has_changed: ${{ steps.changes.outputs.base }}
15+
steps:
16+
- uses: actions/checkout@v2
17+
- id: set-versions
18+
run: echo "versions=$(ls base/images/ | jq -R -s -c 'split("\n")[:-1]')" >> $GITHUB_OUTPUT
19+
- uses: dorny/paths-filter@v2
20+
id: changes
21+
with:
22+
filters: |
23+
base:
24+
- 'base/**'
25+
26+
list_prestashop_images:
1127
runs-on: ubuntu-latest
28+
outputs:
29+
versions: ${{ steps.set-versions.outputs.versions }}
1230
steps:
1331
# Fetch versions to work for images
1432
- uses: actions/checkout@v2
@@ -19,52 +37,58 @@ jobs:
1937
- id: set-versions
2038
run: echo "versions=$(./get_json_versions.py)" >> $GITHUB_OUTPUT
2139

22-
# Push image base
40+
publish_base:
41+
runs-on: ubuntu-latest
42+
needs: list_base_images
43+
strategy:
44+
matrix:
45+
version: ${{ fromJson(needs.list_base_images.outputs.versions) }}
46+
steps:
2347
- name: Login to Docker Hub
2448
uses: docker/login-action@v2
2549
with:
2650
username: ${{ secrets.DOCKERHUB_USERNAME }}
2751
password: ${{ secrets.DOCKERHUB_TOKEN }}
28-
## Check if there are modifications in the base/ directory
29-
## and store it in the variable `steps.changes.outputs.base`
30-
## The variable is built like: steps.{#id}.outputs.{#filter}
31-
- uses: dorny/paths-filter@v2
32-
id: changes
33-
with:
34-
filters: |
35-
base:
36-
- 'base/**'
52+
53+
- name: Enable multi-platform builds
54+
run: docker buildx create --name container --driver=docker-container
55+
56+
- uses: actions/checkout@v2
3757

3858
- name: Base Images > Generate Tags
3959
run: ./generate_tags.sh
4060
working-directory: base
4161

4262
- name: Base Images > Docker Build Tags
43-
run: ./docker_tags.sh
63+
run: DOCKER_REPOSITORY=${{ vars.DOCKER_BASE_REPOSITORY}} ./docker_tags.sh --version ${{ matrix.version }}
4464
if: ${{ github.event_name == 'pull_request' }}
4565
working-directory: base
4666

4767
- name: Base Images > Docker Build & Force Push
48-
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' && steps.changes.outputs.base == 'true' }}
49-
run: ./docker_tags.sh -p -f
68+
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' && needs.list_base_images.outputs.base_has_changed == 'true' }}
69+
run: DOCKER_REPOSITORY=${{ vars.DOCKER_BASE_REPOSITORY}} ./docker_tags.sh -p -f --version ${{ matrix.version }}
5070
working-directory: base
51-
outputs:
52-
versions: ${{ steps.set-versions.outputs.versions }}
5371

54-
publish_images:
72+
73+
publish_prestashop:
5574
runs-on: ubuntu-latest
56-
needs: publish_base
75+
needs:
76+
- list_prestashop_images
77+
- publish_base
5778
strategy:
5879
fail-fast: false
5980
matrix:
60-
ps-version: ${{ fromJson(needs.publish_base.outputs.versions) }}
81+
ps-version: ${{ fromJson(needs.list_prestashop_images.outputs.versions) }}
6182
steps:
6283
- name: Login to Docker Hub
6384
uses: docker/login-action@v2
6485
with:
6586
username: ${{ secrets.DOCKERHUB_USERNAME }}
6687
password: ${{ secrets.DOCKERHUB_TOKEN }}
6788

89+
- name: Enable multi-platform builds
90+
run: docker buildx create --name container --driver=docker-container
91+
6892
- uses: actions/checkout@v2
6993
- name: Set up Python 3.8
7094
uses: actions/setup-python@v2
@@ -73,9 +97,7 @@ jobs:
7397
- name: Install dependencies
7498
run: pip install -r requirements.txt
7599

76-
- name: Build Docker images
77-
run: ./prestashop_docker.py --quiet tag build ${{ matrix.ps-version }} --force
78-
79-
- name: Push Docker images
100+
- name: Build & Push Docker images
80101
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }}
81-
run: ./prestashop_docker.py --quiet tag push ${{ matrix.ps-version }} --force
102+
run: DOCKER_REPOSITORY=${{ vars.DOCKER_REPOSITORY}} ./prestashop_docker.py --quiet tag push ${{ matrix.ps-version }} --force
103+

HOW-TO-USE.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ It requires Python 3.9+.
99
$ pip install -r requirements.txt --break-system-packages
1010
```
1111

12+
If you plan to build the images locally, you'll need to create a builder instance. This command just needs to be run one time.
13+
14+
```bash
15+
$ docker buildx create --name container --driver=docker-container
16+
```
17+
1218
## Usage
1319

1420
Display the help:
@@ -68,10 +74,10 @@ positional arguments:
6874
{exists,build,push,aliases}
6975
exists Check if tag exists on Docker Hub
7076
build Build container and create docker tag
71-
push Push docker tags
77+
push Build container and create docker tag then push docker tags
7278
aliases Get aliases
7379

74-
optional arguments:
80+
options:
7581
-h, --help show this help message and exit
7682
```
7783
@@ -126,7 +132,7 @@ $ nosetests --with-id 7
126132
127133
This will also generate a `.nodeids` binary file, when you add new test methods you need to remove this file to re-generate the list of IDs.
128134
129-
## Building and running PrestaShop docker locally
135+
## Building and running PrestaShop docker locally (local platform only, deprecated)
130136
131137
First to make sure you will use the local docker containers and not the ones from Docker hub make sure you remove all existing PrestaShop images (including the base images)
132138

base/docker_tags.sh

Lines changed: 57 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,72 @@
11
#!/bin/bash
22

3-
cd $(cd "$( dirname "$0" )" && pwd)
3+
: ${PLATFORM_ARGS:="linux/arm/v7,linux/arm64/v8,linux/amd64"}
4+
: ${DOCKER_REPOSITORY:="prestashop/base"}
45

5-
if [ -z "$1" ] || [ "$1" == "-p" ]; then
6-
PS_VERSIONS_FILE="tags.txt";
7-
else
8-
PS_VERSIONS_FILE="$1";
9-
fi
6+
set -e
7+
cd $(cd "$( dirname "$0" )" && pwd)
108

9+
# Default values
10+
PS_VERSIONS_FILE="tags.txt"
11+
SINGLE_VERSION=""
1112
FORCE=false
12-
while getopts ":fp" option; do
13-
case $option in
14-
p)
15-
PUSH=true
16-
;;
17-
f)
18-
FORCE=true
19-
;;
20-
esac
13+
PUSH=false
14+
15+
# Parse arguments
16+
while [[ $# -gt 0 ]]; do
17+
case "$1" in
18+
--version)
19+
SINGLE_VERSION="$2"
20+
shift 2
21+
;;
22+
--file)
23+
PS_VERSIONS_FILE="$2"
24+
shift 2
25+
;;
26+
-f)
27+
FORCE=true
28+
shift
29+
;;
30+
-p)
31+
PUSH=true
32+
shift
33+
;;
34+
*)
35+
echo "Unknown option: $1"
36+
echo "Usage: $0 [--version <version>] [--file <filename>] [-f] [-p]"
37+
exit 1
38+
;;
39+
esac
2140
done
2241

2342
docker_tag_exists() {
24-
curl --silent -f -lSL https://hub.docker.com/v2/repositories/$1/tags/$2 > /dev/null
43+
curl --silent -f -lSL https://hub.docker.com/v2/repositories/$1/tags/$2 > /dev/null 2>&1
2544
}
2645

27-
docker_image()
28-
{
29-
if ! $FORCE && docker_tag_exists prestashop/base ${version}; then
30-
echo "Docker Image already pushed : prestashop/base:$version"
46+
docker_image() {
47+
version="$1"
48+
if ! $FORCE && docker_tag_exists ${DOCKER_REPOSITORY} ${version}; then
49+
echo "Docker Image already pushed : $DOCKER_REPOSITORY:$version"
3150
return
3251
else
33-
echo "Docker build & tag : prestashop/base:$version"
34-
id=$(echo $(docker build --quiet=true images/${version} 2>/dev/null) | awk '{print $NF}')
35-
echo $id;
36-
docker tag $id prestashop/base:${version}
37-
38-
39-
if [ -z "$PUSH" ]; then
40-
# Do not push
41-
return
42-
fi
43-
echo "Docker Push : prestashop/base:$version"
44-
45-
docker push prestashop/base:${version}
52+
echo "Docker build & tag : $DOCKER_REPOSITORY:$version"
53+
docker buildx build \
54+
--progress=plain \
55+
--platform ${PLATFORM_ARGS} \
56+
--builder container \
57+
--tag ${DOCKER_REPOSITORY}:${version} \
58+
$([ "$PUSH" == "true" ] && echo "--push") \
59+
images/${version}
4660
fi
4761
}
4862

49-
50-
# Generate base images for PHP tags
51-
echo "Reading tags in ${PS_VERSIONS_FILE} ..."
52-
while read version; do
53-
docker_image $version
54-
done < $PS_VERSIONS_FILE
63+
if [ -n "$SINGLE_VERSION" ]; then
64+
echo "Building single version: $SINGLE_VERSION"
65+
docker_image "$SINGLE_VERSION"
66+
else
67+
echo "Reading tags in ${PS_VERSIONS_FILE} ..."
68+
while read -r version; do
69+
[ -z "$version" ] && continue
70+
docker_image "$version"
71+
done < "$PS_VERSIONS_FILE"
72+
fi

base/generate_tags.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ generate_image()
3131

3232
if [ -d images/$folder ] && [ -z "$FORCE" ]; then
3333
# Do not erase what we already defined in the directory
34-
echo Already defined, skipping Use -f to forcre update
34+
echo Already defined, skipping Use -f to force update
3535
return
3636
fi
3737

base/images/7.1-apache/Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ PS_HANDLE_DYNAMIC_DOMAIN=0 \
2424
PS_FOLDER_ADMIN=admin \
2525
PS_FOLDER_INSTALL=install
2626

27+
RUN sed -ie "s/deb.debian.org/archive.debian.org/g" /etc/apt/sources.list \
28+
&& sed -ie "s/security.debian.org/archive.debian.org/g" /etc/apt/sources.list \
29+
&& echo 'Sources list updated'
30+
2731
RUN apt-get update \
2832
&& apt-get install -y libmcrypt-dev \
2933
libjpeg62-turbo-dev \

base/images/7.1-fpm/Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ PS_HANDLE_DYNAMIC_DOMAIN=0 \
2424
PS_FOLDER_ADMIN=admin \
2525
PS_FOLDER_INSTALL=install
2626

27+
RUN sed -ie "s/deb.debian.org/archive.debian.org/g" /etc/apt/sources.list \
28+
&& sed -ie "s/security.debian.org/archive.debian.org/g" /etc/apt/sources.list \
29+
&& echo 'Sources list updated'
30+
2731
RUN apt-get update \
2832
&& apt-get install -y libmcrypt-dev \
2933
libjpeg62-turbo-dev \

base/images/7.2-apache/Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ PS_HANDLE_DYNAMIC_DOMAIN=0 \
2424
PS_FOLDER_ADMIN=admin \
2525
PS_FOLDER_INSTALL=install
2626

27+
RUN sed -ie "s/deb.debian.org/archive.debian.org/g" /etc/apt/sources.list \
28+
&& sed -ie "s/security.debian.org/archive.debian.org/g" /etc/apt/sources.list \
29+
&& echo 'Sources list updated'
30+
2731
RUN apt-get update \
2832
&& apt-get install -y libmcrypt-dev \
2933
libjpeg62-turbo-dev \

base/images/7.2-fpm/Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ PS_HANDLE_DYNAMIC_DOMAIN=0 \
2424
PS_FOLDER_ADMIN=admin \
2525
PS_FOLDER_INSTALL=install
2626

27+
RUN sed -ie "s/deb.debian.org/archive.debian.org/g" /etc/apt/sources.list \
28+
&& sed -ie "s/security.debian.org/archive.debian.org/g" /etc/apt/sources.list \
29+
&& echo 'Sources list updated'
30+
2731
RUN apt-get update \
2832
&& apt-get install -y libmcrypt-dev \
2933
libjpeg62-turbo-dev \

base/tags.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
1-
7.1-apache
2-
7.2-apache
31
7.3-apache
42
7.4-apache
53
8.0-apache
64
8.1-apache
75
8.2-apache
86
8.3-apache
97
8.4-apache
10-
7.1-fpm
11-
7.2-fpm
128
7.3-fpm
139
7.4-fpm
1410
8.0-fpm

prestashop_docker.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env python
22

33
import docker
4+
import os
45
from versions import VERSIONS
56
from prestashop_docker.backlog import Backlog
67
from prestashop_docker.generator import Generator
@@ -12,6 +13,8 @@
1213
import argparse
1314
import logging
1415

16+
docker_repository_name = os.getenv('DOCKER_REPOSITORY', 'prestashop/prestashop')
17+
1518

1619
def get_parser():
1720
parser = argparse.ArgumentParser(description='PrestaShop Docker manager.')
@@ -53,7 +56,7 @@ def get_tag_parser(subparser):
5356

5457
push_parser = tag_subparser.add_parser(
5558
'push',
56-
help='Push docker tags'
59+
help='Build container and create docker tag then push docker tags'
5760
)
5861
push_parser.add_argument('version', type=str, help='Version name', nargs='?')
5962
push_parser.add_argument('--force', action='store_const', const=True, help='Force build even if image already exists on Docker hub', default=False)
@@ -125,7 +128,8 @@ def main():
125128
docker.from_env(),
126129
VersionManager(path.join(path.dirname(path.realpath(__file__)), 'images')),
127130
args.cache,
128-
args.quiet
131+
args.quiet,
132+
docker_repository_name,
129133
)
130134
if args.tag_subcommand is None:
131135
tag_parser.print_help()
@@ -138,7 +142,7 @@ def main():
138142
elif args.tag_subcommand == 'build':
139143
tag_manager.build(args.version, args.force)
140144
elif args.tag_subcommand == 'push':
141-
tag_manager.push(args.version, args.force)
145+
tag_manager.build(args.version, args.force, True)
142146
elif args.tag_subcommand == 'aliases':
143147
tag_manager.get_aliases(args.version)
144148
else:

0 commit comments

Comments
 (0)