Skip to content

Commit

Permalink
PLGCSCS-154: Improvement over docker development environment
Browse files Browse the repository at this point in the history
  • Loading branch information
danielcivit committed Oct 9, 2024
1 parent c7b4b6e commit cc91e4f
Show file tree
Hide file tree
Showing 9 changed files with 149 additions and 74 deletions.
5 changes: 5 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
EXPOSE_HOST=multisafepay.io
EXPOSE_TOKEN=
APP_SUBDOMAIN=cscart-xxx
MYSQL_TABLE_PREFIX=cscart_
MYSQL_DATABASE=cscart
MYSQL_USER=cscart
MYSQL_PASSWORD=cscart
CSCART_VERSION=4.x.x.x
CSCART_LICENSE_KEY=YOUR_LICENSE_KEY
CSCART_ADMIN_EMAIL=[email protected]
CSCART_ADMIN_PASSWORD=admin
37 changes: 23 additions & 14 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,32 +1,41 @@
on:
push:
tags:
- '*' # Push events to matching v*, i.e. v1.0, v20.15.10
- '*'
name: Upload Release Asset
jobs:
build:
name: Upload Release Asset # Name of the job
runs-on: ubuntu-latest # or windows-latest, macOS-latest
name: Upload Release Asset
runs-on: ubuntu-latest
steps:
- name: Setup PHP Action
uses: shivammathur/setup-php@v2
with:
php-version: '7.2'
- name: Get the version
id: get_version
run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//} # Extract the version number from the tag
run: echo "VERSION=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV
- name: Checkout code
uses: actions/checkout@v2 # Checkout the code
uses: actions/checkout@v2
- name: Build project
run: ./bin/release.sh ${{ steps.get_version.outputs.VERSION }} # Build the project
run: ./bin/release.sh ${{ steps.get_version.outputs.VERSION }}
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.get_version.outputs.VERSION }}
release_name: Release ${{ steps.get_version.outputs.VERSION }}
draft: true
prerelease: false
- name: Upload Release Asset
run: |
set -x
assets=()
for asset in ./.dist/*.zip; do
assets+=("-a" "$asset")
done
tag_name="${GITHUB_REF##*/}"
hub release create "${assets[@]}" -m "Release $tag_name" "$tag_name" -d
id: upload-release-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./.dist/Plugin_CS-Cart_${{ steps.get_version.outputs.VERSION }}.zip
asset_name: Plugin_CS-Cart_${{ steps.get_version.outputs.VERSION }}.zip
asset_content_type: application/zip
10 changes: 7 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
.DS_Store
.dist
.env
/.idea
/cscart
.dist
.idea
/application
/cscart/*
!/cscart/.gitkeep
/source/*
!/source/.gitkeep
58 changes: 31 additions & 27 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
FROM php:7.3-apache
FROM php:8.1-apache

RUN apt-get update && apt-get upgrade -y
ARG DEBIAN_FRONTEND=noninteractive
ENV TZ=Europe/Amsterdam
RUN apt-get install -y software-properties-common git curl zip mariadb-client libicu-dev libxml2-dev libxslt-dev libfreetype6-dev libjpeg-dev libpng-dev libzip-dev libcurl3-dev
RUN apt-get install -y software-properties-common git curl zip mariadb-client libicu-dev libxml2-dev libxslt-dev libfreetype6-dev libjpeg-dev libpng-dev libzip-dev libcurl3-dev libonig-dev openssl nano

# set up mailhog connection
RUN debconf-set-selections << "postfix postfix/main_mailer_type string 'Internet Site'"
RUN echo "postfix postfix/main_mailer_type string 'Internet Site'" | debconf-set-selections
RUN apt-get install --assume-yes postfix
RUN sed -i -E "s/( *relayhost *= *).*/\1[mail]:1025/g" /etc/postfix/main.cf

RUN pecl install xdebug-3.1.0 && docker-php-ext-enable xdebug
RUN { \
echo 'xdebug.mode=debug'; \
echo 'xdebug.start_with_request=trigger'; \
echo 'xdebug.client_host=host.docker.internal'; \
echo 'xdebug.idekey=PHPSTORM'; \
} | tee -a "/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini"
echo 'xdebug.mode=debug'; \
echo 'xdebug.start_with_request=trigger'; \
echo 'xdebug.client_host=host.docker.internal'; \
echo 'xdebug.idekey=PHPSTORM'; \
echo 'discover_client_host=1'; \
echo 'xdebug.client_port=9003'; \
} | tee -a "/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini"
RUN rm -rf /var/www/html

