Skip to content

Commit

Permalink
tec: Provide a Docker image for production
Browse files Browse the repository at this point in the history
  • Loading branch information
marien-probesys committed Sep 27, 2023
1 parent a3a6cf2 commit dd71926
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/.env.*
/.git/
/docs/
/node_modules/
/tests/
/var/
/vendor/
/public/dev_assets/
12 changes: 12 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,18 @@ docker-build: ## Rebuild Docker containers
docker-clean: ## Clean the Docker stuff
$(DOCKER_COMPOSE) down

.PHONY: docker-image
docker-image: ## Build the Docker image for production (take a VERSION argument)
ifndef VERSION
$(error You need to provide a "VERSION" argument)
endif
docker build \
--build-arg VERSION="$(VERSION)" \
--build-arg SOURCE_COMMIT="$(shell git describe --match '' --always --abbrev=42 --dirty)" \
-t ghcr.io/probesys/bileto:$(VERSION) \
-f docker/production/Dockerfile \
.

.PHONY: install
install: ## Install the dependencies
$(COMPOSER) install
Expand Down
78 changes: 78 additions & 0 deletions docker/production/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# This file is part of Bileto.
# Copyright 2022-2023 Probesys
# SPDX-License-Identifier: AGPL-3.0-or-later

# Build the assets
FROM node:alpine AS assets

WORKDIR /app
COPY package*.json /app
COPY .vite/ /app/.vite
COPY assets/ /app/assets
RUN npm install && npm run build

# Configure the application
FROM php:8.2-apache

ENV APP_ENV prod
ENV COMPOSER_HOME /tmp
ENV TZ Europe/Paris

CMD ["apache2-foreground"]
ENTRYPOINT ["sh", "/entrypoint.sh"]

ARG VERSION
ARG SOURCE_COMMIT

LABEL org.opencontainers.image.authors="Probesys <https://www.probesys.com/contact>" \
org.opencontainers.image.url="https://bileto.fr/" \
org.opencontainers.image.documentation="https://github.com/Probesys/bileto/tree/main/docs" \
org.opencontainers.image.source="https://github.com/Probesys/bileto" \
org.opencontainers.image.version="${VERSION}" \
org.opencontainers.image.revision="${SOURCE_COMMIT}" \
org.opencontainers.image.vendor="Probesys" \
org.opencontainers.image.licenses="AGPL-3.0-or-later" \
org.opencontainers.image.title="Bileto" \
org.opencontainers.image.description="The ergonomic ticketing tool for managing your Help Desk."

# Install Composer
COPY --from=composer/composer /usr/bin/composer /usr/bin/composer

# Configure Apache
COPY docker/production/apache.conf /etc/apache2/sites-available/000-default.conf

# Install the dependencies
RUN apt-get update \
&& apt-get install -y \
libicu-dev \
libldap-dev \
libpq-dev \
libxslt-dev \
libzip-dev \
unzip \
&& docker-php-ext-install -j$(nproc) \
intl \
ldap \
pdo \
pdo_mysql \
pdo_pgsql \
xsl \
zip \
&& a2dismod -qf alias \
&& a2enmod rewrite \
&& ln -snf /usr/share/zoneinfo/$TZ /etc/localtime \
&& echo $TZ > /etc/timezone \
&& printf '[PHP]\ndate.timezone = ${TZ}\n' > /usr/local/etc/php/conf.d/timezone.ini

# Copy the code in the image
COPY . /var/www/html/
RUN rm -rf /var/www/html/public/assets
COPY --from=assets /app/public/assets/ /var/www/html/public/assets/
COPY --from=assets /app/public/manifest.json /var/www/html/public/
COPY docker/production/entrypoint.sh /entrypoint.sh

# Install the Composer dependencies and set correct permissions
RUN composer install --no-dev --optimize-autoloader --no-scripts \
&& chown -R www-data:www-data /var/www/html/

USER www-data
12 changes: 12 additions & 0 deletions docker/production/apache.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<VirtualHost *:80>
DocumentRoot /var/www/html/public

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

<Directory /var/www/html/public>
AllowOverride None
Require all granted
FallbackResource /index.php
</Directory>
</VirtualHost>
13 changes: 13 additions & 0 deletions docker/production/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/sh
set -e

rm -f /tmp/healthy.txt

# Make sure to migrate the application
php bin/console cache:clear
php bin/console doctrine:migration:migrate --no-interaction
php bin/console db:seeds:load

touch /tmp/healthy.txt

exec "$@"

0 comments on commit dd71926

Please sign in to comment.