Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 47 additions & 25 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,32 @@
---
name: Publish containers
name: Publish images

on:
push:
branches:
- master

jobs:
publish_base:
list_base_images:
runs-on: ubuntu-latest
outputs:
versions: ${{ steps.set-versions.outputs.versions }}
base_has_changed: ${{ steps.changes.outputs.base }}
steps:
- uses: actions/checkout@v2
- id: set-versions
run: echo "versions=$(ls base/images/ | jq -R -s -c 'split("\n")[:-1]')" >> $GITHUB_OUTPUT
- uses: dorny/paths-filter@v2
id: changes
with:
filters: |
base:
- 'base/**'

list_prestashop_images:
runs-on: ubuntu-latest
outputs:
versions: ${{ steps.set-versions.outputs.versions }}
steps:
# Fetch versions to work for images
- uses: actions/checkout@v2
Expand All @@ -19,52 +37,58 @@ jobs:
- id: set-versions
run: echo "versions=$(./get_json_versions.py)" >> $GITHUB_OUTPUT

# Push image base
publish_base:
runs-on: ubuntu-latest
needs: list_base_images
strategy:
matrix:
version: ${{ fromJson(needs.list_base_images.outputs.versions) }}
steps:
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
## Check if there are modifications in the base/ directory
## and store it in the variable `steps.changes.outputs.base`
## The variable is built like: steps.{#id}.outputs.{#filter}
- uses: dorny/paths-filter@v2
id: changes
with:
filters: |
base:
- 'base/**'

- name: Enable multi-platform builds
run: docker buildx create --name container --driver=docker-container

- uses: actions/checkout@v2

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

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

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

publish_images:

publish_prestashop:
runs-on: ubuntu-latest
needs: publish_base
needs:
- list_prestashop_images
- publish_base
strategy:
fail-fast: false
matrix:
ps-version: ${{ fromJson(needs.publish_base.outputs.versions) }}
ps-version: ${{ fromJson(needs.list_prestashop_images.outputs.versions) }}
steps:
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Enable multi-platform builds
run: docker buildx create --name container --driver=docker-container

- uses: actions/checkout@v2
- name: Set up Python 3.8
uses: actions/setup-python@v2
Expand All @@ -73,9 +97,7 @@ jobs:
- name: Install dependencies
run: pip install -r requirements.txt

- name: Build Docker images
run: ./prestashop_docker.py --quiet tag build ${{ matrix.ps-version }} --force

- name: Push Docker images
- name: Build & Push Docker images
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }}
run: ./prestashop_docker.py --quiet tag push ${{ matrix.ps-version }} --force
run: DOCKER_REPOSITORY=${{ vars.DOCKER_REPOSITORY}} ./prestashop_docker.py --quiet tag push ${{ matrix.ps-version }} --force

12 changes: 9 additions & 3 deletions HOW-TO-USE.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ It requires Python 3.9+.
$ pip install -r requirements.txt --break-system-packages
```

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.

```bash
$ docker buildx create --name container --driver=docker-container
```

## Usage

Display the help:
Expand Down Expand Up @@ -68,10 +74,10 @@ positional arguments:
{exists,build,push,aliases}
exists Check if tag exists on Docker Hub
build Build container and create docker tag
push Push docker tags
push Build container and create docker tag then push docker tags
aliases Get aliases

optional arguments:
options:
-h, --help show this help message and exit
```

Expand Down Expand Up @@ -126,7 +132,7 @@ $ nosetests --with-id 7

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.

## Building and running PrestaShop docker locally
## Building and running PrestaShop docker locally (local platform only, deprecated)

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)

Expand Down
96 changes: 57 additions & 39 deletions base/docker_tags.sh
Original file line number Diff line number Diff line change
@@ -1,54 +1,72 @@
#!/bin/bash

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

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

# Default values
PS_VERSIONS_FILE="tags.txt"
SINGLE_VERSION=""
FORCE=false
while getopts ":fp" option; do
case $option in
p)
PUSH=true
;;
f)
FORCE=true
;;
esac
PUSH=false

# Parse arguments
while [[ $# -gt 0 ]]; do
case "$1" in
--version)
SINGLE_VERSION="$2"
shift 2
;;
--file)
PS_VERSIONS_FILE="$2"
shift 2
;;
-f)
FORCE=true
shift
;;
-p)
PUSH=true
shift
;;
*)
echo "Unknown option: $1"
echo "Usage: $0 [--version <version>] [--file <filename>] [-f] [-p]"
exit 1
;;
esac
done

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

