project symfony kubernetes code example

Example 1: project symfony kubernetes

# This file is auto-generated during the composer installparameters:    database_host_rw: '%env(DATABASE_HOST_RW)%'    database_host_ro: '%env(DATABASE_HOST_RO)%'    database_port: '%env(DATABASE_PORT)%'    database_name: '%env(DATABASE_NAME)%'    database_user: '%env(DATABASE_USER)%'    database_password: '%env(DATABASE_PASSWORD)%'    redis.host: '%env(REDIS_HOST)%'    redis.port: '%env(REDIS_PORT)%'    filesystem.use_remote: '%env(FS_USE_REMOTE)%'    filesystem.endpoint: 'your spaces or amazon s3 endpoint'    filesystem.buckets.uploads.cdn: 'your cdn prefix' # i use this to translate filepaths to web urls    filesystem.credentials.key: '%env(FS_KEY)%'    filesystem.credentials.secret: '%env(FS_SECRET)%'# Now, we are defining defaults    env(DATABASE_HOST_RW): localhost    env(DATABASE_HOST_RO): localhost    env(DATABASE_PORT): 3306    env(DATABASE_NAME): your local db name    env(DATABASE_USER): db_user    env(DATABASE_PASSWORD): db_password_local    env(REDIS_HOST): localhost    env(REDIS_PORT): 6379    env(FS_USE_REMOTE): false    assets_base: http://localhost:8080    default_timezone: Asia/Damascus

Example 2: project symfony kubernetes

apiVersion: apps/v1kind: StatefulSetmetadata:  name: webserver  labels:    app: webserverspec:  selector:    matchLabels:      app: webserver  serviceName: webserver  replicas: 4  template:    metadata:      name: webserver      labels:        app: webserver    spec:     initContainers:        - name: init-php          image: your-php-image (PLEASE REPLACE THIS)          env:          - name: DATABASE_HOST_RW            valueFrom:              configMapKeyRef:                name: website-config                key: DATABASE_HOST_RW          - name: DATABASE_HOST_RO            valueFrom:              configMapKeyRef:                name: website-config                key: DATABASE_HOST_RO          - name: DATABASE_NAME            valueFrom:              configMapKeyRef:                name: website-config                key: DATABASE_NAME          - name: DATABASE_USER            valueFrom:              configMapKeyRef:                name: website-config                key: DATABASE_USER          - name: DATABASE_PASSWORD            valueFrom:              secretKeyRef:                name: some-secret-name-you-added                key: password          - name: REDIS_HOST            valueFrom:              configMapKeyRef:                name: website-config                key: REDIS_HOST          - name: REDIS_PORT            valueFrom:              configMapKeyRef:                name: website-config                key: REDIS_PORT          volumeMounts:          - name: code            mountPath: /code          command:          - bash          - "-c"          - |            # Copy the code to the shared volume, this will be mounted later into both of nginx and php            cp -r /var/www/html/you_web_site/* /code/            cd /code            composer install            php bin/console assets:install            php bin/console cache:clear --env=dev            php bin/console cache:clear --env=prod# I use this image to build my npm packages and webpack assets        - name: node          image: node:11          volumeMounts:          - name: code            mountPath: /var/www/html/you_web_site/          command:          - bash          - "-c"          - |            set -ex            cd /var/www/html/you_web_site/            npm install || echo "npm install did not work"            ./node_modules/.bin/webpack --mode=production      containers:      - name: nginx        image: you-nginx-image or offecial image (PLEASE REPLACE THIS)        imagePullPolicy: Always # you might want to change this        volumeMounts:        - name: code          mountPath: /var/www/html/you_web_site/      - name: php        image: your-php-image        imagePullPolicy: Always # again        volumeMounts:        - name: code          mountPath: /var/www/html/you_web_site/        env:            # I'm not gonna reput them.. please copy them from            # initContainer -> first Container            # Here, I do pass two extra env vars to store auth to digital ocean spaces- name: FS_KEY          valueFrom:            secretKeyRef:              name: your-secret-name              key: key        - name: FS_SECRET          valueFrom:            secretKeyRef:              name:  your-secret-name              key: secret         # That's another var I use to force my app to use local file system when it's set to false.        - name: FS_USE_REMOTE          value: "true"      # if your images are stored in private repo      imagePullSecrets:      - name: your-image-pull-secret      volumes:      - name: webserver-config-map        configMap:          name: webserver# I use a persistent volume to store code, so I don't rebuild everything on every pod restart (like, node_modules). However, it's perfectly fine to use temp volume, it will just take a bit longer to start the container  volumeClaimTemplates:  - metadata:      name: code    spec:      accessModes: ["ReadWriteOnce"]      resources:        requests:          storage: 4Gi      storageClassName: do-block-storage

Example 3: project symfony kubernetes

# PHP DockerfileFROM composer:1.5.1 AS composerFROM php:7.1.24-fpmRUN apt-get update && apt-get install -y \      acl \      libfreetype6-dev \      libjpeg62-turbo-dev \      libpng-dev \      libbz2-dev \      libicu-dev \      libzip-dev \      zip \    && docker-php-ext-install -j$(nproc) iconv \    && docker-php-ext-install bz2 \    && docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \    && docker-php-ext-install -j$(nproc) gd \    && apt-get install jpegoptim \    && docker-php-ext-install intl \    && docker-php-ext-install mysqli \    && docker-php-ext-install pdo_mysql \    && docker-php-ext-install opcache \    && docker-php-ext-configure zip --with-libzip \    && docker-php-ext-install zip \    && docker-php-ext-install exif \    && pecl install xdebug-2.5.0 \    && docker-php-ext-enable xdebug \    && apt-get install -y vim;# copy the Composer PHAR from the Composer image into the PHP imageCOPY --from=composer /usr/bin/composer /usr/bin/composerRUN echo 'memory_limit = 2048M' >> /usr/local/etc/php/conf.d/docker-php-memlimit.ini# Create user codekeeper, and use it as owner of the codeRUN useradd -ms /bin/bash codekeeperRUN mkdir -p /codeWORKDIR /codeRUN chown codekeeper:codekeeper .USER codekeeper# Install composer packages (by starting with coping only composer file, to make use of docker layering feature)COPY symfony/composer.json symfony/composer.lock ./RUN composer install --prefer-dist --no-scripts --no-dev --no-autoloader# Now, copy the codeCOPY --chown=codekeeper:codekeeper symfony /codeWORKDIR /code# Remove execute permissions from all files in (/code), but add it only for directories (to allow traversal)USER root#RUN chmod -R -x+X .# Give permissions to write to varRUN setfacl -dR -m u:www-data:rwX -m u:codekeeper:rwX varRUN setfacl -R -m u:www-data:rwX -m u:codekeeper:rwX varCMD ["sh", "-c", "(setfacl -R -m u:www-data:rwX -m u:codekeeper:rwX var) && (setfacl -dR -m u:www-data:rwX -m u:codekeeper:rwX var) && php-fpm"]

Tags:

Php Example