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 all commits
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
9 changes: 8 additions & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ CRON_PASSWORD=
###> doctrine/doctrine-bundle ###
# Siehe https://www.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url
DATABASE_URL="mysql://db_user:db_password@localhost:3306/db_name"
MYSQL_ROOT_PASSWORD=changeThisToASecurePassword
MYSQL_DATABASE=db_name
MYSQL_USER=db_user
MYSQL_PASSWORD=db_password
###< doctrine/doctrine-bundle ###

###> symfony/messenger ###
Expand All @@ -37,4 +41,7 @@ MESSENGER_TRANSPORT_DSN=doctrine://default
MAILER_DSN=native://default
###< symfony/mailer ###

PHP_BINARY=/usr/bin/php
PHP_BINARY=/usr/bin/php

### Docker ###
TZ=Europe/Berlin
73 changes: 73 additions & 0 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: Docker Image CI

on:
workflow_dispatch:
release:
types: [ published ]

env:
# Use docker.io for Docker Hub if empty
REGISTRY: ghcr.io
# github.repository as <account>/<repo>
IMAGE_NAME: ${{ github.repository }}

jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
# This is used to complete the identity challenge
# with sigstore/fulcio when running outside of PRs.
id-token: write

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Log in to the Container registry
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

# Set image name to lower case because ghcr.io complains about uppercase
- name: downcase image name
run: |
echo "IMAGE_NAME_LOWER=${IMAGE_NAME@L}" >> "${GITHUB_ENV}"

- name: Set env
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV

- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME_LOWER }}

# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
- name: Build and push Docker image to latest
if: ${{ !github.event.release.prerelease && github.event_name != 'push' }}
id: build-and-push-latest
uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME_LOWER }}:latest
labels: ${{ steps.meta.outputs.labels }}
build-args: version_info=${{ env.RELEASE_VERSION }} (${{ env.CURRENT_DATE }})

# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
- name: Build and push Docker image to ${{ env.RELEASE_VERSION }} and unstable
if: ${{ github.event_name != 'push' && github.event_name != 'pull_request' }}
id: build-and-push-tag
uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME_LOWER }}:${{ env.RELEASE_VERSION }} , ${{ env.REGISTRY }}/${{ env.IMAGE_NAME_LOWER }}:unstable
labels: ${{ steps.meta.outputs.labels }}
build-args: version_info=${{ env.RELEASE_VERSION }} (${{ env.CURRENT_DATE }})
122 changes: 122 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
# 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 --no-dev --classmap-authoritative --no-scripts

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 the assets
RUN npm install \
&& npm run build \
&& php bin/console assets:install

FROM base AS runner

WORKDIR /var/www/html

# Copy necessary files into the container
COPY . .

# Remove unnecessary files
RUN rm -rf ./docs
RUN rm -rf ./.github
RUN rm -rf ./docker-compose.yml
RUN rm -rf ./Dockerfile
RUN rm -rf ./.gitignore

# 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

# Output of assets? --> Needs to be copied to the final image - maybe separate stage

# Remove the .htaccess file because we are using Nginx
RUN rm -rf ./public/.htaccess

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

# 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

# Expose port 80
EXPOSE 80

# Use the startup script as the entrypoint
ENTRYPOINT ["/usr/local/bin/startup.sh"]
34 changes: 34 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
services:
web:
build: .
restart: always
ports:
- "8080:80"
depends_on:
db:
condition: service_healthy
env_file:
- .env.local
volumes:
- certs:/var/www/html/certs
# nginx configuration file
# - ./nginx.conf:/etc/nginx/sites-enabled/default

db:
image: mariadb:10.4
restart: always
env_file:
- .env.local
volumes:
- db_data:/var/lib/mysql
healthcheck:
test: mysqladmin ping -h 127.0.0.1 -u $$MYSQL_USER --password=$$MYSQL_PASSWORD
interval: 5s
timeout: 20s
retries: 10

volumes:
db_data:
certs:


Loading