Skip to content

Commit fab56fc

Browse files
committed
Enable build of multi-platform images thanks to docker buildx
1 parent 2bf8a5e commit fab56fc

File tree

4 files changed

+37
-74
lines changed

4 files changed

+37
-74
lines changed

base/docker_tags.sh

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#!/bin/bash
22

3+
declare PLATFORM_ARGS="linux/arm/v7,linux/arm64/v8,linux/amd64"
4+
declare DOCKER_REPOSITORY="prestashop/base"
5+
36
cd $(cd "$( dirname "$0" )" && pwd)
47

58
if [ -z "$1" ] || [ "$1" == "-p" ]; then
@@ -21,28 +24,23 @@ while getopts ":fp" option; do
2124
done
2225

2326
docker_tag_exists() {
24-
curl --silent -f -lSL https://hub.docker.com/v2/repositories/$1/tags/$2 > /dev/null
27+
curl --silent -f -lSL https://hub.docker.com/v2/repositories/$1/tags/$2 2> /dev/null
2528
}
2629

2730
docker_image()
2831
{
29-
if ! $FORCE && docker_tag_exists prestashop/base ${version}; then
30-
echo "Docker Image already pushed : prestashop/base:$version"
32+
if ! $FORCE && docker_tag_exists ${DOCKER_REPOSITORY} ${version}; then
33+
echo "Docker Image already pushed : $DOCKER_REPOSITORY:$version"
3134
return
3235
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}
36+
echo "Docker build & tag : $DOCKER_REPOSITORY:$version"
37+
docker buildx build \
38+
--progress=plain \
39+
--platform ${PLATFORM_ARGS} \
40+
--builder container \
41+
--tag ${DOCKER_REPOSITORY}:${version} \
42+
$([ "${PUSH}" == "true" ] && echo "--push" || echo "") \
43+
images/${version}
4644
fi
4745
}
4846

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

prestashop_docker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def main():
113113
elif args.tag_subcommand == 'build':
114114
tag_manager.build(args.version, args.force)
115115
elif args.tag_subcommand == 'push':
116-
tag_manager.push(args.version, args.force)
116+
tag_manager.build(args.version, args.force, true)
117117
elif args.tag_subcommand == 'aliases':
118118
tag_manager.get_aliases(args.version)
119119
else:

prestashop_docker/tag_manager.py

Lines changed: 21 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def __init__(self, docker_api, docker_client, version_manager, cache, quiet):
2727
self.cache = cache
2828
self.tags = None
2929

30-
def build(self, version=None, force=False):
30+
def build(self, version=None, force=False, push=False):
3131
'''
3232
Build version on the current machine
3333
@@ -46,68 +46,33 @@ def build(self, version=None, force=False):
4646
# Do not build images that already exists on Docker Hub
4747
continue
4848

49-
log = self.docker_client.api.build(
50-
path=str(version_path),
51-
tag='prestashop/prestashop:' + version,
52-
rm=True,
53-
nocache=(not self.cache),
54-
decode=True
55-
)
56-
57-
self.stream.display(log)
49+
if not shutil.which("docker"):
50+
raise RuntimeError("The docker client must be installed")
5851

52+
tags=["--tag", "prestashop/prestashop:" + version]
5953
aliases = self.version_manager.get_aliases()
6054
if version in aliases:
6155
for alias in aliases[version]:
62-
print(
63-
'Create tag {}'.format(alias)
64-
)
65-
self.docker_client.api.tag(
66-
'prestashop/prestashop:' + version,
67-
'prestashop/prestashop',
68-
alias
69-
)
70-
71-
def push(self, version=None, force=False):
72-
'''
73-
Push version on Docker Hub
74-
75-
@param version: Optional version you want to build
76-
@type version: str
77-
'''
78-
versions = self.get_versions(version)
79-
80-
for version in versions.keys():
81-
print(
82-
'Pushing {}'.format(version)
83-
)
84-
85-
if not force and self.exists(version):
86-
continue
87-
88-
log = self.docker_client.api.push(
89-
repository='prestashop/prestashop',
90-
tag=version,
91-
decode=True,
92-
stream=True
93-
)
56+
print('Will be aliased as tag {}'.format(alias))
57+
tags = tags + ["--tag", "prestashop/prestashop:" + alias]
58+
59+
args = []
60+
if push:
61+
args.append('--push')
62+
if not self.cache
63+
args.append('--no-cache')
64+
65+
cmd_args = ["docker", "buildx", "build",
66+
"--platform", "linux/arm/v7,linux/arm64/v8,linux/amd64",
67+
"--builder", "container",
68+
] + tags + args + [
69+
str(version_path)
70+
]
71+
72+
log = subprocess.Popen(cmd_args, shell=True, stdout=subprocess.PIPE).stdout.read()
9473

9574
self.stream.display(log)
9675

97-
aliases = self.version_manager.get_aliases()
98-
if version in aliases:
99-
for alias in aliases[version]:
100-
print(
101-
'Pushing tag {}'.format(alias)
102-
)
103-
log = self.docker_client.api.push(
104-
repository='prestashop/prestashop',
105-
tag=alias,
106-
decode=True,
107-
stream=True
108-
)
109-
self.stream.display(log)
110-
11176
def exists(self, version):
11277
'''
11378
Test if a version is already on Docker Hub

0 commit comments

Comments
 (0)