Skip to content

Commit

Permalink
Merge pull request #398 from PrestaShop/90x-docker
Browse files Browse the repository at this point in the history
Add possibility to build docker based on a branch
  • Loading branch information
jolelievre authored Oct 29, 2024
2 parents c3333f3 + c7c71e3 commit ff2200b
Show file tree
Hide file tree
Showing 19 changed files with 106 additions and 163 deletions.
9 changes: 9 additions & 0 deletions Dockerfile-branch.model
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM prestashop/base:$container_version
LABEL maintainer="PrestaShop Core Team <[email protected]>"

RUN apt update
RUN apt -y install git

RUN git clone -b $ps_version https://github.com/PrestaShop/PrestaShop.git /tmp/data-ps

CMD ["/tmp/docker_run.sh"]
9 changes: 9 additions & 0 deletions images/9.0.x/8.1-apache/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM prestashop/base:8.1-apache
LABEL maintainer="PrestaShop Core Team <[email protected]>"

RUN apt update
RUN apt -y install git

RUN git clone -b 9.0.x https://github.com/PrestaShop/PrestaShop.git /tmp/data-ps

CMD ["/tmp/docker_run.sh"]
9 changes: 9 additions & 0 deletions images/9.0.x/8.1-fpm/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM prestashop/base:8.1-fpm
LABEL maintainer="PrestaShop Core Team <[email protected]>"

RUN apt update
RUN apt -y install git

RUN git clone -b 9.0.x https://github.com/PrestaShop/PrestaShop.git /tmp/data-ps

CMD ["/tmp/docker_run.sh"]
9 changes: 9 additions & 0 deletions images/9.0.x/8.2-apache/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM prestashop/base:8.2-apache
LABEL maintainer="PrestaShop Core Team <[email protected]>"

RUN apt update
RUN apt -y install git

RUN git clone -b 9.0.x https://github.com/PrestaShop/PrestaShop.git /tmp/data-ps

CMD ["/tmp/docker_run.sh"]
9 changes: 9 additions & 0 deletions images/9.0.x/8.2-fpm/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM prestashop/base:8.2-fpm
LABEL maintainer="PrestaShop Core Team <[email protected]>"

RUN apt update
RUN apt -y install git

RUN git clone -b 9.0.x https://github.com/PrestaShop/PrestaShop.git /tmp/data-ps

CMD ["/tmp/docker_run.sh"]
9 changes: 9 additions & 0 deletions images/9.0.x/8.3-apache/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM prestashop/base:8.3-apache
LABEL maintainer="PrestaShop Core Team <[email protected]>"

RUN apt update
RUN apt -y install git

RUN git clone -b 9.0.x https://github.com/PrestaShop/PrestaShop.git /tmp/data-ps

CMD ["/tmp/docker_run.sh"]
9 changes: 9 additions & 0 deletions images/9.0.x/8.3-fpm/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM prestashop/base:8.3-fpm
LABEL maintainer="PrestaShop Core Team <[email protected]>"

RUN apt update
RUN apt -y install git

RUN git clone -b 9.0.x https://github.com/PrestaShop/PrestaShop.git /tmp/data-ps

CMD ["/tmp/docker_run.sh"]
20 changes: 0 additions & 20 deletions images/nightly/7.2-apache/Dockerfile

This file was deleted.

20 changes: 0 additions & 20 deletions images/nightly/7.2-fpm/Dockerfile

This file was deleted.

20 changes: 0 additions & 20 deletions images/nightly/7.3-apache/Dockerfile

This file was deleted.

20 changes: 0 additions & 20 deletions images/nightly/7.3-fpm/Dockerfile

This file was deleted.

20 changes: 0 additions & 20 deletions images/nightly/7.4-apache/Dockerfile

This file was deleted.

20 changes: 0 additions & 20 deletions images/nightly/7.4-fpm/Dockerfile

This file was deleted.

20 changes: 0 additions & 20 deletions images/nightly/8.0-apache/Dockerfile

