Skip to content

Commit

Permalink
Merge pull request #158 from 2pisoftware/develop
Browse files Browse the repository at this point in the history
Release develop changes
  • Loading branch information
adam-buckley authored Sep 16, 2024
2 parents d548905 + 6e35442 commit 8f1ed87
Show file tree
Hide file tree
Showing 22 changed files with 296 additions and 72 deletions.
27 changes: 26 additions & 1 deletion .codepipeline/docker/cmfive_dev_tools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,34 @@
set -e

echo "🏗️ Installing required system packages"
apk add --no-cache php$PHPVERSION-dom php$PHPVERSION-xmlwriter php$PHPVERSION-tokenizer php$PHPVERSION-ctype mysql-client mariadb-connector-c-dev bash
apk add --no-cache \
php$PHP_VERSION-dom \
php$PHP_VERSION-xmlwriter \
php$PHP_VERSION-tokenizer \
php$PHP_VERSION-ctype \
php$PHP_VERSION-xdebug \
mysql-client \
mariadb-connector-c-dev \
bash

echo "🔨 Installing phpunit v${PHPUNIT}"
cd /usr/local/bin && curl -L https://phar.phpunit.de/phpunit-${PHPUNIT}.phar -o phpunit && chmod +x phpunit && chmod 777 .

# Install xdebug config
echo "🔨 Configuring xdebug"
cat <<EOF > /etc/php$PHP_VERSION/conf.d/50_xdebug.ini
zend_extension=xdebug.so
xdebug.mode=debug
xdebug.start_with_request=yes
xdebug.client_host=host.docker.internal
EOF

# Tell supervisord to restart php-fpm
echo "🔄 Restarting php-fpm"
if supervisorctl status | grep -q "RUNNING"; then
supervisorctl restart php-fpm
else
echo "Supervisord is not running. Cannot restart php-fpm."
fi

# NOTE: Playwright is not recommended to be installed here
14 changes: 11 additions & 3 deletions .codepipeline/docker/install_dev_tools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
# SKIP_PLAYWRIGHT=true ./install_dev_tools.sh

#Settings
PHPVERSION=81
PHPUNIT=10

# If CONTAINER is not defined, default to the container name of the webapp service in docker compose
Expand Down Expand Up @@ -71,7 +70,7 @@ if [ $? -ne 0 ]; then
fi

# Run cmfive_dev_tools
docker exec $CONTAINER sh -c "PHPUNIT=${PHPUNIT} PHPVERSION=${PHPVERSION} /home/cmfive/cmfive_dev_tools.sh"
docker exec $CONTAINER sh -c "PHPUNIT=${PHPUNIT} /home/cmfive/cmfive_dev_tools.sh"
if [ $? -ne 0 ]; then
echo "❌ Error: cmfive_dev_tools.sh failed"
exit 1
Expand All @@ -93,13 +92,22 @@ echo "🔨 Installing Playwright dependencies"
# If not Debian or Ubuntu exit the script
if ! command -v apt-get &> /dev/null; then
echo "⚠️ WARNING: Playwright dependencies are only supported on Debian and Ubuntu"
echo
echo "There is a containerised version you can run instead"
echo " test/playwright/docker_run.sh"
echo "Or to run a fresh container"
echo " test/playwright/docker_run.sh --fresh"
echo ""
echo "Alternatively you can use the Visual Studio Code extension"
echo ""
echo "✔️ Dev tools installed successfully"
exit 0
fi

# Check if npm is installed on host machine
if ! command -v npm &> /dev/null; then
echo "⚠️ WARNING: npm is not installed on this machine. Please install npm and run 'npm install' in the test directory"
echo "⚠️ WARNING: npm is not installed on this machine."
echo "Please install npm then install Playwright dependencies"
echo "✔️ Dev tools installed successfully"
exit 0
fi
Expand Down
26 changes: 16 additions & 10 deletions .codepipeline/docker/setup.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

# ================================================================
# Prepare and install Cmfive
# Prepare and install Cosine
# ================================================================

set -e
Expand All @@ -19,7 +19,7 @@ if [ "$SKIP_CMFIVE_AUTOSETUP" = true ]; then
exit 0
fi

