Skip to content

Commit

Permalink
Merge pull request #5 from trants/main
Browse files Browse the repository at this point in the history
Initial dockerizing application, Updated images config files & secret key environment
  • Loading branch information
Jeff A Justice committed Dec 28, 2023
2 parents 6a2b8a0 + 8d511f8 commit 8125cb0
Show file tree
Hide file tree
Showing 35 changed files with 509 additions and 8 deletions.
18 changes: 18 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Nginx
NGINX_PORT=
NGINX_HTTPS_PORT=

# PHP
BLACKFIRE_CLIENT_ID=
BLACKFIRE_CLIENT_TOKEN=
COMPOSER_DISABLE_XDEBUG_WARN=1
PHP_CS_FIXER_IGNORE_ENV=1

# MariaDB
MARIA_DB_PORT=3306
MYSQL_ROOT_PASSWORD=root

# PostgreSQL
POSTGRES_DB_PORT=5432
POSTGRES_USER=root
POSTGRES_PASSWORD=root
2 changes: 1 addition & 1 deletion .github/workflows/.build-nginx-1.18.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ jobs:
context: images/nginx/1.18
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ secrets.DOCKER_IMAGE }}:1.18
tags: ${{ secrets.DOCKER_NGINX_IMAGE }}:1.18
cache-from: type=gha
cache-to: type=gha,mode=max
2 changes: 1 addition & 1 deletion .github/workflows/.build-php-8.1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ jobs:
context: images/php/8.1
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ secrets.DOCKER_IMAGE }}:8.1
tags: ${{ secrets.DOCKER_PHP_IMAGE }}:8.1
cache-from: type=gha
cache-to: type=gha,mode=max
2 changes: 1 addition & 1 deletion .github/workflows/.build-php-8.2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ jobs:
context: images/php/8.2
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ secrets.DOCKER_IMAGE }}:8.1
tags: ${{ secrets.DOCKER_PHP_IMAGE }}:8.2
cache-from: type=gha
cache-to: type=gha,mode=max
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,7 @@ Temporary Items

# Environment's params
.env

