Skip to content

Commit

Permalink
Improve Docker setup (Azuriom#91)
Browse files Browse the repository at this point in the history
  • Loading branch information
magrigry authored Feb 7, 2022
1 parent eecd309 commit 86b813e
Show file tree
Hide file tree
Showing 4 changed files with 200 additions and 81 deletions.
36 changes: 0 additions & 36 deletions Makefile

This file was deleted.

105 changes: 105 additions & 0 deletions azuriom.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#!/bin/sh

SCRIPT=$(realpath "$0")
SCRIPT_DIR=$(dirname "$SCRIPT")

cd "${SCRIPT_DIR}" || exit

case $1 in

"build")
bash "$0" composer-install
bash "$0" npm-install
bash "$0" npm-run-prod
bash "$0" laravel-symlink
docker-compose build
exit
;;

"start")
docker-compose up -d
exit
;;

"stop")
docker-compose stop
exit
;;

"docker-compose-build")
docker-compose build
exit
;;

"npm-install")
docker run -it --rm -v "${SCRIPT_DIR}":/usr/src/app -w /usr/src/app node:12 npm ci
exit
;;

"npm-run-prod")
docker run -it --rm -v "${SCRIPT_DIR}":/usr/src/app -w /usr/src/app node:12 npm run prod
exit
;;

"composer-install")
docker run --rm --interactive --tty --volume "${SCRIPT_DIR}":/app composer install
exit
;;

"laravel-generate-key")
docker-compose exec php-fpm php artisan key:generate
exit
;;

"laravel-init-db")
docker-compose exec php-fpm php artisan migrate --seed
exit
;;

"laravel-migrate")
docker-compose exec php-fpm php artisan migrate
exit
;;

"laravel-symlink")
docker-compose exec php-fpm php artisan storage:link
exit
;;

"laravel-create-admin")
docker-compose exec php-fpm php artisan user:create --admin
exit
;;

"laravel-clear-cache")
docker-compose exec php-fpm php artisan cache:clear
exit
;;

"artisan")
shift
docker-compose exec php-fpm php artisan "$*"
exit
;;

esac

# Display Help
echo "Manage Azuriom using docker and docker-compose. See https://github.com/Azuriom/Azuriom/blob/master/docker/INSTALL.md"
echo
echo "Usage: ./azuriom.sh COMMAND [arguments]"
echo
echo "Commands:"
echo " build Build the whole application."
echo " start Start containers (require the whole application to be built)"
echo " docker-compose-build Build containers"
echo " npm-install Install npm dependencies"
echo " npm-run-prod Compile assets (require npm dependencies to be installed)"
echo " composer-install Install composer dependencies"
echo " laravel-generate-key Generate laravel APP_KEY in .env file (used by laravel for data encryption)"
echo " laravel-init-db Initiate database"
echo " laravel-migrate Run migration (mostly used when updating to insert database changes)"
echo " laravel-symlink Create a symlink (create a symlink public/storage -> storage/app/public)"
echo " laravel-create-admin Create an admin user through CLI"
echo " laravel-clear-cache Clear laravel cache"
echo " artisan <commands> Run any artisan command (e.g. ./azuriom artisan cache:clear)"
8 changes: 2 additions & 6 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,15 @@ services:
build: docker/nginx
restart: always
ports:
- '80:80'
- "${PORT-80}:80"
volumes:
- './:/usr/share/nginx/html'
php-fpm:
build: docker/php
restart: always
volumes:
- './:/usr/share/nginx/html'
composer:
image: 'composer:1.10'
command: install --ignore-platform-reqs
volumes:
- './:/app'