This file was deleted.

20 changes: 0 additions & 20 deletions images/nightly/8.0-fpm/Dockerfile

This file was deleted.

3 changes: 2 additions & 1 deletion prestashop_docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ def main():
generator = Generator(
path.join(path.dirname(path.realpath(__file__)), 'images'),
open('./Dockerfile.model').read(),
open('./Dockerfile-nightly.model').read()
open('./Dockerfile-nightly.model').read(),
open('./Dockerfile-branch.model').read()
)
generator.generate_all(VERSIONS)
elif args.subcommand == 'tag':
Expand Down
7 changes: 6 additions & 1 deletion prestashop_docker/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
class Generator:
NIGHTLY = 'nightly'

def __init__(self, directory_path, template, nightly_template):
def __init__(self, directory_path, template, nightly_template, branch_template):
"""Constructor
@param directory_path: Directory path
Expand All @@ -17,13 +17,16 @@ def __init__(self, directory_path, template, nightly_template):
@type template: str
@param nightly_template: Nightly template
@type nightly_template: str
@param branch_template: Branch template
@type branch_template: str
"""
self.download_url = 'https://www.prestashop.com/download/old/' \
'prestashop_{}.zip'
self.download_url_github = 'https://github.com/PrestaShop/PrestaShop/releases/download/{}/prestashop_{}.zip'
self.directory_path = directory_path
self.template = Template(template)
self.nightly_template = Template(nightly_template)
self.branch_template = Template(branch_template)

def create_directory(self, directory_path):
"""Try to create a directory if it's possible
Expand Down Expand Up @@ -57,6 +60,8 @@ def generate_image(self, ps_version, container_version):
file_path = path.join(directory_path, 'Dockerfile')
template = self.nightly_template if (
ps_version == self.NIGHTLY
) else self.branch_template if (
ps_version.endswith('.x')
) else self.template

with open(file_path, 'w+') as f:
Expand Down
31 changes: 30 additions & 1 deletion tests/prestashop_docker/test_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,20 @@ def setUp(self):
CONTAINER_VERSION: $container_version
'''
)
self.fs.create_file(
'Dockerfile-branch.model',
contents='''
CONTAINER_VERSION: $container_version
RUN apt -y install git
RUN git clone -b $ps_version https://github.com/PrestaShop/PrestaShop.git /tmp/data-ps
'''
)

self.generator = Generator(
'/tmp/images',
open('Dockerfile.model').read(),
open('Dockerfile-nightly.model').read()
open('Dockerfile-nightly.model').read(),
open('Dockerfile-branch.model').read()
)

def test_create_directory(self):
Expand Down Expand Up @@ -92,6 +101,26 @@ def test_generate_nightly_image(self):
self.assertIn('PS_VERSION: nightly', content)
self.assertIn('CONTAINER_VERSION: 7.2-alpine', content)

def test_generate_branch_image(self):
dockerfile = '/tmp/images/9.0.x/8.1-alpine/Dockerfile'
self.assertFalse(path.exists(dockerfile))
self.generator.generate_image(
'9.0.x',
'8.1-alpine'
)
self.assertTrue(path.exists(dockerfile))

with open(dockerfile) as f:
content = f.read()
self.assertNotIn(
'PS_URL',
content
)
self.assertNotIn('PS_VERSION', content)
self.assertIn('CONTAINER_VERSION: 8.1-alpine', content)
self.assertIn('RUN apt -y install git', content)
self.assertIn('RUN git clone -b 9.0.x https://github.com/PrestaShop/PrestaShop.git /tmp/data-ps', content)

def test_generate_all(self):
files = (
'/tmp/images/7.0/7.3-apache/Dockerfile',
Expand Down
5 changes: 5 additions & 0 deletions versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,11 @@
'8.0',
'8.1',
),
'9.0.x': (
'8.1',
'8.2',
'8.3',
),
'nightly': (
'8.1',
'8.2',
Expand Down

0 comments on commit ff2200b

Please sign in to comment.