#install CS Cart dependencies
Expand All @@ -28,26 +30,28 @@ RUN apt-get update && apt-get install -y \
RUN curl https://raw.githubusercontent.com/colinmollenhour/modman/master/modman --silent --output /usr/local/bin/modman && chmod +x /usr/local/bin/modman

RUN { \
echo '<FilesMatch \.php$>'; \
echo '\tSetHandler application/x-httpd-php'; \
echo '</FilesMatch>'; \
echo; \
echo 'DirectoryIndex disabled'; \
echo 'DirectoryIndex index.php index.html'; \
echo; \
echo '<Directory /var/www/html/>'; \
echo '\tOptions +Indexes +FollowSymLinks'; \
echo '\tAllowOverride All'; \
echo '\tRequire all granted'; \
echo '\tOrder allow,deny'; \
echo '\tAllow from all'; \
echo '\tSetEnvIf X-Forwarded-Proto https HTTPS=on'; \
echo '\tSetEnvIf X-Forwarded-Host ^(.+) HTTP_X_FORWARDED_HOST=$1'; \
echo '\tRequestHeader set Host %{HTTP_X_FORWARDED_HOST}e env=HTTP_X_FORWARDED_HOST'; \
echo '</Directory>'; \
} | tee "/etc/apache2/conf-available/docker-php.conf" \
&& a2enconf docker-php && a2enmod headers && a2enmod rewrite
echo '<FilesMatch \.php$>'; \
echo '\tSetHandler application/x-httpd-php'; \
echo '</FilesMatch>'; \
echo; \
echo 'DirectoryIndex disabled'; \
echo 'DirectoryIndex index.php index.html'; \
echo; \
echo '<Directory /var/www/html/>'; \
echo '\tOptions +Indexes +FollowSymLinks'; \
echo '\tAllowOverride All'; \
echo '\tRequire all granted'; \
echo '\tOrder allow,deny'; \
echo '\tAllow from all'; \
echo '\tSetEnvIf X-Forwarded-Proto https HTTPS=on'; \
echo '\tSetEnvIf X-Forwarded-Host ^(.+) HTTP_X_FORWARDED_HOST=$1'; \
echo '\tRequestHeader set Host %{HTTP_X_FORWARDED_HOST}e env=HTTP_X_FORWARDED_HOST'; \
echo '</Directory>'; \
} | tee "/etc/apache2/conf-available/docker-php.conf" \
&& a2enconf docker-php && a2enmod headers && a2enmod rewrite

RUN chown -R www-data:www-data /var/www/

EXPOSE 9003

USER www-data
73 changes: 61 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,30 +1,80 @@
include .env
export

# Escape "@" in the admin email to avoid issues with sed
CSCART_ESCAPED_ADMIN_EMAIL = $(subst @,\@,${CSCART_ADMIN_EMAIL})

# Escape "/" and "&" as they have a special meaning in sed and can be part of the password
CSCART_ESCAPED_ADMIN_PASSWORD = $(shell echo "${CSCART_ADMIN_PASSWORD}" | sed 's/[\/&]/\\&/g')

# Generate the secret key using openssl and base64, and escape special characters for later usage with sed
CSCART_SECRET_KEY := $(shell openssl rand -base64 32 | sed -e 's/[+/=]/\\&/g')

.PHONY: install
install: install-cscart install-multisafepay
install: validate-email deploy-cscart run-cscart-installer install-multisafepay

.PHONY: validate-email
validate-email:
@# NOTE: Character "@" suppresses the output of the command or line
@if ! echo "${CSCART_ADMIN_EMAIL}" | grep -E '^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$$' > /dev/null; then \
echo "\nInvalid email address: ${CSCART_ADMIN_EMAIL}.\n\nExiting the script.\n"; \
exit 1; \
fi

.PHONY: check-folder-empty
check-folder-empty:
@echo "Please enter your superuser credentials to allow deletion of necessary files and folders in the './cscart' directory:"
@# Delete all files in cscart directory (except the root .gitkeep and .modman folder and its content).
@# This deletion avoid conflicts with other previous installations, including different CS-Cart versions
@sudo -k find ./cscart -mindepth 1 ! -path './cscart/.gitkeep' ! -path './cscart/.modman/multisafepay' -delete
@# Check if the folder contains other than .gitkeep file and -modman folder (including its content)
@if [ $$(find ./cscart -mindepth 1 -maxdepth 1 ! -path './cscart/.modman' ! -path './cscart/.modman/*' | wc -l) -ne 1 ]; then \
echo "\nNot all files in the './cscart' folder were removed.\n\nPlease manually delete its contents, except for the root '.gitkeep' file and the '.modman' folder.\n"; \
exit 1; \
fi

