Add docker compose setup (#73)

* Add docker compose setup

* Shorten healthcheck interval for faster startup

* Add .env file for docker setup. Take changes in composer/package-lock into account.

* Add readme entry

* JWT force command + readme minor changes

* Udpated readme

---------

Co-authored-by: Julien Nahum <julien@nahum.net>
This commit is contained in:
Philip Gatzka 2023-02-22 19:13:32 +01:00 committed by GitHub
parent 5a1bd0e0c6
commit 49d1a237ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 194 additions and 5 deletions

8
.env.docker Normal file
View File

@ -0,0 +1,8 @@
POSTGRES_USER="postgres"
POSTGRES_PASSWORD="postgres"
POSTGRES_DB="postgres"
DB_HOST="database"
DB_DATABASE="postgres"
DB_USERNAME="postgres"
DB_PASSWORD="postgres"

2
.gitignore vendored
View File

@ -27,3 +27,5 @@ public/.DS_Store
.env.production
.env.staging
_ide_helper.php
/.make.*

43
Makefile Normal file
View File

@ -0,0 +1,43 @@
up: down .env .make.composer-install .make.npm-install .make.npm-build .make.artisan-key-generate .make.jwt-secret .make.migrate server
down:
docker compose down
clean:
rm ./.make.*
server:
docker compose up -d server
logs:
docker compose logs -f server
.make.composer-install: composer.json composer.lock
docker compose run --rm composer-install
touch $@
.make.npm-install: package.json package-lock.json
docker compose run --rm npm-install
touch $@
.make.npm-build:
docker compose run --rm npm-build
touch $@
.make.artisan-key-generate:
docker compose run --rm php-cli artisan key:generate
touch $@
.make.jwt-secret:
docker compose run --rm php-cli artisan jwt:secret --f
touch $@
.make.migrate:
docker compose run --rm migrate
touch $@
.env:
cp .env.example .env
.PHONY: up down clean server

View File

@ -33,18 +33,49 @@ The easiest way to get started with OpnForm is with the [official managed servic
It takes 1 minute to try out the builder for free. You'll have high availability, backups, security, and maintenance all managed for you.
## Self-hosting
🚧 This section is under construction!
### Requirements
- PHP >= 8.0
- MySQL/MariaDB or PostgreSQL
- Node.js and NPM/Yarn/... to compile assets
### Local installation
## Installation
### Docker installation 🐳
There's a `docker compose` setup automating most of the manual steps:
```bash
make up
```
The application is now running on [http://localhost:4000](http://localhost:4000).
Alternatively, you may use the compose setup on its own
```bash
# Start the application
docker compose up -d server
# Run php commands, for example
docker compose run php-cli artisan about
# ...or update npm dependencies
docker compose run node-cli npm ci
```
`make` keeps track of all executed targets using `.make.*` files.
In case you'd like to start from scratch (re-install dependencies, reset jwt
token, run migrations, ...), run
```bash
make clean
```
After that, `make` will re-execute all targets upon the next execution.
### Using Laravel Valet
This section explains how to get started locally with the project. It's most likely relevant if you're trying to work on the project.
First, let's work with the codebase and its dependencies.
```bash

75
docker-compose.yml Normal file
View File

@ -0,0 +1,75 @@
---
services:
php-cli:
build:
dockerfile: './php-cli.Dockerfile'
entrypoint: [ 'php' ]
volumes:
- '.:/project'
working_dir: '/project'
user: '1000'
node-cli:
image: 'node:16'
volumes:
- '.:/project'
working_dir: '/project'
user: '1000'
composer-cli:
build:
dockerfile: './php-cli.Dockerfile'
entrypoint: [ 'composer' ]
volumes:
- '.:/project'
working_dir: '/project'
user: '1000'
composer-install:
extends:
service: composer-cli
command: [ 'install' ]
npm-install:
extends:
service: node-cli
entrypoint: [ 'npm' ]
command: [ 'clean-install' ]
npm-build:
extends:
service: node-cli
entrypoint: [ 'npm', 'run' ]
command: [ 'build' ]
database:
image: 'postgres:15'
restart: 'unless-stopped'
env_file: '.env.docker'
healthcheck:
test: [ 'CMD-SHELL', 'pg_isready', '-d', 'postgres' ]
start_period: 5s
interval: 5s
timeout: 10s
retries: 3
migrate:
extends:
service: php-cli
depends_on:
database:
condition: service_healthy
env_file: '.env.docker'
command: [ 'artisan', 'migrate' ]
server:
extends:
service: php-cli
depends_on:
migrate:
condition: service_completed_successfully
env_file: '.env.docker'
command: [ '-S', '0.0.0.0:4000', '-t', './public']
ports:
- '4000:4000'

30
php-cli.Dockerfile Normal file
View File

@ -0,0 +1,30 @@
# syntax=docker/dockerfile:1.3-labs
FROM php:8.1-cli
COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/bin/
COPY --from=composer:2 /usr/bin/composer /usr/bin/composer
RUN <<EOF
install-php-extensions \
apcu \
bcmath \
bz2 \
calendar \
ffi \
gd \
gmp \
imagick \
intl \
mysqli \
pcntl \
pcov \
pdo_mysql \
pdo_pgsql \
redis \
soap \
sockets \
sodium \
xsl \
zip \
exif
EOF