Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/streamline setup #80

Merged
merged 2 commits into from
Jan 23, 2024
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
13 changes: 12 additions & 1 deletion .codepipeline/local-dev/configs/supervisord/supervisord.conf
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,15 @@ autostart=true
autorestart=true
priority=10
stdout_events_enabled=true
stderr_events_enabled=true
stderr_events_enabled=true
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0

[program:cmfive-setup]
command=/bootstrap/setup.sh
autostart=true
autorestart=false
stdout_events_enabled=true
stderr_events_enabled=true
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
36 changes: 36 additions & 0 deletions .codepipeline/local-dev/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash
set -e

#If ~/.cmfive-installed exists close the script
if [ -f ~/.cmfive-installed ]; then
echo "Cmfive already installed"
exit 0
fi
echo "Setting up cmfive"

cd /var/www/html

#Wait 15 seconds for things to start
sleep 15

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

#Allow all permissions to the folders
echo "Setting permissions"
chmod 777 -R cache/ storage/ uploads/

#Setup Cmfive
echo "Running cmfive.php actions"
echo
php cmfive.php install core
php cmfive.php seed encryption
php cmfive.php install migrations
php cmfive.php seed admin Admin Admin dev@2pisoftware.com admin admin

#Let container know that everything is finished
echo "Cmfive setup complete"
touch ~/.cmfive-installed
7 changes: 7 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ COPY . /var/www/html
WORKDIR /bootstrap

COPY /.codepipeline/local-dev/start.sh .
COPY /.codepipeline/local-dev/setup.sh .
COPY /.codepipeline/local-dev/configs/fpm/* /etc/php/8.1/fpm/
COPY /.codepipeline/local-dev/configs/nginx/nginx.conf /etc/nginx/nginx.conf
COPY /.codepipeline/local-dev/configs/nginx/default.conf /etc/nginx/conf.d/default.conf
Expand All @@ -60,4 +61,10 @@ COPY /.codepipeline/local-dev/configs/supervisord/supervisord.conf /etc/supervis
RUN mkdir /run/php

RUN chmod -R 777 /bootstrap/start.sh

# Healthcheck to ensure nginx is running and cmfive is installed
HEALTHCHECK --interval=10s --timeout=10s --start-period=5s --retries=15 \
CMD curl -s -o /dev/null -w "%{http_code}" http://localhost:3000 | grep -q -E "^[1-3][0-9]{2}$" && \
test -f ~/.cmfive-installed

CMD ["/bootstrap/start.sh"]
33 changes: 17 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,33 @@ Requirements:
- mkcert

Install the root CA on your machine so that the SSL certificate is trusted (you can skip this and opt to go through the warning pages that browsers will give you):
run from the boilerplate directory
run from the boilerplate directory:

```bash
cd .build/certs
mkcert -install
```

Once done you can start the containers. For development we recommend the Docker plugin by Microsoft for VS Code. To run it on the CLI:
```bash
docker-compose up
```
Once done you can start the containers. For development we recommend the Docker plugin by Microsoft for VS Code. Simply right click on the **docker-compose.yml** file and select **Compose Up**.

Alternatively to run it on the CLI:

Ensure you also have MySQL running, to set up one in a container:
```bash
docker run mysql:5.7 --net=host
docker-compose up -d
```

Once everything is running alter the config.php to point at your mysql instance and run:
Give it a few minutes. You can check the status in VS Code on the Docker tab. Important containers will report "healthy".


Alternatively you can check on the CLI:
```bash
php cmfive.php install core
php cmfive.php install migrations
docker ps
```

Then seed an admin user:
```
php cmfive.php
[select option 3 and fill in the prompts]
```
NOTE: The compiler will always start after cmfive is running.

From there, navigate to: [http://localhost:3000](http://localhost:3000) and log in with your admin account. For development it is:

From there, navigate to: [https://localhost:9002](https://localhost:9002) and log in with your admin account.
- Username: admin
- Password: admin

30 changes: 29 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,33 @@ services:
- "3306:3306"
environment:
- MYSQL_ROOT_PASSWORD=root
- MYSQL_USER=cmfive
- MYSQL_PASSWORD=cmfive
- MYSQL_DATABASE=cmfive
- TZ=Australia/Sydney
volumes:
- dbdata:/var/lib/mysql:delegated
# 'delegated' may be faster on mac or win?
networks:
- default
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
interval: 30s
timeout: 5s
retries: 5

webapp:
build:
context: .
dockerfile: Dockerfile
container_name: nginx-php8.1
container_name: cmfive
hostname: nginx-php8.1
environment:
- TZ=Australia/Sydney
- DB_HOST=mysqldb
- DB_DATABASE=cmfive
- DB_USERNAME=cmfive
- DB_PASSWORD=cmfive
volumes:
- ./:/var/www/html
- ./test/Codeception/tests/boilerplate:/var/www/html/test/Codeception/tests/boilerplate
Expand All @@ -41,6 +53,22 @@ services:
- mysqldb
- seleniumsrv

compiler:
image: node:18-alpine
container_name: node-compiler
volumes:
- ./:/var/www/html
working_dir: /var/www/html/system/templates/base
command: "sh -c \"npm i && npm run watch\""
healthcheck:
test: ["CMD-SHELL", "ps aux | grep 'npm run watch' | grep -v grep"]
interval: 30s
timeout: 5m
retries: 5
depends_on:
webapp:
condition: service_healthy

seleniumsrv:
image: selenium/standalone-chrome:111.0
container_name: seleniumDrv
Expand Down