docker_image()
{
if ! $FORCE && docker_tag_exists prestashop/base ${version}; then
echo "Docker Image already pushed : prestashop/base:$version"
docker_image() {
version="$1"
if ! $FORCE && docker_tag_exists ${DOCKER_REPOSITORY} ${version}; then
echo "Docker Image already pushed : $DOCKER_REPOSITORY:$version"
return
else
echo "Docker build & tag : prestashop/base:$version"
id=$(echo $(docker build --quiet=true images/${version} 2>/dev/null) | awk '{print $NF}')
echo $id;
docker tag $id prestashop/base:${version}


if [ -z "$PUSH" ]; then
# Do not push
return
fi
echo "Docker Push : prestashop/base:$version"

docker push prestashop/base:${version}
echo "Docker build & tag : $DOCKER_REPOSITORY:$version"
docker buildx build \
--progress=plain \
--platform ${PLATFORM_ARGS} \
--builder container \
--tag ${DOCKER_REPOSITORY}:${version} \
$([ "$PUSH" == "true" ] && echo "--push") \
images/${version}
fi
}


# Generate base images for PHP tags
echo "Reading tags in ${PS_VERSIONS_FILE} ..."
while read version; do
docker_image $version
done < $PS_VERSIONS_FILE
if [ -n "$SINGLE_VERSION" ]; then
echo "Building single version: $SINGLE_VERSION"
docker_image "$SINGLE_VERSION"
else
echo "Reading tags in ${PS_VERSIONS_FILE} ..."
while read -r version; do
[ -z "$version" ] && continue
docker_image "$version"
done < "$PS_VERSIONS_FILE"
fi
2 changes: 1 addition & 1 deletion base/generate_tags.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ generate_image()

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

Expand Down
4 changes: 4 additions & 0 deletions base/images/7.1-apache/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ PS_HANDLE_DYNAMIC_DOMAIN=0 \
PS_FOLDER_ADMIN=admin \
PS_FOLDER_INSTALL=install

RUN sed -ie "s/deb.debian.org/archive.debian.org/g" /etc/apt/sources.list \
&& sed -ie "s/security.debian.org/archive.debian.org/g" /etc/apt/sources.list \
&& echo 'Sources list updated'

RUN apt-get update \
&& apt-get install -y libmcrypt-dev \
libjpeg62-turbo-dev \
Expand Down
4 changes: 4 additions & 0 deletions base/images/7.1-fpm/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ PS_HANDLE_DYNAMIC_DOMAIN=0 \
PS_FOLDER_ADMIN=admin \
PS_FOLDER_INSTALL=install

RUN sed -ie "s/deb.debian.org/archive.debian.org/g" /etc/apt/sources.list \
&& sed -ie "s/security.debian.org/archive.debian.org/g" /etc/apt/sources.list \
&& echo 'Sources list updated'

RUN apt-get update \
&& apt-get install -y libmcrypt-dev \
libjpeg62-turbo-dev \
Expand Down
4 changes: 4 additions & 0 deletions base/images/7.2-apache/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ PS_HANDLE_DYNAMIC_DOMAIN=0 \
PS_FOLDER_ADMIN=admin \
PS_FOLDER_INSTALL=install

RUN sed -ie "s/deb.debian.org/archive.debian.org/g" /etc/apt/sources.list \
&& sed -ie "s/security.debian.org/archive.debian.org/g" /etc/apt/sources.list \
&& echo 'Sources list updated'

RUN apt-get update \
&& apt-get install -y libmcrypt-dev \
libjpeg62-turbo-dev \
Expand Down
4 changes: 4 additions & 0 deletions base/images/7.2-fpm/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ PS_HANDLE_DYNAMIC_DOMAIN=0 \
PS_FOLDER_ADMIN=admin \
PS_FOLDER_INSTALL=install

RUN sed -ie "s/deb.debian.org/archive.debian.org/g" /etc/apt/sources.list \
&& sed -ie "s/security.debian.org/archive.debian.org/g" /etc/apt/sources.list \
&& echo 'Sources list updated'

RUN apt-get update \
&& apt-get install -y libmcrypt-dev \
libjpeg62-turbo-dev \
Expand Down
4 changes: 0 additions & 4 deletions base/tags.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
7.1-apache
7.2-apache
7.3-apache
7.4-apache
8.0-apache
8.1-apache
8.2-apache
8.3-apache
8.4-apache
7.1-fpm
7.2-fpm
7.3-fpm
7.4-fpm
8.0-fpm
Expand Down
10 changes: 7 additions & 3 deletions prestashop_docker.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python

import docker
import os
from versions import VERSIONS
from prestashop_docker.backlog import Backlog
from prestashop_docker.generator import Generator
Expand All @@ -12,6 +13,8 @@
import argparse
import logging

docker_repository_name = os.getenv('DOCKER_REPOSITORY', 'prestashop/prestashop')


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

push_parser = tag_subparser.add_parser(
'push',
help='Push docker tags'
help='Build container and create docker tag then push docker tags'
)
push_parser.add_argument('version', type=str, help='Version name', nargs='?')
push_parser.add_argument('--force', action='store_const', const=True, help='Force build even if image already exists on Docker hub', default=False)
Expand Down Expand Up @@ -125,7 +128,8 @@ def main():
docker.from_env(),
VersionManager(path.join(path.dirname(path.realpath(__file__)), 'images')),
args.cache,
args.quiet
args.quiet,
docker_repository_name,
)
if args.tag_subcommand is None:
tag_parser.print_help()
Expand All @@ -138,7 +142,7 @@ def main():
elif args.tag_subcommand == 'build':
tag_manager.build(args.version, args.force)
elif args.tag_subcommand == 'push':
tag_manager.push(args.version, args.force)
tag_manager.build(args.version, args.force, True)
elif args.tag_subcommand == 'aliases':
tag_manager.get_aliases(args.version)
else:
Expand Down
2 changes: 1 addition & 1 deletion prestashop_docker/docker_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def __init__(self, cache, debug):
if self.cache:
requests_cache.install_cache('cache')

def get_tags(self, image_name='prestashop/prestashop'):
def get_tags(self, image_name):
"""Generate return tags

@return: The json content
Expand Down
Loading