.PHONY: install-cscart
install-cscart: download-cscart run-cscart-installer install-multisafepay
.PHONY: deploy-cscart
deploy-cscart: check-folder-empty
@# Decompress the CS-Cart archive to the cscart directory
unzip -o ./source/cscart_v${CSCART_VERSION}.zip -d ./cscart

.PHONY: run-cscart-installer
run-cscart-installer:
docker-compose exec app curl -o /tmp/wait-for-it.sh https://raw.githubusercontent.com/vishnubob/wait-for-it/master/wait-for-it.sh
docker-compose exec app chmod +x /tmp/wait-for-it.sh
docker-compose exec app /tmp/wait-for-it.sh db:3306 --timeout=30
docker-compose exec app sed -i 's/CART-1111-1111-1111-1111/${CSCART_LICENSE_KEY}/' install/config.php
@# In the first segment of the sed command, the "@" in the email doesn’t need escaping since it’s a literal string, not a variable
docker-compose exec app sed -i 's/[email protected]/${CSCART_ESCAPED_ADMIN_EMAIL}/' install/config.php
docker-compose exec app sed -i 's/admin/${CSCART_ESCAPED_ADMIN_PASSWORD}/' install/config.php
docker-compose exec app sed -i 's/YOURVERYSECRETCEY/${CSCART_SECRET_KEY}/' install/config.php
@# Delete in the config file non existing languages: "bg" and "sl"
docker-compose exec app sed -i "s/'bg', 'no', 'sl'/'no'/" install/config.php
docker-compose exec app sed -i 's/localhost/db:3306/' install/config.php
docker-compose exec app sed -i 's/%DB_NAME%/${MYSQL_DATABASE}/' install/config.php
docker-compose exec app sed -i 's/%DB_USER%/${MYSQL_USER}/' install/config.php
docker-compose exec app sed -i 's/%DB_PASS%/${MYSQL_PASSWORD}/' install/config.php
docker-compose exec app sed -i 's/%HTTP_HOST%/https:\/\/${APP_SUBDOMAIN}.${EXPOSE_HOST}/' install/config.php
docker-compose exec app /bin/sh -c 'cd install && php index.php'
docker-compose exec app mysql -hdb -u${MYSQL_USER} -p${MYSQL_PASSWORD} ${MYSQL_DATABASE} -e "UPDATE cscart_settings_objects SET value = 'Y' WHERE name = 'secure_admin' OR name = 'secure_storefront'"

.PHONY: download-cscart
download-cscart:
docker-compose exec app curl -L "https://www.cs-cart.com/index.php?dispatch=pages.get_trial&page_id=297&edition=ultimate" -o cscart.zip -s
docker-compose exec app unzip -o -q cscart.zip
docker-compose exec app mysql -h db -u ${MYSQL_USER} -p${MYSQL_PASSWORD} ${MYSQL_DATABASE} -e "UPDATE ${MYSQL_TABLE_PREFIX}settings_objects SET value = 'Y' WHERE name = 'secure_admin' OR name = 'secure_storefront'"
docker-compose exec app rm /tmp/wait-for-it.sh

.PHONY: install-multisafepay
install-multisafepay:
docker-compose exec app php msp_installer.php
install-multisafepay: msp-installer modman-deploy
@# - ignore the error if the command fails
@# || true ensures that the command returns a successful exit code due
@# to the errors that chown throws when pass through .git folder
@-docker-compose exec app chown -R www-data:www-data /var/www/ > /dev/null 2>&1 || true

.PHONY: msp-installer
msp-installer:
docker cp ./src/msp_installer.php $$(docker-compose ps -q app):/var/www/html/msp_installer.php
docker-compose exec app chmod +x /var/www/html/msp_installer.php
@docker-compose exec app php /var/www/html/msp_installer.php || (echo "msp_installer.php failed" && exit 1)

.PHONY: modman-deploy
modman-deploy:
docker-compose exec app modman deploy-all

.PHONY: modman
modman:
Expand All @@ -33,4 +83,3 @@ modman:
.PHONY: modman-copy
modman-copy:
docker-compose exec app modman deploy multisafepay --copy --force --quiet

Empty file added cscart/.gitkeep
Empty file.
26 changes: 17 additions & 9 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,36 +1,44 @@
version: '3.3'