echo "🏗️ Setting up Cmfive"
echo "🏗️ Setting up Cosine"

#Copy the config template if config.php doens't exist
if [ ! -f config.php ]; then
Expand All @@ -32,7 +32,7 @@ echo "Setting permissions"
chmod ugo=rwX -R cache/ storage/ uploads/

# ------------------------------------------------
# Setup Cmfive
# Setup Cosine
# ------------------------------------------------

echo "Running cmfive.php actions"
Expand Down Expand Up @@ -69,15 +69,21 @@ fi

# If CMFIVE_CORE_BRANCH is set print to logs
if [ -n "$CMFIVE_CORE_BRANCH" ]; then
echo "Using CMFIVE_CORE_BRANCH [ $CMFIVE_CORE_BRANCH ]"
echo "⚠️ CMFIVE_CORE_BRANCH is deprecated, please use INSTALL_CORE_BRANCH"
INSTALL_CORE_BRANCH=$CMFIVE_CORE_BRANCH
fi

# If INSTALL_CORE_BRANCH is set print to logs
if [ -n "$INSTALL_CORE_BRANCH" ]; then
echo "🌿 Overriding built in core with branch \"$INSTALL_CORE_BRANCH\""
fi

# System dir and composer packages must exist
if [ ! -f "/var/www/html/system/web.php" ] || [ ! -f "/var/www/html/composer.json" ] || [ -n "$CMFIVE_CORE_BRANCH" ]; then
CMFIVE_CORE_BRANCH=${CMFIVE_CORE_BRANCH:-master} # Default to master if not set
if [ ! -f "/var/www/html/system/web.php" ] || [ ! -f "/var/www/html/composer.json" ] || [ -n "$INSTALL_CORE_BRANCH" ]; then
INSTALL_CORE_BRANCH=${INSTALL_CORE_BRANCH:-main} # Default to main if not set
rm -rf /var/www/html/system # Remove system dir to ensure correct core is installed
echo "➕ Installing core from branch [ $CMFIVE_CORE_BRANCH ]"
php cmfive.php install core $CMFIVE_CORE_BRANCH
echo "➕ Installing core from branch [ $INSTALL_CORE_BRANCH ]"
php cmfive.php install core $INSTALL_CORE_BRANCH
checkSymlink
echo "✔️ New core installed"
else
Expand All @@ -92,11 +98,11 @@ php cmfive.php install migrations
if [ "$ENVIRONMENT" = "development" ]; then
echo "🧑‍💻 Development mode"
echo "Creating admin user"
php cmfive.php seed admin Admin Admin [email protected] admin admin
php cmfive.php seed admin admin admin [email protected] admin admin
fi

#Let container know that everything is finished
echo "=========================="
echo "Cmfive setup complete"
echo "Cosine setup complete"
echo "=========================="
touch /home/cmfive/.cmfive-installed
14 changes: 0 additions & 14 deletions .codepipeline/docker/start.sh

This file was deleted.

20 changes: 20 additions & 0 deletions .codepipeline/ec2/after-install.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
#!/bin/bash

if [ -f /etc/cosine/deployment-type ]; then
COSINE_DEPLOYMENT_TYPE=$(cat /etc/cosine/deployment-type)
else
COSINE_DEPLOYMENT_TYPE="classic"
fi

if [ "$COSINE_DEPLOYMENT_TYPE" == "docker" ]; then
sudo chown -R ubuntu:ubuntu /var/www/cmfive-boilerplate

if docker ps | grep -q cosine; then
docker exec -it cosine bash -c "php cmfive.php install migrations"
docker exec -it cosine bash -c "rm -f cache/config.cache"
docker exec -it cosine bash -c "rm -f cache/classdirectory.cache"
else
echo "Cosine container not running yet"
fi

exit 0
fi

echo "Running After Install"

# Rename directory.
Expand Down
35 changes: 35 additions & 0 deletions .codepipeline/ec2/application-start.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,40 @@
#/bin/bash

