Skip to content

Commit

Permalink
Improve docker build
Browse files Browse the repository at this point in the history
  • Loading branch information
mattbell87 committed Feb 26, 2024
1 parent 47ce7e6 commit 30341f1
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .codepipeline/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ RUN cd /cmfive-core/system/templates/base && npm install && npm run production
# == Final stage ==
# --------------------------------------------------------------------------

# This stage copies the core, installs cmfive packages and copies the theme.
# This stage copies the core, installs Cmfive packages and copies the theme.
# It is based on the cmfive-boilerplate image from the root directory.

FROM cmfive-boilerplate:latest AS cmfive
Expand Down
23 changes: 19 additions & 4 deletions .codepipeline/docker/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Pipeline for building a cmfive docker image
# Pipeline for building a Cmfive docker image

This directory builds an image that contins a complete cmfive installation with a production build of the theme.
This directory builds an image that contins a complete Cmfive installation with a production build of the theme.

## Manual steps for building a docker image locally:

Expand All @@ -21,10 +21,25 @@ You will now to have a docker image called `cmfive:latest` that you can run. Eg:
docker run -p 3000:80 cmfive:latest
```

## Testing out changes for the docker image

You can test out how your changes would look by building a new image with the same tag as what is defined in the docker-compose.yml file. Eg:

```sh
docker build -t cmfive-boilerplate:latest .
docker build -t ghcr.io/2pisoftware/cmfive:develop ./.codepipeline/docker
```

Then once you do a `docker compose up` it will use the image you just built.

Note that this image is only stored locally and the final image can only be built by the GitHub workflow.

## Github workflow

1. Push to repo
1. Push to a branch and open a PR
2. The workflow **.github/workflows/docker-image.yml** is triggered
3. The workflow builds the docker image as above and pushes it to the GitHub Container Registry
4. The image is now available at `ghcr.io/2pisoftware/cmfive`
4. The image is now available at `ghcr.io/2pisoftware/cmfive:pr-<pr-number>`
5. Once the PR is merged, the image is built again and pushed to `ghcr.io/2pisoftware/cmfive:develop` or `ghcr.io/2pisoftware/cmfive:latest` depending on the branch that was merged to.


5 changes: 4 additions & 1 deletion .codepipeline/docker/configs/supervisord/supervisord.conf
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0

[program:cmfive-setup]
command=/bootstrap/setup.sh
command=/bin/ash -c "/bootstrap/setup.sh"
autostart=true
autorestart=false
stdout_logfile=/dev/stdout
Expand All @@ -60,3 +60,6 @@ stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
priority=20
user=cmfive
exitcodes=0
startretries=0
startsecs=0
41 changes: 32 additions & 9 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 Cmfive
# ================================================================

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

echo "Setting up cmfive"
echo "🏗️ Setting up Cmfive"

#Copy the config template if config.php doens't exist
if [ ! -f config.php ]; then
echo "Installing config.php"
cp /bootstrap/config.default.php config.php
fi

#Allow all permissions to the folders
#Ensure necessary directories have the correct permissions
echo "Setting permissions"
chmod ugo=rwX -R cache/ storage/ uploads/

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

echo "Running cmfive.php actions"
echo
if [ ! -f /var/www/html/system/web.php ]; then
echo "System missing, installing core"
php cmfive.php install core

# If system dir exists but composer doesnt print a warning
if [ -f "/var/www/html/system/web.php" ] && [ ! -f "/var/www/html/composer.json" ]; then
echo "⚠️ Warning: System dir exists but composer packages are missing"
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
echo "➕ Installing core from branch [ $CMFIVE_CORE_BRANCH ]"
php cmfive.php install core $CMFIVE_CORE_BRANCH
echo "✔️ Core installed"
else
echo "✔️ Core already installed"
fi

php cmfive.php seed encryption
php cmfive.php install migrations
php cmfive.php seed admin Admin Admin [email protected] admin admin

# if DEVELOPMENT
if [ "$ENVIRONMENT" = "development" ]; then
echo "🧑‍💻 Development mode"
echo "Creating admin user"
php cmfive.php seed admin Admin Admin [email protected] admin admin
fi

#Let container know that everything is finished
echo "Cmfive setup complete"
echo "=========================="
echo "✅ Cmfive setup complete"
echo "=========================="
touch /home/cmfive/.cmfive-installed
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ services:
- DB_DATABASE=cmfive
- DB_USERNAME=cmfive
- DB_PASSWORD=cmfive
- ENVIRONMENT=development
volumes:
- ./:/var/www/html:rw
- ./test/Codeception/tests/boilerplate:/var/www/html/test/Codeception/tests/boilerplate
Expand Down
2 changes: 1 addition & 1 deletion index.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
ini_set("display_errors", 1);
ini_set("display_errors", 0); //Avoids 200 OK being sent when there are errors
error_reporting(E_ALL);

require_once 'system/web.php';
Expand Down

0 comments on commit 30341f1

Please sign in to comment.