services:
app:
depends_on:
- db
- mail
build: .
build:
context: .
sysctls:
- net.ipv4.ip_unprivileged_port_start=0
volumes:
- ./:/var/www/html/.modman/multisafepay
- ./msp_installer.php:/var/www/html/msp_installer.php
- ./cscart:/var/www/html/
environment:
PHP_IDE_CONFIG: "serverName=app"
db:
image: 'mysql:5.7'
image: "mysql:5.7"
platform: linux/x86_64
command: --default-authentication-plugin=mysql_native_password
# restart: always
environment:
MYSQL_ROOT_PASSWORD: ${MYSQL_PASSWORD}
MYSQL_DATABASE: ${MYSQL_DATABASE}
MYSQL_USER: ${MYSQL_USER}
MYSQL_PASSWORD: ${MYSQL_PASSWORD}
mail:
image: 'mailhog/mailhog'
image: "mailhog/mailhog"
platform: linux/x86_64
ports:
- 8025:8025
- "8025:8025"
adminer:
image: adminer:latest
platform: linux/arm64/v8
ports:
- "8080:8080"
depends_on:
- db
links:
- db
expose:
depends_on:
- app
build: https://github.com/beyondcode/expose.git
entrypoint: ["/bin/sh", "-c" , "/src/expose token ${EXPOSE_TOKEN} && sed -i -E \"s/'dns'\\s?=>\\s?'.*'/'dns' => true/g\" /root/.expose/config.php && /src/expose share app --server-host=${EXPOSE_HOST} --subdomain=${APP_SUBDOMAIN}"]
ports:
- 4040:4040
- "4040:4040"
14 changes: 5 additions & 9 deletions modman
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
src/app/addons/multisafepay app/addons/multisafepay

src/app/lib/other/templater/plugins/block.msp_issuers.php app/lib/other/templater/plugins/block.msp_issuers.php
src/app/lib/other/smarty/plugins/block.msp_issuers.php app/lib/other/smarty/plugins/block.msp_issuers.php
src/app/lib/vendor/smarty/smarty/libs/plugins/block.msp_issuers.php app/lib/vendor/smarty/smarty/libs/plugins/block.msp_issuers.php

