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

Docker #88

Draft
wants to merge 31 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
99a2226
ci: added docker image for idp
SimonFrank14 Jul 28, 2024
42edb49
Improvments for Docker Image
SimonFrank14 Aug 1, 2024
e321da7
Merge branch 'SchulIT:master' into docker-image
SimonFrank14 Aug 1, 2024
e925105
Set no-dev flag for composer install
SimonFrank14 Aug 1, 2024
3e4d08d
Create docker-image.yml
SimonFrank14 Aug 1, 2024
3aa7f55
Merge pull request #1 from SimonFrank14/docker-image
SimonFrank14 Aug 1, 2024
d00535b
Update docker-image.yml
SimonFrank14 Aug 1, 2024
51cef3d
Update docker-image.yml
SimonFrank14 Aug 1, 2024
6ccc5f9
Update docker-image.yml
SimonFrank14 Aug 1, 2024
46d0614
Added Github Action to automatically build image (#2)
SimonFrank14 Aug 1, 2024
752f3cb
Added restart prop to web container
SimonFrank14 Aug 1, 2024
0920017
Merge branch 'docker-image' of https://github.com/SimonFrank14/idp in…
SimonFrank14 Aug 1, 2024
d3a0be9
boost startup of web container after db ready
SimonFrank14 Aug 1, 2024
66102ad
added docker installation docu
SimonFrank14 Aug 1, 2024
07d49cc
Docker image (#3)
SimonFrank14 Aug 3, 2024
282c253
nginx fix
SimonFrank14 Aug 3, 2024
4c4476f
remove no dev flag temp
SimonFrank14 Aug 3, 2024
65338de
Merge branch 'master' into docker-image
SimonFrank14 Aug 4, 2024
e6930f1
Docker image (#4)
SimonFrank14 Aug 4, 2024
1ef6d47
Update docker-image.yml
SimonFrank14 Aug 8, 2024
a24d4c1
Update docker-image.yml
SimonFrank14 Aug 8, 2024
58e3c4e
Merge branch 'SchulIT:master' into master
SimonFrank14 Aug 8, 2024
2b0ff79
Update docker-image.yml
SimonFrank14 Aug 8, 2024
580d854
Update docker-image.yml
SimonFrank14 Aug 8, 2024
20e68f0
Update docker-image.yml
SimonFrank14 Aug 8, 2024
4139d1c
Update docker-image.yml
SimonFrank14 Aug 8, 2024
d8c5208
some optimizations for the docker build image
SimonFrank14 Aug 8, 2024
1956310
Merge branch 'master' into docker-image
SimonFrank14 Aug 8, 2024
336aab5
Update docker-image.yml (#5)
SimonFrank14 Aug 8, 2024
adc6b0a
fixed filesystem permission issue
SimonFrank14 Aug 11, 2024
05f1ead
Cache was not included in chown
SimonFrank14 Aug 11, 2024
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
124 changes: 124 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
# Use the official PHP image with FPM as the base image
FROM php:8.2-fpm AS base

# Install dependencies and PHP extensions
RUN apt-get update && apt-get install -y \
unzip \
libxml2-dev \
libssl-dev \
libzip-dev \
libpng-dev \
libfreetype6-dev \
libjpeg62-turbo-dev \
libonig-dev \
libxslt1-dev \
libmcrypt-dev \
libsodium-dev \
nginx \
openssl \
&& docker-php-ext-configure gd --with-freetype --with-jpeg \
&& docker-php-ext-install -j$(nproc) \
ctype \
dom \
filter \
iconv \
intl \
mbstring \
pdo_mysql \
phar \
simplexml \
sodium \
xml \
xmlwriter \
zip \
gd \
xsl \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

# Set memory limit for PHP
RUN echo "memory_limit=512M" > /usr/local/etc/php/conf.d/memory-limit.ini
ENV PHP_MEMORY_LIMIT=512M

FROM base AS composer

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

# Set COMPOSER_ALLOW_SUPERUSER environment variable
ENV COMPOSER_ALLOW_SUPERUSER=1

# Set working directory
WORKDIR /var/www/html

# Copy the composer.json and composer.lock files into the container
COPY . .

# Install PHP dependencies including symfony/runtime
RUN composer install --classmap-authoritative --no-scripts
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--no-dev Flag hinzufügen, wenn fertig mit testen


FROM base AS node

# Set working directory
WORKDIR /var/www/html

COPY --from=composer /var/www/html/vendor /var/www/html/vendor

# Copy the package.json and package-lock.json files into the container
COPY . .

# Install Node.js dependencies
RUN apt-get update && apt-get install -y \
curl \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

# Install Node.js and npm
RUN curl -fsSL https://deb.nodesource.com/setup_18.x | bash - \
&& apt-get install -y nodejs \
&& npm install -g npm@latest

# Install Node.js dependencies and build assets
RUN npm install \
&& npm run build \
&& php bin/console assets:install

FROM base AS runner

# Copy necessary files into the container
#COPY bin /var/www/html/bin
#COPY .env /var/www/html/.env
#COPY templates /var/www/html/templates
#COPY migrations /var/www/html/migrations
#COPY config /var/www/html/config
#COPY src /var/www/html/src
#COPY public /var/www/html/public
COPY . .

# Copy build files from the previous stages
COPY --from=node /var/www/html/public /var/www/html/public
COPY --from=composer /var/www/html/vendor /var/www/html/vendor

WORKDIR /var/www/html

# Create SAML certificate
RUN php bin/console app:create-certificate --type saml --no-interaction

# Copy the Nginx configuration file into the container
COPY default.conf /etc/nginx/sites-enabled/sso
# COPY default.conf /etc/nginx/conf.d/default.conf

# Copy the startup script into the container
COPY startup.sh /usr/local/bin/startup.sh

# Ensure the startup script is executable
RUN chmod +x /usr/local/bin/startup.sh

# Set first run flag
ENV FIRST_RUN=1

# Expose port 80
EXPOSE 80

# Use the startup script as the entrypoint
CMD ["/usr/local/bin/startup.sh"]
56 changes: 56 additions & 0 deletions default.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
server {
listen 80;
server_name localhost;

root /var/www/html/public;

location / {
# try to serve file directly, fallback to index.php
try_files $uri /index.php$is_args$args;
}

# optionally disable falling back to PHP script for the asset directories;
# nginx will return a 404 error when files are not found instead of passing the
# request to Symfony (improves performance but Symfony's 404 page is not displayed)
# location /bundles {
# try_files $uri =404;
# }

location ~ ^/index\.php(/|$) {
fastcgi_pass 127.0.0.1:9000;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;

# When you are using symlinks to link the document root to the
# current version of your application, you should pass the real
# application path instead of the path to the symlink to PHP
# FPM.
# Otherwise, PHP's OPcache may not properly detect changes to
# your PHP files (see https://github.com/zendtech/ZendOptimizerPlus/issues/126
# for more information).
# Caveat: When PHP-FPM is hosted on a different machine from nginx
# $realpath_root may not resolve as you expect! In this case try using
# $document_root instead.
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;

proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
# Prevents URIs that include the front controller. This will 404:
# http://domain.tld/index.php/some-path
# Remove the internal directive to allow URIs like this
# internal;
}

# return 404 for all other php files not matching the front controller
# this prevents access to other php files you don't want to be accessible.
location ~ \.php$ {
return 404;
}

# Optional logging
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
}
29 changes: 29 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
version: '3.8'

services:
web:
build: .
ports:
- "8080:80"
depends_on:
- db
env_file:
- .env.local

db:
image: mariadb:10.4
restart: always
environment:
MYSQL_ROOT_PASSWORD: rootpassword
MYSQL_DATABASE: idp
MYSQL_USER: idpuser
MYSQL_PASSWORD: idppassword
ports:
- "3306:3306"
volumes:
- db_data:/var/lib/mysql

volumes:
db_data:


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

# Check if the FIRST_RUN environment variable is 1
if [ "$FIRST_RUN" = "1" ]; then
# Run database migrations
php bin/console doctrine:migrations:migrate --no-interaction

# Perform initial setup
php bin/console app:setup

# Register cron jobs
php bin/console shapecode:cron:scan

# Update Browscap
php bin/console app:browscap:update

# Set FIRST_RUN environment variable to 0
export FIRST_RUN=0
fi

# Start PHP-FPM
php-fpm &

# Start Nginx
nginx -g 'daemon off;'