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: add Dockerfile #5

Closed
wants to merge 3 commits into from
Closed
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
6 changes: 6 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Dockerfile
docker-compose.yml
node_modules/
.git/
.idea/
.dockerignore
104 changes: 104 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
FROM php:8.3-apache-bookworm AS php

WORKDIR /build

# install dependencies to build image
RUN \
apt update && \
apt install libldap2-dev wget zlib1g-dev libpng-dev libzip-dev curl libcurl4-gnutls-dev libxml2-dev libpq-dev -y && \
rm -rf /var/lib/apt/lists/* && \
docker-php-ext-configure ldap --with-libdir=lib/x86_64-linux-gnu/ && \
docker-php-ext-configure pdo --with-libdir=lib/x86_64-linux-gnu/ && \
docker-php-ext-install ldap pdo && \
docker-php-ext-install zip curl bcmath dom ctype iconv pdo_mysql pdo_pgsql gd

RUN pecl install --force redis \
&& rm -rf /tmp/pear \
&& docker-php-ext-enable redis


# copy files
COPY . .
# get php composer
RUN wget https://raw.githubusercontent.com/composer/getcomposer.org/76a7060ccb93902cd7576b67264ad91c8a2700e2/web/installer -O - | php --
# install composer dependencies
ENV COMPOSER_ALLOW_SUPERUSER=1
RUN SYMFONY_ENV=prod php composer.phar install -o



FROM node:20-bullseye-slim AS node

WORKDIR /build
# build frontend files
COPY --from=php /build .
RUN yarn install --frozen-lockfile
RUN yarn build
RUN rm -r node_modules/



FROM php:8.3-apache-bookworm

WORKDIR /build

# add dependencies to final runtime image
RUN \
apt update && \
apt install libldap2-dev wget zlib1g-dev libpng-dev libzip-dev curl libcurl4-gnutls-dev libxml2-dev libpq-dev -y && \
rm -rf /var/lib/apt/lists/* && \
docker-php-ext-configure ldap --with-libdir=lib/x86_64-linux-gnu/ && \
docker-php-ext-configure pdo --with-libdir=lib/x86_64-linux-gnu/ && \
docker-php-ext-install ldap pdo && \
docker-php-ext-install zip curl bcmath dom ctype iconv pdo_mysql pdo_pgsql gd

RUN pecl install --force redis \
&& rm -rf /tmp/pear \
&& docker-php-ext-enable redis

COPY --from=node /build /var/www/html

# apply apache2 config for symfony
RUN bash -c 'echo -e "<VirtualHost *:80>\n\
ServerAdmin webmaster@localhost\n\
DocumentRoot /var/www/html/public/\n\
<Directory /var/www/html/public>\n\
AllowOverride None\n\
Require all granted\n\
FallbackResource /index.php\n\
</Directory>\n\
\n\
ErrorLog \${APACHE_LOG_DIR}/error.log\n\
CustomLog \${APACHE_LOG_DIR}/access.log combined\n\
\n\
</VirtualHost>\
" > /etc/apache2/sites-available/000-default.conf'

EXPOSE 80

WORKDIR /var/www/html

# specify environment variables for .env file

ENV REDIS_DSN="redis://redis"
ENV APP_ENV="prod"
ENV APP_SECRET=""
ENV DATABASE_URL="mysql://limas:limas@mysql:3306/limas?serverVersion=5.7.9&charset=utf8mb4"
ENV NEXAR_ID="client"
ENV NEXAR_SECRET="secret"
# ISO 3166 (alpha-2) country code
ENV NEXAR_COUNTRY="DE"
# ISO 4217 currency code
ENV NEXAR_CURRENCY="EUR"

VOLUME ["/var/www/html/data"]

# run build commands
RUN php bin/console limas:extjs:models
RUN php bin/console cache:warmup

# overwrite entrypoint for custom startup commands

RUN chmod +x /var/www/html/docker/entrypoint.sh

ENTRYPOINT ["/var/www/html/docker/entrypoint.sh"]
19 changes: 19 additions & 0 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/env bash

cd /var/www/html

# migrate database always to newest state
php bin/console doctrine:migrations:migrate

# onetime generation
if [[ ! -f /var/www/html/data/.docker_installed ]]; then
php bin/console limas:user:create --role super_admin admin admin@example.com admin
php bin/console lexik:jwt:generate-keypair
php bin/console limas:extjs:models
php bin/console cache:warmup
touch /var/www/html/data/.docker_installed
fi


# start apache
docker-php-entrypoint apache2-foreground
59 changes: 57 additions & 2 deletions documentation/Installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Dependencies
* php-dom
* php-ctype
* php-iconv
* php-redis
* [Composer](https://getcomposer.org/download/)
* MySQL 5.7 server
* Nginx or Apache
Expand All @@ -17,14 +18,68 @@ Dependencies
---

1. Copy or clone this repository into a folder on your server
3. Configure your webserver to serve from the `public/` folder. See [here](https://symfony.com/doc/6.1/setup/web_server_configuration.html) for additional information.
3. Configure your webserver to serve from the `public/` folder. See [here](https://symfony.com/doc/7.0/setup/web_server_configuration.html) for additional information.
4. Copy the global config file `cp .env .env.local` and edit `.env.local`:
* Change the line `APP_ENV=dev` to `APP_ENV=prod`
5. Install composer dependencies and generate autoload files: `SYMFONY_ENV=prod composer install --no-dev -o`
5. Install composer dependencies and generate autoload files: `SYMFONY_ENV=prod composer install -o`
6. Install client side dependencies and build it: `yarn install` and `yarn build`
7. Create database: `php bin/console doctrine:migrations:migrate`
8. Create superadmin account: `php bin/console limas:user:create --role super_admin admin admin@example.com admin`
* _Optional_ protect it: `php bin/console limas:user:protect admin`
9. Generate models.js asset: `php bin/console limas:extjs:models`
10. _Optional_ generate JWT keypair: `php bin/console lexik:jwt:generate-keypair`
11. _Optional_ (speeds up first load): Warmup cache: `php bin/console cache:warmup`


## Docker Usage

Manually build the docker image with: `docker build -t local-limas-build .`

Run the image with: `docker run --name limas -p 8080:80 -v "./data:/var/www/html/data" -e "APP_ENV=prod" -e "DATABASE_URL=mysql://username:password@mysql_host:3306/database-name?serverVersion=5.7.9&charset=utf8mb4"`

On the first start an admin user with `admin@example.com` and `admin` will be created, as well as the database migrations, which run on every start.

A docker-compose example can be found here:
```yaml
services:
db:
image: mysql
restart: unless-stopped
ports:
- 3306:3306
environment:
MYSQL_ROOT_PASSWORD: example
MYSQL_DATABASE: limas
MYSQL_USER: limas
MYSQL_PASSWORD: limas
limas:
image: local-limas-build
restart: unless-stopped
ports:
- 8080:80
volumes:
- ./data:/var/www/html/data
environment:
APP_ENV: prod
DATABASE_URL: mysql://limas:limas@db:3306/limas?serverVersion=5.7.9&charset=utf8mb4
redis:
image: redis:7-alpine
restart: unless-stopped
```

Connect to the application via `http://localhost:8080` (or the corresponding hostname of your server)

To add SSL, you need a reverse proxy with SSL configured, like traefik.

All Environment variables with their default values:

| Environment variable name | default value |
|---------------------------|----------------------------------------------------------------------------|
| REDIS_DSN | `redis://redis` |
| APP_ENV | `prod` (can only be set to `dev` or `prod`) |
| APP_SECRET | _empty_ |
| DATABASE_URL | `mysql://limas:limas@mysql:3306/limas?serverVersion=5.7.9&charset=utf8mb4` |
| NEXAR_ID | `client` |
| NEXAR_SECRET | `secret` |
| NEXAR_COUNTRY | `DE` |
| NEXAR_CURRENCY | `EUR` |