Skip to content

Commit

Permalink
Update Dockerfile and Caddyfile configurations
Browse files Browse the repository at this point in the history
  • Loading branch information
flemming-pr committed Jan 6, 2024
1 parent 0ef28fe commit d608b9f
Show file tree
Hide file tree
Showing 6 changed files with 173 additions and 45 deletions.
42 changes: 26 additions & 16 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,39 +1,49 @@
FROM php:8.2-cli-alpine3.18 AS build

RUN mkdir -p /var/www/html
RUN mkdir -p /var/www/html/databasestore

WORKDIR /var/www/html

# Install Composer manually
COPY --from=composer/composer:latest-bin /composer /usr/bin/composer

RUN apk add --no-cache \
npm

COPY ./ /var/www/html

RUN composer install --optimize-autoloader --no-interaction --no-dev --ignore-platform-req=ext-intl

FROM dunglas/frankenphp
FROM unit:php8.2

RUN mkdir -p /var/www/html
RUN mkdir -p /var/www/html/databasestore

WORKDIR /var/www/html

WORKDIR /app/public
COPY --from=build --chown=unit:unit /var/www/html /var/www/html

ENV TZ=Europe/Berlin

RUN apt-get update && \
apt-get install -y netcat-traditional && \
rm -rf /var/lib/apt/lists/*
# Update package lists and install required dependencies
RUN apt-get update && apt-get install -y \
netcat \
libicu-dev \
libjpeg-dev \
libpng-dev \
libfreetype6-dev \
sudo \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

RUN install-php-extensions \
pdo_mysql \
gd \
intl \
zip \
opcache
# Install and enable the intl and gd extensions
RUN docker-php-ext-install intl gd pdo_mysql

COPY --from=build /var/www/html /app/public
COPY docker/config.json /docker-entrypoint.d/config.json

RUN chmod +x /app/public/docker/entrypoint.sh
COPY docker/entrypoint.sh /docker-entrypoint.d/entrypoint.sh

EXPOSE 80
RUN chmod +x /docker-entrypoint.d/entrypoint.sh

ENTRYPOINT ["/app/public/docker/entrypoint.sh"]
CMD [ "frankenphp", "run", "--config", "/app/public/docker/Caddyfile" ]
EXPOSE 80
45 changes: 39 additions & 6 deletions backend/docker/Caddyfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,41 @@
{
# Enable FrankenPHP
frankenphp
# Configure when the directive must be executed
order php_server before file_server
# Disable tls
auto_https off
{$CADDY_GLOBAL_OPTIONS}

frankenphp {
#worker /path/to/your/worker.php
{$FRANKENPHP_CONFIG}
}

# https://caddyserver.com/docs/caddyfile/directives#sorting-algorithm
order mercure after encode
order vulcain after reverse_proxy
order php_server before file_server
order php before file_server
auto_https off
servers {
trusted_proxies static [private_ranges]
}
}

{$CADDY_EXTRA_CONFIG}

{$SERVER_NAME:localhost} {
log {
# Redact the authorization query parameter that can be set by Mercure
format filter {
wrap console
fields {
uri query {
replace authorization REDACTED
}
}
}
}

root * public/
encode zstd gzip

{$CADDY_SERVER_EXTRA_DIRECTIVES}

php_server
}
30 changes: 30 additions & 0 deletions backend/docker/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"listeners": {
"*:80": {
"pass": "routes"
}
},
"routes": [
{
"match": {
"uri": "!/index.php"
},
"action": {
"share": "/var/www/html/public$uri",
"response_headers": {
"Cache-Control": "max-age=60, s-maxage=120"
},
"fallback": {
"pass": "applications/laravel"
}
}
}
],
"applications": {
"laravel": {
"type": "php",
"root": "/var/www/html/public/",
"script": "index.php"
}
}
}
1 change: 1 addition & 0 deletions backend/docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/bash

pwd
ls -al

mkdir -p storage/framework/{sessions,views,cache}
Expand Down
66 changes: 66 additions & 0 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
version: "3"

networks:
web:
external: true
stack:

volumes:
storage:
database:

services:
backend:
image: ghcr.io/chaostreff-flensburg/pretty-good-proposal/backend:latest
restart: always
volumes:
- storage:/var/www/html/storage
labels:
- "traefik.enable=true"
- "traefik.http.routers.api-pgp.rule=Host(`api.bewerbung.c3fl.de`)"
- "traefik.http.routers.api-pgp.entrypoints=https,http"
- "traefik.http.services.api-pgp.loadbalancer.server.port=80"
- "traefik.http.routers.api-pgp.tls.certresolver=mytlschallenge"
- "traefik.docker.network=web"
working_dir: /app/public
networks:
- web
- stack
env_file:
- .env
logging:
options:
max-size: "10m"

database:
image: mysql:8.0
volumes:
- database:/var/lib/mysql:cached
networks:
- stack
ports:
- 127.0.0.1:3306:3306
env_file:
- .env
command: mysqld --character-set-server=utf8 --collation-server=utf8_general_ci --sql_mode=''
logging:
options:
max-size: "10m"
max-file: "3"
restart: always

frontend:
image: ghcr.io/chaostreff-flensburg/pretty-good-proposal/frontend:latest
restart: always
labels:
- "traefik.enable=true"
- "traefik.http.routers.frontend-pgp.rule=Host(`bewerbung.c3fl.de`)"
- "traefik.http.routers.frontend-pgp.entrypoints=https,http"
- "traefik.http.services.frontend-pgp.loadbalancer.server.port=80"
- "traefik.http.routers.frontend-pgp.tls.certresolver=mytlschallenge"
- "traefik.docker.network=web"
networks:
- web
logging:
options:
max-size: "10m"
34 changes: 11 additions & 23 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
version: "3"

networks:
web:
external: true
stack:

volumes:
Expand All @@ -11,23 +9,18 @@ volumes:

services:
backend:
image: ghcr.io/chaostreff-flensburg/pretty-good-proposal/backend:latest
build:
context: backend
dockerfile: Dockerfile
restart: always
volumes:
- storage:/var/www/html/storage
labels:
- "traefik.enable=true"
- "traefik.http.routers.api-pgp.rule=Host(`api.bewerbung.c3fl.de`)"
- "traefik.http.routers.api-pgp.entrypoints=https,http"
- "traefik.http.services.api-pgp.loadbalancer.server.port=80"
- "traefik.http.routers.api-pgp.tls.certresolver=mytlschallenge"
- "traefik.docker.network=web"
working_dir: /app/public
networks:
- web
- stack
env_file:
- .env
ports:
- 8082:80
logging:
options:
max-size: "10m"
Expand All @@ -39,7 +32,7 @@ services:
networks:
- stack
ports:
- 127.0.0.1:3306:3306
- 127.0.0.1:3366:3306
env_file:
- .env
command: mysqld --character-set-server=utf8 --collation-server=utf8_general_ci --sql_mode=''
Expand All @@ -50,17 +43,12 @@ services:
restart: always

frontend:
image: ghcr.io/chaostreff-flensburg/pretty-good-proposal/frontend:latest
build:
context: frontend
dockerfile: Dockerfile
restart: always
labels:
- "traefik.enable=true"
- "traefik.http.routers.frontend-pgp.rule=Host(`bewerbung.c3fl.de`)"
- "traefik.http.routers.frontend-pgp.entrypoints=https,http"
- "traefik.http.services.frontend-pgp.loadbalancer.server.port=80"
- "traefik.http.routers.frontend-pgp.tls.certresolver=mytlschallenge"
- "traefik.docker.network=web"
networks:
- web
ports:
- 8083:80
logging:
options:
max-size: "10m"

0 comments on commit d608b9f

Please sign in to comment.