database:
image: 'postgres:12'
restart: always
Expand Down
132 changes: 93 additions & 39 deletions docker/INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,88 +3,142 @@
Requirements:
- [Docker](https://docs.docker.com/engine/install/)
- [Docker Compose](https://docs.docker.com/compose/install/)
- [Make](https://en.wikipedia.org/wiki/Make_(software))
- bash shell (usually already installed)
- [git](https://git-scm.com/)

Note : All the following commands should be run as root

# Dependencies installation example

```
apt update
apt install -y curl git software-properties-common curl apt-transport-https ca-certificates gnupg tar
curl -sSL https://get.docker.com/ | CHANNEL=stable bash
curl -L "https://github.com/docker/compose/releases/download/latest/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
```

And enable Docker on boot
```
systemctl enable --now docker && service docker start
```

# Installation

Clone the repository
## Download Azuriom
```
git clone https://github.com/Azuriom/Azuriom.git
mkdir -p /var/azuriom && cd /var/azuriom && git clone --depth 1 https://github.com/Azuriom/Azuriom.git .
```

Go into the folder
Go into the downloaded folder
```
cd Azuriom
```

Set rights on files & folders
## Set rights on files & folders
```
chmod -R 755 storage bootstrap/cache resources/themes plugins
chmod -R o+rw storage bootstrap/cache resources/themes plugins
chmod +x azuriom.sh
```

Change the owner to `www-data` (or make files writable for everybody but it's **unsecure**)
## Change the owner to www-data
If the `www-data` user doesn't exists, you need to add it (if an error tell your that this user already exists no worries, just skip it) :
```
useradd www-data
```
```
chown -R www-data *
chown -R www-data:www-data *
```

## Setup `.env`
Copy the `.env.example` to `.env` and set the database information like this:

### Use an external database that uou setup on your own

```
DB_CONNECTION=mysql
DB_HOST=[IP adresse of your database. If you use a local database, set the public IP of your server (localhost or 127.0.0.1 won't work)]
DB_PORT=3306
DB_DATABASE=[database_name]
DB_USERNAME=[database_user]
DB_PASSWORD=[database_password]
```

### Or use a database provided with docker

```
DB_CONNECTION=pgsql
DB_HOST=database
DB_PORT=5432
DB_DATABASE=[database name]
DB_USERNAME=[database user]
DB_PASSWORD=[database password]
DB_DATABASE=azuriom
DB_USERNAME=azuriom
DB_PASSWORD=[Here_A_Random_String]
```

Start the containers
```
make run
```

Generate the secret key
## Build everything
```
make generate-key
./azuriom.sh build
```

Database initialisation
## Generate the secret key (only for new install)
```
make init-db
./azuriom.sh laravel-generate-key
```

Generate the symlink
## Database initialisation (only for new install)
```
make symlink
./azuriom.sh laravel-init-db
```

Create a new user as an administrator
## Create a new user as an administrator
```
make create-admin
./azuriom.sh laravel-create-admin
```

Install npm dependencies and compile assets Laravel mix
```
npm install && npm run prod
## Configure scheduled tasks
```bash
crontab -l > cron
echo "* * * * * cd /var/azuriom && make artisan schedule:run >> /dev/null 2>&1" >> cron
crontab cron
rm cron
```

_If there is some error at this step, edit `webpack.mix.js` and change the timeout at the bottom of this file, like this_
```javascript
setTimeout(() => {
//
}, 10000); // change the value here
```
# Start and stop

## Start your services on default port 80
```
./azuriom start
```

It's ready to be used on port 80!
If you want to always start your container on a specific port, just add `PORT=8080` to your `.env` file

[Optional]
You can add the scheduler with this CRON entry
## You can down the containers with
```
* * * * * cd [Path to the CMS folder] && docker-compose exec php-fpm php artisan schedule:run >> /dev/null 2>&1
./azuriom stop
```

---
You can down the containers with
## How to update Azuriom

* `git pull`
* `./azuriom.sh build`
* `./azuriom.sh laravel-clear-cache`
* `./azuriom.sh laravel-migrate`

# More commands
```
make stop
Commands:
build Build the whole application.
start Start containers (require the whole application to be built)
docker-compose-build Build containers
npm-install Install npm dependencies
npm-run-prod Compile assets (require npm dependencies to be installed)
composer-install Install composer dependencies
laravel-generate-key Generate laravel APP_KEY in .env file (used by laravel for data encryption)
laravel-init-db Initiate database
laravel-migrate Run migration (mostly used when updating to insert database changes)
laravel-symlink Create a symlink (create a symlink public/storage -> storage/app/public)
laravel-create-admin Create an admin user through CLI
laravel-clear-cache Clear laravel cache
artisan <commands> Run any artisan command (e.g. ./azuriom artisan cache:clear)
```

0 comments on commit 86b813e

Please sign in to comment.