Skip to content

Commit

Permalink
WIP docker configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
jamescrowley committed Nov 30, 2022
1 parent 503b85a commit 56857a1
Show file tree
Hide file tree
Showing 17 changed files with 214 additions and 81 deletions.
6 changes: 5 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,11 @@ jobs:
# deploy
gcloud app deploy app-<< parameters.serviceName >>.yaml --version ${CIRCLE_BUILD_NUM}
gcloud app deploy cron.yaml dispatch.yaml --version ${CIRCLE_BUILD_NUM}
- run: |
# deploy to google run too
gcloud run deploy dropapp-test --source . --project ${GOOGLE_PROJECT_ID} \
--add-cloudsql-instances=${<< parameters.envVariablePrefix >>DBNAME} \
--set-env-vars GOOGLE_CLOUD_PROJECT=${GOOGLE_PROJECT_ID}
create-sentry-release:
docker:
- image: circleci/node:4.8.2
Expand Down
Empty file removed .docker/.gitkeep
Empty file.
12 changes: 0 additions & 12 deletions .docker/php/Dockerfile

This file was deleted.

25 changes: 0 additions & 25 deletions .docker/php/dropapp.conf

This file was deleted.

3 changes: 1 addition & 2 deletions .gcloudignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,4 @@
# other folders to ignore
.docker
phinx.yml
docker-compose.yml
build.php
docker-compose.yml
2 changes: 1 addition & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"recommendations": [
"xdebug.php-debug",
"bmewburn.vscode-intelephense-client",
"fterrag.vscode-php-cs-fixer"
"junstyle.php-cs-fixer"
],
// List of extensions recommended by VS Code that should not be recommended for users of this workspace.
"unwantedRecommendations": [
Expand Down
4 changes: 2 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [

{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"port": 9003,
"pathMappings": {
"/var/www/html": "${workspaceFolder}"},
"/var/www/html": "${workspaceFolder}"
},
"log": true
},
{
Expand Down
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"[php]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "fterrag.vscode-php-cs-fixer"
"editor.defaultFormatter": "junstyle.php-cs-fixer"
},
"php-cs-fixer.rules": "@PhpCsFixer",
"intelephense.format.enable": false
Expand Down
96 changes: 96 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
FROM php:7.4.25-apache AS base
WORKDIR /var/www/html

# install needed libraries
RUN apt-get update \
&& apt-get -y --no-install-recommends install libfontconfig1 libxrender1 libxext6 zlib1g-dev libpng-dev libfreetype6-dev libjpeg62-turbo-dev \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

RUN a2enmod rewrite

RUN docker-php-ext-install \
gd \
pdo_mysql \
exif

# op cache
RUN docker-php-ext-install -j "$(nproc)" opcache

RUN set -ex; \
{ \
echo "; Cloud Run enforces memory & timeouts"; \
echo "memory_limit = -1"; \
echo "max_execution_time = 0"; \
echo "; File upload at Cloud Run network limit"; \
echo "upload_max_filesize = 32M"; \
echo "post_max_size = 32M"; \
echo "; Configure Opcache for Containers"; \
echo "opcache.enable = On"; \
echo "opcache.validate_timestamps = Off"; \
echo "; Configure Opcache Memory (Application-specific)"; \
echo "opcache.memory_consumption = 32"; \
} > "$PHP_INI_DIR/conf.d/cloud-run.ini"

RUN pecl install opencensus-alpha

# Use the PORT environment variable in Apache configuration files.
# https://cloud.google.com/run/docs/reference/container-contract#port
RUN sed -i 's/80/${PORT}/g' /etc/apache2/sites-available/000-default.conf /etc/apache2/ports.conf

FROM base AS debug

# RUN enable-xdebug in PHP 8 env
RUN pecl install xdebug && docker-php-ext-enable xdebug
# Configure PHP for development.
# https://github.com/docker-library/docs/blob/master/php/README.md#configuration
RUN mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini"

FROM composer:2.1.11 AS build

WORKDIR /var/www/html
# ensures we use docker cache and only rebuild composer
# if the dependencies have changed
COPY composer.json .
COPY composer.lock .
RUN composer install --no-dev --no-scripts --ignore-platform-reqs
COPY . .
RUN composer dump-autoload --optimize
RUN ls
RUN php build/build.php
RUN rm -r build/

FROM base AS final

# Configure PHP for production.
# https://github.com/docker-library/docs/blob/master/php/README.md#configuration
RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"

COPY --from=build /var/www/html /var/www/html



# docker pull myimage:latest-build | true
# docker pull myimage:latest | true

# docker build . --target=build --cache-from=myimage:latest-build -t myimage:latest-build
# docker build . --cache-from=myimage:latest-build --cache-from=myimage:latest -t myimage:latest

# docker push myimage:latest-build
# docker push myimage:latest


# use docker build from circleci and then push to gcloud run
# gcloud auth configure-docker
# docker tag dropapp europe-west1-docker.pkg.dev/dropapp-242214/cloudrun/dropapp
# docker push europe-west1-docker.pkg.dev/dropapp-242214/cloudrun/dropapp
# gcloud run deploy

# gcloud config set builds/use_kaniko True
# docker build -t dropapp . && docker run -e PORT=8080 -p 81:8080 dropapp
# use cloud build as (a) we only have 1gb free data transfer from circleci
# and (b) cloud build offers 120 mins free per day

# gcloud run deploy dropapp-test --source . --project dropapp-242214 --add-cloudsql-instances=dropapp-242214:europe-west1:boxtribute-production

# docker run -it dropapp sh
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ If you are interested in being part of this project, write us at [jointheteam@bo

docker-compose up

Alternatively, you can run using the PHP development server

GOOGLE_CLOUD_PROJECT=xxx php -S localhost:8000 gcloud-entry.php

5. To initialize the database for the first time, you should run:

vendor/bin/phinx migrate -e development
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
},
"require": {
"robmorgan/phinx": "^0.12",
"symfony/yaml": "^5.0",
"google/cloud-storage": "^1.12",
"opencensus/opencensus-exporter-stackdriver": "^0.1.0",
"smarty/smarty": "^4.3",
Expand Down
105 changes: 90 additions & 15 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 56857a1

Please sign in to comment.