Skip to content

Commit 56857a1

Browse files
committed
WIP docker configuration
1 parent 503b85a commit 56857a1

17 files changed

Lines changed: 214 additions & 81 deletions

.circleci/config.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,11 @@ jobs:
118118
# deploy
119119
gcloud app deploy app-<< parameters.serviceName >>.yaml --version ${CIRCLE_BUILD_NUM}
120120
gcloud app deploy cron.yaml dispatch.yaml --version ${CIRCLE_BUILD_NUM}
121-
121+
- run: |
122+
# deploy to google run too
123+
gcloud run deploy dropapp-test --source . --project ${GOOGLE_PROJECT_ID} \
124+
--add-cloudsql-instances=${<< parameters.envVariablePrefix >>DBNAME} \
125+
--set-env-vars GOOGLE_CLOUD_PROJECT=${GOOGLE_PROJECT_ID}
122126
create-sentry-release:
123127
docker:
124128
- image: circleci/node:4.8.2

.docker/.gitkeep

Whitespace-only changes.

.docker/php/Dockerfile

Lines changed: 0 additions & 12 deletions
This file was deleted.

.docker/php/dropapp.conf

Lines changed: 0 additions & 25 deletions
This file was deleted.

.gcloudignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,4 @@
1818
# other folders to ignore
1919
.docker
2020
phinx.yml
21-
docker-compose.yml
22-
build.php
21+
docker-compose.yml

.vscode/extensions.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"recommendations": [
77
"xdebug.php-debug",
88
"bmewburn.vscode-intelephense-client",
9-
"fterrag.vscode-php-cs-fixer"
9+
"junstyle.php-cs-fixer"
1010
],
1111
// List of extensions recommended by VS Code that should not be recommended for users of this workspace.
1212
"unwantedRecommendations": [

.vscode/launch.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
55
"version": "0.2.0",
66
"configurations": [
7-
87
{
98
"name": "Listen for XDebug",
109
"type": "php",
1110
"request": "launch",
1211
"port": 9003,
1312
"pathMappings": {
14-
"/var/www/html": "${workspaceFolder}"},
13+
"/var/www/html": "${workspaceFolder}"
14+
},
1515
"log": true
1616
},
1717
{

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"[php]": {
33
"editor.formatOnSave": true,
4-
"editor.defaultFormatter": "fterrag.vscode-php-cs-fixer"
4+
"editor.defaultFormatter": "junstyle.php-cs-fixer"
55
},
66
"php-cs-fixer.rules": "@PhpCsFixer",
77
"intelephense.format.enable": false

Dockerfile

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
FROM php:7.4.25-apache AS base
2+
WORKDIR /var/www/html
3+
4+
# install needed libraries
5+
RUN apt-get update \
6+
&& apt-get -y --no-install-recommends install libfontconfig1 libxrender1 libxext6 zlib1g-dev libpng-dev libfreetype6-dev libjpeg62-turbo-dev \
7+
&& apt-get clean \
8+
&& rm -rf /var/lib/apt/lists/*
9+
10+
RUN a2enmod rewrite
11+
12+
RUN docker-php-ext-install \
13+
gd \
14+
pdo_mysql \
15+
exif
16+
17+
# op cache
18+
RUN docker-php-ext-install -j "$(nproc)" opcache
19+
20+
RUN set -ex; \
21+
{ \
22+
echo "; Cloud Run enforces memory & timeouts"; \
23+
echo "memory_limit = -1"; \
24+
echo "max_execution_time = 0"; \
25+
echo "; File upload at Cloud Run network limit"; \
26+
echo "upload_max_filesize = 32M"; \
27+
echo "post_max_size = 32M"; \
28+
echo "; Configure Opcache for Containers"; \
29+
echo "opcache.enable = On"; \
30+
echo "opcache.validate_timestamps = Off"; \
31+
echo "; Configure Opcache Memory (Application-specific)"; \
32+
echo "opcache.memory_consumption = 32"; \
33+
} > "$PHP_INI_DIR/conf.d/cloud-run.ini"
34+
35+
RUN pecl install opencensus-alpha
36+
37+
# Use the PORT environment variable in Apache configuration files.
38+
# https://cloud.google.com/run/docs/reference/container-contract#port
39+
RUN sed -i 's/80/${PORT}/g' /etc/apache2/sites-available/000-default.conf /etc/apache2/ports.conf
40+
41+
FROM base AS debug
42+
43+
# RUN enable-xdebug in PHP 8 env
44+
RUN pecl install xdebug && docker-php-ext-enable xdebug
45+
# Configure PHP for development.
46+
# https://github.com/docker-library/docs/blob/master/php/README.md#configuration
47+
RUN mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini"
48+
49+
FROM composer:2.1.11 AS build
50+
51+
WORKDIR /var/www/html
52+
# ensures we use docker cache and only rebuild composer
53+
# if the dependencies have changed
54+
COPY composer.json .
55+
COPY composer.lock .
56+
RUN composer install --no-dev --no-scripts --ignore-platform-reqs
57+
COPY . .
58+
RUN composer dump-autoload --optimize
59+
RUN ls
60+
RUN php build/build.php
61+
RUN rm -r build/
62+
63+
FROM base AS final
64+
65+
# Configure PHP for production.
66+
# https://github.com/docker-library/docs/blob/master/php/README.md#configuration
67+
RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"
68+
69+
COPY --from=build /var/www/html /var/www/html
70+
71+
72+
73+
# docker pull myimage:latest-build | true
74+
# docker pull myimage:latest | true
75+
76+
# docker build . --target=build --cache-from=myimage:latest-build -t myimage:latest-build
77+
# docker build . --cache-from=myimage:latest-build --cache-from=myimage:latest -t myimage:latest
78+
79+
# docker push myimage:latest-build
80+
# docker push myimage:latest
81+
82+
83+
# use docker build from circleci and then push to gcloud run
84+
# gcloud auth configure-docker
85+
# docker tag dropapp europe-west1-docker.pkg.dev/dropapp-242214/cloudrun/dropapp
86+
# docker push europe-west1-docker.pkg.dev/dropapp-242214/cloudrun/dropapp
87+
# gcloud run deploy
88+
89+
# gcloud config set builds/use_kaniko True
90+
# docker build -t dropapp . && docker run -e PORT=8080 -p 81:8080 dropapp
91+
# use cloud build as (a) we only have 1gb free data transfer from circleci
92+
# and (b) cloud build offers 120 mins free per day
93+
94+
# gcloud run deploy dropapp-test --source . --project dropapp-242214 --add-cloudsql-instances=dropapp-242214:europe-west1:boxtribute-production
95+
96+
# docker run -it dropapp sh

README.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,6 @@ If you are interested in being part of this project, write us at [jointheteam@bo
4242

4343
docker-compose up
4444

45-
Alternatively, you can run using the PHP development server
46-
47-
GOOGLE_CLOUD_PROJECT=xxx php -S localhost:8000 gcloud-entry.php
48-
4945
5. To initialize the database for the first time, you should run:
5046

5147
vendor/bin/phinx migrate -e development

0 commit comments

Comments
 (0)