if [ -f /etc/cosine/deployment-type ]; then
COSINE_DEPLOYMENT_TYPE=$(cat /etc/cosine/deployment-type)
else
COSINE_DEPLOYMENT_TYPE="classic"
fi

if [ "$COSINE_DEPLOYMENT_TYPE" == "docker" ]; then
systemctl start cosine

# Read cosine config
source /etc/cosine/cosine.conf

if [ "$CORE_BRANCH" != "main" ]; then
# Theme will need compiling

# # Copy theme from container to host
# echo "Copying theme from container to host"
# docker cp cosine:/var/www/html/system/templates/base /tmp/cmfive-theme
# cd /tmp/cmfive-theme
# echo "Compiling theme"
# docker run --rm \
# -v $(pwd):/app \
# -w /app \
# node:20-alpine sh -c "npm ci && npm run production"
# # Copy the compiled theme back to the docker container
# echo "Copying compiled theme back to container"
# docker cp /tmp/cmfive-theme/. cosine:/var/www/html/system/templates/base

# NOTE: Commented out the above due to high system requirements
echo "Theme compilation needed but skipped"
fi

exit 0
fi

echo "Running Application Start"

# Start Nginx and PHP FPM.
Expand Down
12 changes: 12 additions & 0 deletions .codepipeline/ec2/application-stop.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
#/bin/bash

if [ -f /etc/cosine/deployment-type ]; then
COSINE_DEPLOYMENT_TYPE=$(cat /etc/cosine/deployment-type)
else
COSINE_DEPLOYMENT_TYPE="classic"
fi

if [ "$COSINE_DEPLOYMENT_TYPE" == "docker" ]; then
systemctl stop cosine

exit 0
fi

echo "Running Application Stop"

# Stop Nginx and PHP FPM.
Expand Down
6 changes: 6 additions & 0 deletions .codepipeline/ec2/before-install.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
#/bin/bash

if [ -f /etc/cosine/deployment-type ]; then
COSINE_DEPLOYMENT_TYPE=$(cat /etc/cosine/deployment-type)
else
COSINE_DEPLOYMENT_TYPE="classic"
fi

echo "Running Before Install"

# Install updates.
Expand Down
28 changes: 25 additions & 3 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ on:
- develop
- master
push:
tags:
- 'v*'
branches:
- develop
- master
Expand All @@ -23,6 +25,9 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
Expand Down Expand Up @@ -54,16 +59,33 @@ jobs:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

# Build and push the image
- name: Build and push cmfive image
uses: docker/build-push-action@v5
# Build combined ARM/x86-64 image on master and develop branches
- name: Build and push cmfive ARM/x86-64 image
uses: docker/build-push-action@v6
if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/develop' || startsWith(github.ref, 'refs/tags/v')
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=registry,ref=ghcr.io/2pisoftware/cmfive:buildcache
cache-to: type=registry,ref=ghcr.io/2pisoftware/cmfive:buildcache,mode=max
# x86-64 and ARM64
platforms: linux/amd64,linux/arm64

# Build x86-64 image on other branches
- name: Build and push cmfive x86-64 image
uses: docker/build-push-action@v6
if: github.ref != 'refs/heads/master' && github.ref != 'refs/heads/develop' && !startsWith(github.ref, 'refs/tags/v')
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=registry,ref=ghcr.io/2pisoftware/cmfive:buildcache
cache-to: type=registry,ref=ghcr.io/2pisoftware/cmfive:buildcache,mode=max
# x86-64
platforms: linux/amd64

# Scan the docker image and compare it with the latest image
- name: Docker Scout
Expand Down
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@

desktop.ini
docker-compose.override.yml
.env
.env
.codeql

# IDE Fluff
.settings
Expand All @@ -21,7 +22,6 @@ docker-compose.override.yml
.metadata
.phpintel
nbproject/
.vscode/
.vs/

# Composer
Expand Down
14 changes: 14 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Listen for Xdebug",
"type": "php",
"request": "launch",
"port": 9003,
"pathMappings": {
"/var/www/html/": "${workspaceFolder}",
}
},
]
}
Loading

0 comments on commit 8f1ed87

Please sign in to comment.