# Directories docker
docker/nginx/sites-enabled/*.conf
compose/src
104 changes: 104 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,105 @@
# Flash Development

This repository allows you to quickly get a development environment up and running using Docker, including a MySQL,
PostgreSQL
database and some debugging tools.

This environment includes the latest versions of the following software:

- `nginx`
- `phpfpm`
- `mariadb`
- `postgresql`
- `xdebug`

### 📦 Requirements

The Docker & Docker Compose system requirements are Linux Ubuntu as the OS (other operating systems are supported as
well), an absolute minimum 512MB RAM (2GB recommended)

In order to install docker Ubuntu, you will need to meet the following requirements:

- OS: Linux Ubuntu
- Memory: 512MB RAM (2GB Recommended)
- Disk: Sufficient amount to run the Docker containers you wish to use
- CPU: Dependant on the applications you wish to run in the containers

### 📋 Features

- Easy switch between PHP versions: 8.3, 8.2, 8.1, 8.0 7.4, 7.3, 7.2, 7.1, 5.6…
- Choose your favorite database engine: MySQL, Postgres, MariaDB…
- Run your own stack: Memcached, HHVM, RabbitMQ…
- Each software runs on its own container: PHP-FPM, NGINX, PHP-CLI…
- Easy to customize any container, with simple edit to the Dockerfile.
- All Images extend from an official base Image. (Trusted base Images).
- Pre-configured NGINX to host any code at your root directory.
- Can use per project,or single for all projects.
- Easy to install/remove software’s in Containers using environment variables.
- Clean and well-structured Dockerfiles (Dockerfile).
- Latest version of the Docker Compose file (docker-compose).
- Everything is visible and editable.
- Fast Images Builds.

### 🔧 Installation

1. Install Docker and Docker-Compose

- [Docker Install documentation](https://docs.docker.com/install/)
- [Docker-Compose Install documentation](https://docs.docker.com/compose/install/)

2. Bring up your stack by running

```shell
git clone https://github.com/hitechnix/flash-development.git \
&& cd flash-development \
&& cp .env.example .env
```

3. Edit environment variable

```bash
# Nginx
NGINX_PORT=
NGINX_HTTPS_PORT=

# PHP
BLACKFIRE_CLIENT_ID=
BLACKFIRE_CLIENT_TOKEN=
COMPOSER_DISABLE_XDEBUG_WARN=1
PHP_CS_FIXER_IGNORE_ENV=1

# MariaDB
MARIA_DB_PORT=3306
MYSQL_ROOT_PASSWORD=root

# PostgreSQL
POSTGRES_DB_PORT=5432
POSTGRES_USER=root
POSTGRES_PASSWORD=root
```

4. Start application

```shell
docker-compose up -d
```

### 📝 Usage

Reader-friendly documentation can be found [here][link-docs].

### 📨 Message

I hope you find this useful. If you have any questions, please create an issue.

### 🔐 Security

If you discover any security related issues, please email support@hitechnix.com instead of using the issue tracker.

### 📖 License

This software is released under the [BSD 3-Clause][link-license] License. Please see the [LICENSE](LICENSE) file
or https://opensource.hitechnix.com/LICENSE.txt for more information.

[link-docs]:https://opensource.hitechnix.com/flash-development
[link-license]: https://opensource.org/license/bsd-3-clause
2 changes: 2 additions & 0 deletions bin/bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
bin/cli bash
3 changes: 3 additions & 0 deletions bin/cli
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
[ -z "$1" ] && echo "Please specify a CLI command (ex. ls)" && exit
docker-compose exec php "$@"
5 changes: 5 additions & 0 deletions bin/clinotty
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
[ -z "$1" ] && echo "Please specify a CLI command (ex. ls)" && exit
# -T: Disable pseudo-tty allocation
docker-compose exec -T php "$@"

4 changes: 4 additions & 0 deletions bin/cliq
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
[ -z "$1" ] && echo "Please specify a CLI command (ex. ls)" && exit
# Without stdout and stderr
bin/clinotty "$@" >/dev/null 2>&1
2 changes: 2 additions & 0 deletions bin/composer
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
bin/cli composer "$@"
15 changes: 15 additions & 0 deletions bin/copyfromcontainer
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash
[ -z "$1" ] && echo "Please specify a directory or file to copy from container (ex. vendor, --all)" && exit

REAL_SRC=$(cd -P "src" && pwd)
if [ "$1" == "--all" ]; then
docker cp "$(bin/docker-compose ps -q php|awk '{print $1}')":/var/www/./ "$REAL_SRC/"
echo "Completed copying all files from container to host"
else
if [ -f "$1" ] ; then
docker cp "$(bin/docker-compose ps -q php|awk '{print $1}')":/var/www/"$1" "$REAL_SRC/$1"
else
docker cp "$(bin/docker-compose ps -q php|awk '{print $1}')":/var/www/"$1" "$REAL_SRC/$(dirname "$1")"
fi
echo "Completed copying $1 from container to host"
fi
19 changes: 19 additions & 0 deletions bin/copytocontainer
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash
[ -z "$1" ] && echo "Please specify a directory or file to copy to container (ex. vendor, --all)" && exit

REAL_SRC=$(cd -P "src" && pwd)
if [ "$1" == "--all" ]; then
docker cp "$REAL_SRC/./" "$(bin/docker-compose ps -q php|awk '{print $1}')":/var/www/
echo "Completed copying all files from host to container"
bin/fixowns
bin/fixperms
else
if [ -f "$REAL_SRC/$1" ]; then
docker cp "$REAL_SRC/${1}" "$(bin/docker-compose ps -q php|awk '{print $1}')":/var/www/"$1"
else
docker cp "$REAL_SRC/${1}" "$(bin/docker-compose ps -q php|awk '{print $1}')":/var/www/"$(dirname "$1")"
fi
echo "Completed copying $1 from host to container"
bin/fixowns "$1"
bin/fixperms "$1"
fi
2 changes: 2 additions & 0 deletions bin/node
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
bin/cli node "$@"
2 changes: 2 additions & 0 deletions bin/npm
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
bin/cli npm "$@"
2 changes: 2 additions & 0 deletions bin/remove
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
docker-compose -f docker-compose.yml rm
3 changes: 3 additions & 0 deletions bin/removeall
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
bin/remove
bin/removevolumes
7 changes: 7 additions & 0 deletions bin/removevolumes
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash
current_folder=${PWD##*/}
volume_prefix=$(echo "$current_folder" | awk '{print tolower($0)}' | sed 's/\.//g')
docker volume rm "${volume_prefix}"_mariadb-data
docker volume rm "${volume_prefix}"_postgresql-data
docker volume rm "${volume_prefix}"_sockdata
docker volume rm "${volume_prefix}"_ssldata
3 changes: 3 additions & 0 deletions bin/restart
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
bin/stop
bin/start
3 changes: 3 additions & 0 deletions bin/root
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
[ -z "$1" ] && echo "Please specify a CLI command (ex. ls)" && exit
docker-compose exec -u root php "$@"
3 changes: 3 additions & 0 deletions bin/rootnotty
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
[ -z "$1" ] && echo "Please specify a CLI command (ex. ls)" && exit
docker-compose exec -u root -T php "$@"
12 changes: 12 additions & 0 deletions bin/setup-domain
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash
set -o errexit