src/app/payments/multisafepay/multisafepay_fastcheckout.functions.php app/payments/multisafepay/multisafepay_fastcheckout.functions.php
src/app/payments/MultiSafepay.combined.php app/payments/MultiSafepay.combined.php
src/app/payments/multisafepay.php app/payments/multisafepay.php
Expand All @@ -30,7 +26,7 @@ src/app/payments/multisafepay_kbc.php app/payments/multisafepay_kbc.php
src/app/payments/multisafepay_klarna.php app/payments/multisafepay_klarna.php
src/app/payments/multisafepay_maestro.php app/payments/multisafepay_maestro.php
src/app/payments/multisafepay_mastercard.php app/payments/multisafepay_mastercard.php
src/app/payments/multisafepay_payafter.php app/payments/multisafepay_payafter.php
src/app/payments/multisafepay_bnpl_mf.php app/payments/multisafepay_bnpl_mf.php
src/app/payments/multisafepay_paypal.php app/payments/multisafepay_paypal.php
src/app/payments/multisafepay_paysafecard.php app/payments/multisafepay_paysafecard.php
src/app/payments/multisafepay_santander.php app/payments/multisafepay_santander.php
Expand Down Expand Up @@ -61,7 +57,7 @@ src/design/backend/templates/views/orders/components/payments/msp_kbc.tpl design
src/design/backend/templates/views/orders/components/payments/msp_klarna.tpl design/backend/templates/views/orders/components/payments/msp_klarna.tpl
src/design/backend/templates/views/orders/components/payments/msp_maestro.tpl design/backend/templates/views/orders/components/payments/msp_maestro.tpl
src/design/backend/templates/views/orders/components/payments/msp_mastercard.tpl design/backend/templates/views/orders/components/payments/msp_mastercard.tpl
src/design/backend/templates/views/orders/components/payments/msp_payafter.tpl design/backend/templates/views/orders/components/payments/msp_payafter.tpl
src/design/backend/templates/views/orders/components/payments/msp_bnpl_mf.tpl design/backend/templates/views/orders/components/payments/msp_bnpl_mf.tpl
src/design/backend/templates/views/orders/components/payments/msp_paypal.tpl design/backend/templates/views/orders/components/payments/msp_paypal.tpl
src/design/backend/templates/views/orders/components/payments/msp_paysafecard.tpl design/backend/templates/views/orders/components/payments/msp_paysafecard.tpl
src/design/backend/templates/views/orders/components/payments/msp_santander.tpl design/backend/templates/views/orders/components/payments/msp_santander.tpl
Expand All @@ -81,7 +77,7 @@ src/design/backend/templates/views/payments/components/cc_processors/msp_visa.tp
src/design/backend/templates/views/payments/components/cc_processors/msp_klarna.tpl design/backend/templates/views/payments/components/cc_processors/msp_klarna.tpl
src/design/backend/templates/views/payments/components/cc_processors/msp_cbc.tpl design/backend/templates/views/payments/components/cc_processors/msp_cbc.tpl
src/design/backend/templates/views/payments/components/cc_processors/msp_trustpay.tpl design/backend/templates/views/payments/components/cc_processors/msp_trustpay.tpl
src/design/backend/templates/views/payments/components/cc_processors/msp_payafter.tpl design/backend/templates/views/payments/components/cc_processors/msp_payafter.tpl
src/design/backend/templates/views/payments/components/cc_processors/msp_bnpl_mf.tpl design/backend/templates/views/payments/components/cc_processors/msp_bnpl_mf.tpl
src/design/backend/templates/views/payments/components/cc_processors/msp_einvoice.tpl design/backend/templates/views/payments/components/cc_processors/msp_einvoice.tpl
src/design/backend/templates/views/payments/components/cc_processors/msp_amex.tpl design/backend/templates/views/payments/components/cc_processors/msp_amex.tpl
src/design/backend/templates/views/payments/components/cc_processors/msp_santander.tpl design/backend/templates/views/payments/components/cc_processors/msp_santander.tpl
Expand Down Expand Up @@ -124,7 +120,7 @@ src/design/themes/basic/templates/views/orders/components/payments/msp_kbc.tpl d
src/design/themes/basic/templates/views/orders/components/payments/msp_klarna.tpl design/themes/basic/templates/views/orders/components/payments/msp_klarna.tpl
src/design/themes/basic/templates/views/orders/components/payments/msp_maestro.tpl design/themes/basic/templates/views/orders/components/payments/msp_maestro.tpl
src/design/themes/basic/templates/views/orders/components/payments/msp_mastercard.tpl design/themes/basic/templates/views/orders/components/payments/msp_mastercard.tpl
src/design/themes/basic/templates/views/orders/components/payments/msp_payafter.tpl design/themes/basic/templates/views/orders/components/payments/msp_payafter.tpl
src/design/themes/basic/templates/views/orders/components/payments/msp_bnpl_mf.tpl design/themes/basic/templates/views/orders/components/payments/msp_bnpl_mf.tpl
src/design/themes/basic/templates/views/orders/components/payments/msp_paypal.tpl design/themes/basic/templates/views/orders/components/payments/msp_paypal.tpl
src/design/themes/basic/templates/views/orders/components/payments/msp_paysafecard.tpl design/themes/basic/templates/views/orders/components/payments/msp_paysafecard.tpl
src/design/themes/basic/templates/views/orders/components/payments/msp_santander.tpl design/themes/basic/templates/views/orders/components/payments/msp_santander.tpl
Expand All @@ -141,7 +137,7 @@ src/design/themes/responsive/templates/views/orders/components/payments/msp_sant
src/design/themes/responsive/templates/views/orders/components/payments/msp_paysafecard.tpl design/themes/responsive/templates/views/orders/components/payments/msp_paysafecard.tpl
src/design/themes/responsive/templates/views/orders/components/payments/msp_wallet.tpl design/themes/responsive/templates/views/orders/components/payments/msp_wallet.tpl
src/design/themes/responsive/templates/views/orders/components/payments/msp_trustpay.tpl design/themes/responsive/templates/views/orders/components/payments/msp_trustpay.tpl
src/design/themes/responsive/templates/views/orders/components/payments/msp_payafter.tpl design/themes/responsive/templates/views/orders/components/payments/msp_payafter.tpl
src/design/themes/responsive/templates/views/orders/components/payments/msp_bnpl_mf.tpl design/themes/responsive/templates/views/orders/components/payments/msp_bnpl_mf.tpl
src/design/themes/responsive/templates/views/orders/components/payments/msp_idealqr.tpl design/themes/responsive/templates/views/orders/components/payments/msp_idealqr.tpl
src/design/themes/responsive/templates/views/orders/components/payments/msp_cbc.tpl design/themes/responsive/templates/views/orders/components/payments/msp_cbc.tpl
src/design/themes/responsive/templates/views/orders/components/payments/msp_alipay.tpl design/themes/responsive/templates/views/orders/components/payments/msp_alipay.tpl
Expand Down
Empty file added source/.gitkeep
Empty file.

0 comments on commit cc91e4f

Please sign in to comment.