[ -z "$1" ] && echo "Please specify a domain name (ex. domain.test)" && exit

DOMAIN=$1

echo "Your system password has been requested to add an entry to /etc/hosts..."
echo "127.0.0.1 ::1 $DOMAIN" | sudo tee -a /etc/hosts

echo "Generating SSL certificate..."
bin/setup-ssl "$DOMAIN"
17 changes: 17 additions & 0 deletions bin/setup-ssl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash
[ -z "$1" ] && echo "Please specify a domain (ex. domain.test)" && exit

# Generate certificate authority if not already setup
if ! docker-compose exec -T -u root nginx cat /root/.local/share/mkcert/rootCA.pem | grep -q 'BEGIN CERTIFICATE'; then
bin/setup-ssl-ca
fi

# Generate the certificate for the specified domain
docker-compose exec -T -u root nginx mkcert -key-file nginx.key -cert-file nginx.crt "$@"
echo "Moving key and cert to /etc/nginx/certs/..."
docker-compose exec -T -u root nginx chown app:app nginx.key nginx.crt
docker-compose exec -T -u root nginx mv nginx.key nginx.crt /etc/nginx/certs/

# Restart nginx to apply the updates
echo "Restarting containers to apply updates..."
bin/restart
70 changes: 70 additions & 0 deletions bin/setup-ssl-ca
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/bin/bash
set -o errexit
# Generate a new local CA "/root/.local/share/mkcert"
docker-compose exec -T -u root nginx mkcert -install

docker cp "$(docker-compose ps -q nginx|awk '{print $1}')":/root/.local/share/mkcert/rootCA.pem .
echo "System password requested to install certificate authority on host..."

if [ "$(uname)" == "Darwin" ]; then
sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain rootCA.pem

### Check if Firefox is installed
FFoxBin="/Applications/Firefox.app/Contents/MacOS/firefox-bin"
if [ -f "$FFoxBin" ]; then
echo "{\"policies\": {\"Certificates\": {\"ImportEnterpriseRoots\": true}}}" | sudo tee policies.json

### Check if distribution directory exists
DistDirectory="/Applications/Firefox.app/Contents/Resources/distribution"
if [ ! -d "$DistDirectory" ]; then
sudo mkdir "$DistDirectory"
fi
### Move the newly created policies.json to the Certificates directory
sudo mv policies.json "$DistDirectory"/policies.json

### Check if Certificates directory exists
CertDirectory="/Library/Application Support/Mozilla/Certificates"
if [ ! -d "$CertDirectory" ]; then
sudo mkdir "$CertDirectory"
fi

### Move the newly created .pem to the Certificates directory
sudo mv rootCA.pem "$CertDirectory"/rootCA.pem
else
sudo rm rootCA.pem
fi

else

### Requirement: apt install libnss3-tools
REQUIRED_PKG="libnss3-tools"
PKG_OK=$(dpkg-query -W --showformat='${Status}\n' $REQUIRED_PKG|grep "install ok installed")
echo Checking for $REQUIRED_PKG: "$PKG_OK"
if [ "" = "$PKG_OK" ]; then
echo "No $REQUIRED_PKG found. Setting up $REQUIRED_PKG."
sudo apt-get --yes install $REQUIRED_PKG
fi

### CA file to install (CUSTOMIZE!)
certfile="rootCA.pem"
certname="Root CA"

### For cert8 (legacy - DBM)
find ~/ -name "cert8.db" -print0 | while read -r certDB
do
certdir=$(dirname "${certDB}");
certutil -D -n "${certname}" -i ${certfile} -d dbm:"${certdir}"
certutil -A -n "${certname}" -t "TCu,Cu,Tu" -i ${certfile} -d dbm:"${certdir}"
done

### For cert9 (SQL)
find ~/ -name "cert9.db" -print0 | while read -r certDB
do
certdir=$(dirname "${certDB}");
certutil -D -n "${certname}" -i ${certfile} -d sql:"${certdir}"
certutil -A -n "${certname}" -t "TCu,Cu,Tu" -i ${certfile} -d sql:"${certdir}"
done

sudo mv rootCA.pem /usr/local/share/ca-certificates/rootCA.crt
sudo update-ca-certificates
fi
2 changes: 2 additions & 0 deletions bin/start
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
docker-compose -f docker-compose.yml start
2 changes: 2 additions & 0 deletions bin/status
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
docker-compose -f docker-compose.yml ps
2 changes: 2 additions & 0 deletions bin/stop
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
docker-compose -f docker-compose.yml stop
Loading

0 comments on commit 8125cb0

Please sign in to comment.