├── .github
├── ISSUE_TEMPLATE.md
└── PULL_REQUEST_TEMPLATE.md
├── .gitignore
├── CONTRIBUTING.md
├── Dockerfile
├── LICENSE.md
├── README.md
├── compose-wordpress.yml
├── docker-compose-wordpress.yml
└── docker-entrypoint.sh
/.github/ISSUE_TEMPLATE.md:
--------------------------------------------------------------------------------
1 |
4 | > Please provide us with the following information:
5 | > ---------------------------------------------------------------
6 |
7 | ### This issue is for a: (mark with an `x`)
8 | ```
9 | - [ ] bug report -> please search issues before submitting
10 | - [ ] feature request
11 | - [ ] documentation issue or request
12 | - [ ] regression (a behavior that used to work and stopped in a new release)
13 | ```
14 |
15 | ### Minimal steps to reproduce
16 | >
17 |
18 | ### Any log messages given by the failure
19 | >
20 |
21 | ### Expected/desired behavior
22 | >
23 |
24 | ### OS and Version?
25 | > Windows 7, 8 or 10. Linux (which distribution). macOS (Yosemite? El Capitan? Sierra?)
26 |
27 | ### Versions
28 | >
29 |
30 | ### Mention any other details that might be useful
31 |
32 | > ---------------------------------------------------------------
33 | > Thanks! We'll be in touch soon.
34 |
--------------------------------------------------------------------------------
/.github/PULL_REQUEST_TEMPLATE.md:
--------------------------------------------------------------------------------
1 | ## Purpose
2 |
3 | * ...
4 |
5 | ## Does this introduce a breaking change?
6 |
7 | ```
8 | [ ] Yes
9 | [ ] No
10 | ```
11 |
12 | ## Pull Request Type
13 | What kind of change does this Pull Request introduce?
14 |
15 |
16 | ```
17 | [ ] Bugfix
18 | [ ] Feature
19 | [ ] Code style update (formatting, local variables)
20 | [ ] Refactoring (no functional changes, no api changes)
21 | [ ] Documentation content changes
22 | [ ] Other... Please describe:
23 | ```
24 |
25 | ## How to Test
26 | * Get the code
27 |
28 | ```
29 | git clone [repo-address]
30 | cd [repo-name]
31 | git checkout [branch-name]
32 | npm install
33 | ```
34 |
35 | * Test the code
36 |
37 | ```
38 | ```
39 |
40 | ## What to Check
41 | Verify that the following are valid
42 | * ...
43 |
44 | ## Other Information
45 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 | ##
4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
5 |
6 | # User-specific files
7 | *.suo
8 | *.user
9 | *.userosscache
10 | *.sln.docstates
11 |
12 | # User-specific files (MonoDevelop/Xamarin Studio)
13 | *.userprefs
14 |
15 | # Build results
16 | [Dd]ebug/
17 | [Dd]ebugPublic/
18 | [Rr]elease/
19 | [Rr]eleases/
20 | x64/
21 | x86/
22 | bld/
23 | [Bb]in/
24 | [Oo]bj/
25 | [Ll]og/
26 |
27 | # Visual Studio 2015/2017 cache/options directory
28 | .vs/
29 | # Uncomment if you have tasks that create the project's static files in wwwroot
30 | #wwwroot/
31 |
32 | # Visual Studio 2017 auto generated files
33 | Generated\ Files/
34 |
35 | # MSTest test Results
36 | [Tt]est[Rr]esult*/
37 | [Bb]uild[Ll]og.*
38 |
39 | # NUNIT
40 | *.VisualState.xml
41 | TestResult.xml
42 |
43 | # Build Results of an ATL Project
44 | [Dd]ebugPS/
45 | [Rr]eleasePS/
46 | dlldata.c
47 |
48 | # Benchmark Results
49 | BenchmarkDotNet.Artifacts/
50 |
51 | # .NET Core
52 | project.lock.json
53 | project.fragment.lock.json
54 | artifacts/
55 | **/Properties/launchSettings.json
56 |
57 | # StyleCop
58 | StyleCopReport.xml
59 |
60 | # Files built by Visual Studio
61 | *_i.c
62 | *_p.c
63 | *_i.h
64 | *.ilk
65 | *.meta
66 | *.obj
67 | *.iobj
68 | *.pch
69 | *.pdb
70 | *.ipdb
71 | *.pgc
72 | *.pgd
73 | *.rsp
74 | *.sbr
75 | *.tlb
76 | *.tli
77 | *.tlh
78 | *.tmp
79 | *.tmp_proj
80 | *.log
81 | *.vspscc
82 | *.vssscc
83 | .builds
84 | *.pidb
85 | *.svclog
86 | *.scc
87 |
88 | # Chutzpah Test files
89 | _Chutzpah*
90 |
91 | # Visual C++ cache files
92 | ipch/
93 | *.aps
94 | *.ncb
95 | *.opendb
96 | *.opensdf
97 | *.sdf
98 | *.cachefile
99 | *.VC.db
100 | *.VC.VC.opendb
101 |
102 | # Visual Studio profiler
103 | *.psess
104 | *.vsp
105 | *.vspx
106 | *.sap
107 |
108 | # Visual Studio Trace Files
109 | *.e2e
110 |
111 | # TFS 2012 Local Workspace
112 | $tf/
113 |
114 | # Guidance Automation Toolkit
115 | *.gpState
116 |
117 | # ReSharper is a .NET coding add-in
118 | _ReSharper*/
119 | *.[Rr]e[Ss]harper
120 | *.DotSettings.user
121 |
122 | # JustCode is a .NET coding add-in
123 | .JustCode
124 |
125 | # TeamCity is a build add-in
126 | _TeamCity*
127 |
128 | # DotCover is a Code Coverage Tool
129 | *.dotCover
130 |
131 | # AxoCover is a Code Coverage Tool
132 | .axoCover/*
133 | !.axoCover/settings.json
134 |
135 | # Visual Studio code coverage results
136 | *.coverage
137 | *.coveragexml
138 |
139 | # NCrunch
140 | _NCrunch_*
141 | .*crunch*.local.xml
142 | nCrunchTemp_*
143 |
144 | # MightyMoose
145 | *.mm.*
146 | AutoTest.Net/
147 |
148 | # Web workbench (sass)
149 | .sass-cache/
150 |
151 | # Installshield output folder
152 | [Ee]xpress/
153 |
154 | # DocProject is a documentation generator add-in
155 | DocProject/buildhelp/
156 | DocProject/Help/*.HxT
157 | DocProject/Help/*.HxC
158 | DocProject/Help/*.hhc
159 | DocProject/Help/*.hhk
160 | DocProject/Help/*.hhp
161 | DocProject/Help/Html2
162 | DocProject/Help/html
163 |
164 | # Click-Once directory
165 | publish/
166 |
167 | # Publish Web Output
168 | *.[Pp]ublish.xml
169 | *.azurePubxml
170 | # Note: Comment the next line if you want to checkin your web deploy settings,
171 | # but database connection strings (with potential passwords) will be unencrypted
172 | *.pubxml
173 | *.publishproj
174 |
175 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
176 | # checkin your Azure Web App publish settings, but sensitive information contained
177 | # in these scripts will be unencrypted
178 | PublishScripts/
179 |
180 | # NuGet Packages
181 | *.nupkg
182 | # The packages folder can be ignored because of Package Restore
183 | **/[Pp]ackages/*
184 | # except build/, which is used as an MSBuild target.
185 | !**/[Pp]ackages/build/
186 | # Uncomment if necessary however generally it will be regenerated when needed
187 | #!**/[Pp]ackages/repositories.config
188 | # NuGet v3's project.json files produces more ignorable files
189 | *.nuget.props
190 | *.nuget.targets
191 |
192 | # Microsoft Azure Build Output
193 | csx/
194 | *.build.csdef
195 |
196 | # Microsoft Azure Emulator
197 | ecf/
198 | rcf/
199 |
200 | # Windows Store app package directories and files
201 | AppPackages/
202 | BundleArtifacts/
203 | Package.StoreAssociation.xml
204 | _pkginfo.txt
205 | *.appx
206 |
207 | # Visual Studio cache files
208 | # files ending in .cache can be ignored
209 | *.[Cc]ache
210 | # but keep track of directories ending in .cache
211 | !*.[Cc]ache/
212 |
213 | # Others
214 | ClientBin/
215 | ~$*
216 | *~
217 | *.dbmdl
218 | *.dbproj.schemaview
219 | *.jfm
220 | *.pfx
221 | *.publishsettings
222 | orleans.codegen.cs
223 |
224 | # Including strong name files can present a security risk
225 | # (https://github.com/github/gitignore/pull/2483#issue-259490424)
226 | #*.snk
227 |
228 | # Since there are multiple workflows, uncomment next line to ignore bower_components
229 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
230 | #bower_components/
231 |
232 | # RIA/Silverlight projects
233 | Generated_Code/
234 |
235 | # Backup & report files from converting an old project file
236 | # to a newer Visual Studio version. Backup files are not needed,
237 | # because we have git ;-)
238 | _UpgradeReport_Files/
239 | Backup*/
240 | UpgradeLog*.XML
241 | UpgradeLog*.htm
242 | ServiceFabricBackup/
243 | *.rptproj.bak
244 |
245 | # SQL Server files
246 | *.mdf
247 | *.ldf
248 | *.ndf
249 |
250 | # Business Intelligence projects
251 | *.rdl.data
252 | *.bim.layout
253 | *.bim_*.settings
254 | *.rptproj.rsuser
255 |
256 | # Microsoft Fakes
257 | FakesAssemblies/
258 |
259 | # GhostDoc plugin setting file
260 | *.GhostDoc.xml
261 |
262 | # Node.js Tools for Visual Studio
263 | .ntvs_analysis.dat
264 | node_modules/
265 |
266 | # Visual Studio 6 build log
267 | *.plg
268 |
269 | # Visual Studio 6 workspace options file
270 | *.opt
271 |
272 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
273 | *.vbw
274 |
275 | # Visual Studio LightSwitch build output
276 | **/*.HTMLClient/GeneratedArtifacts
277 | **/*.DesktopClient/GeneratedArtifacts
278 | **/*.DesktopClient/ModelManifest.xml
279 | **/*.Server/GeneratedArtifacts
280 | **/*.Server/ModelManifest.xml
281 | _Pvt_Extensions
282 |
283 | # Paket dependency manager
284 | .paket/paket.exe
285 | paket-files/
286 |
287 | # FAKE - F# Make
288 | .fake/
289 |
290 | # JetBrains Rider
291 | .idea/
292 | *.sln.iml
293 |
294 | # CodeRush
295 | .cr/
296 |
297 | # Python Tools for Visual Studio (PTVS)
298 | __pycache__/
299 | *.pyc
300 |
301 | # Cake - Uncomment if you are using it
302 | # tools/**
303 | # !tools/packages.config
304 |
305 | # Tabs Studio
306 | *.tss
307 |
308 | # Telerik's JustMock configuration file
309 | *.jmconfig
310 |
311 | # BizTalk build output
312 | *.btp.cs
313 | *.btm.cs
314 | *.odx.cs
315 | *.xsd.cs
316 |
317 | # OpenCover UI analysis results
318 | OpenCover/
319 |
320 | # Azure Stream Analytics local run output
321 | ASALocalRun/
322 |
323 | # MSBuild Binary and Structured Log
324 | *.binlog
325 |
326 | # NVidia Nsight GPU debugger configuration file
327 | *.nvuser
328 |
329 | # MFractors (Xamarin productivity tool) working folder
330 | .mfractor/
331 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing to [project-title]
2 |
3 | This project welcomes contributions and suggestions. Most contributions require you to agree to a
4 | Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
5 | the rights to use your contribution. For details, visit https://cla.microsoft.com.
6 |
7 | When you submit a pull request, a CLA-bot will automatically determine whether you need to provide
8 | a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions
9 | provided by the bot. You will only need to do this once across all repos using our CLA.
10 |
11 | This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
12 | For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
13 | contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
14 |
15 | - [Code of Conduct](#coc)
16 | - [Issues and Bugs](#issue)
17 | - [Feature Requests](#feature)
18 | - [Submission Guidelines](#submit)
19 |
20 | ## Code of Conduct
21 | Help us keep this project open and inclusive. Please read and follow our [Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
22 |
23 | ## Found an Issue?
24 | If you find a bug in the source code or a mistake in the documentation, you can help us by
25 | [submitting an issue](#submit-issue) to the GitHub Repository. Even better, you can
26 | [submit a Pull Request](#submit-pr) with a fix.
27 |
28 | ## Want a Feature?
29 | You can *request* a new feature by [submitting an issue](#submit-issue) to the GitHub
30 | Repository. If you would like to *implement* a new feature, please submit an issue with
31 | a proposal for your work first, to be sure that we can use it.
32 |
33 | * **Small Features** can be crafted and directly [submitted as a Pull Request](#submit-pr).
34 |
35 | ## Submission Guidelines
36 |
37 | ### Submitting an Issue
38 | Before you submit an issue, search the archive, maybe your question was already answered.
39 |
40 | If your issue appears to be a bug, and hasn't been reported, open a new issue.
41 | Help us to maximize the effort we can spend fixing issues and adding new
42 | features, by not reporting duplicate issues. Providing the following information will increase the
43 | chances of your issue being dealt with quickly:
44 |
45 | * **Overview of the Issue** - if an error is being thrown a non-minified stack trace helps
46 | * **Version** - what version is affected (e.g. 0.1.2)
47 | * **Motivation for or Use Case** - explain what are you trying to do and why the current behavior is a bug for you
48 | * **Browsers and Operating System** - is this a problem with all browsers?
49 | * **Reproduce the Error** - provide a live example or a unambiguous set of steps
50 | * **Related Issues** - has a similar issue been reported before?
51 | * **Suggest a Fix** - if you can't fix the bug yourself, perhaps you can point to what might be
52 | causing the problem (line of code or commit)
53 |
54 | You can file new issues by providing the above information at the corresponding repository's issues link: https://github.com/[organization-name]/[repository-name]/issues/new].
55 |
56 | ### Submitting a Pull Request (PR)
57 | Before you submit your Pull Request (PR) consider the following guidelines:
58 |
59 | * Search the repository (https://github.com/[organization-name]/[repository-name]/pulls) for an open or closed PR
60 | that relates to your submission. You don't want to duplicate effort.
61 |
62 | * Make your changes in a new git fork:
63 |
64 | * Commit your changes using a descriptive commit message
65 | * Push your fork to GitHub:
66 | * In GitHub, create a pull request
67 | * If we suggest changes then:
68 | * Make the required updates.
69 | * Rebase your fork and force push to your GitHub repository (this will update your Pull Request):
70 |
71 | ```shell
72 | git rebase master -i
73 | git push -f
74 | ```
75 |
76 | That's it! Thank you for your contribution!
77 |
--------------------------------------------------------------------------------
/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM php:7.2-apache
2 |
3 | # install the PHP extensions we need
4 | RUN set -ex; \
5 | \
6 | savedAptMark="$(apt-mark showmanual)"; \
7 | \
8 | apt-get update; \
9 | apt-get install -y --no-install-recommends \
10 | libjpeg-dev \
11 | libpng-dev \
12 | ; \
13 | \
14 | docker-php-ext-configure gd --with-png-dir=/usr --with-jpeg-dir=/usr; \
15 | docker-php-ext-install gd mysqli opcache; \
16 | \
17 | # reset apt-mark's "manual" list so that "purge --auto-remove" will remove all build dependencies
18 | apt-mark auto '.*' > /dev/null; \
19 | apt-mark manual $savedAptMark; \
20 | ldd "$(php -r 'echo ini_get("extension_dir");')"/*.so \
21 | | awk '/=>/ { print $3 }' \
22 | | sort -u \
23 | | xargs -r dpkg-query -S \
24 | | cut -d: -f1 \
25 | | sort -u \
26 | | xargs -rt apt-mark manual; \
27 | \
28 | apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \
29 | rm -rf /var/lib/apt/lists/*
30 |
31 | #install redis php extension
32 | ENV PHPREDIS_VERSION=4.0.2
33 |
34 | RUN docker-php-source extract \
35 | && curl -L -o /tmp/redis.tar.gz https://github.com/phpredis/phpredis/archive/$PHPREDIS_VERSION.tar.gz \
36 | && tar xfz /tmp/redis.tar.gz \
37 | && rm -r /tmp/redis.tar.gz \
38 | && mv phpredis-$PHPREDIS_VERSION /usr/src/php/ext/redis \
39 | && docker-php-ext-install redis \
40 | && docker-php-source delete
41 |
42 | # set recommended PHP.ini settings
43 | # see https://secure.php.net/manual/en/opcache.installation.php
44 | RUN { \
45 | echo 'opcache.memory_consumption=128'; \
46 | echo 'opcache.interned_strings_buffer=8'; \
47 | echo 'opcache.max_accelerated_files=4000'; \
48 | echo 'opcache.revalidate_freq=2'; \
49 | echo 'opcache.fast_shutdown=1'; \
50 | echo 'opcache.enable_cli=1'; \
51 | } > /usr/local/etc/php/conf.d/opcache-recommended.ini
52 |
53 | RUN a2enmod rewrite expires
54 |
55 | VOLUME /var/www/html
56 |
57 | ENV WORDPRESS_VERSION 4.9.6
58 | ENV WORDPRESS_SHA1 6992f19163e21720b5693bed71ffe1ab17a4533a
59 |
60 | RUN set -ex; \
61 | curl -o wordpress.tar.gz -fSL "https://wordpress.org/wordpress-${WORDPRESS_VERSION}.tar.gz"; \
62 | echo "$WORDPRESS_SHA1 *wordpress.tar.gz" | sha1sum -c -; \
63 | # upstream tarballs include ./wordpress/ so this gives us /usr/src/wordpress
64 | tar -xzf wordpress.tar.gz -C /usr/src/; \
65 | rm wordpress.tar.gz; \
66 | chown -R www-data:www-data /usr/src/wordpress
67 |
68 | COPY docker-entrypoint.sh /usr/local/bin/
69 |
70 | ENTRYPOINT ["docker-entrypoint.sh"]
71 | CMD ["apache2-foreground"]
72 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) Microsoft Corporation. All rights reserved.
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ---
2 | page_type: sample
3 | languages:
4 | - yaml
5 | products:
6 | - azure
7 | description: "Multi-container using Docker Compose in Azure Web App for Containers."
8 | urlFragment: docker-compose-web-app-sample
9 | ---
10 |
11 | # Multi-container using Docker Compose in Azure Web App for Containers
12 | This custom image is based on the 'official image' of [WordPress from Docker Hub](https://hub.docker.com/_/wordpress/).
13 |
14 | The following changes have been made in this custom image:
15 | * [Explicitly uses WordPress 4.9.5, PHP 7.2 and Apache.]()
16 | * [Adds PHP extension for Redis v4.0.2.]()
17 | * [Adds Baltimore Cyber Trust Root Certificate file for SSL to MySQL.]()
18 | * [Uses App Setting for MySQL SSL Certificate Authority certificate in WordPress wp-config.php.]()
19 | * [Uses App Setting for Redis host name in WordPress wp-config.php.]()
20 | * [Uses Redis Object Cache 1.3.8 WordPress plugin.]()
21 |
22 | ## Setting up multi-container configuration for Web App for Containers
23 | Follow the [tutorial](https://docs.microsoft.com/en-us/azure/app-service/containers/tutorial-multi-container-app) here.
24 |
25 | ## Contributing
26 | This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.
27 |
28 | When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.
29 |
30 | This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.
31 |
--------------------------------------------------------------------------------
/compose-wordpress.yml:
--------------------------------------------------------------------------------
1 | version: '3.3'
2 |
3 | services:
4 | wordpress:
5 | image: mcr.microsoft.com/azuredocs/multicontainerwordpress
6 | ports:
7 | - "8000:80"
8 | restart: always
9 |
10 | redis:
11 | image: mcr.microsoft.com/oss/bitnami/redis:6.0.8
12 | environment:
13 | - ALLOW_EMPTY_PASSWORD=yes
14 | restart: always
15 |
--------------------------------------------------------------------------------
/docker-compose-wordpress.yml:
--------------------------------------------------------------------------------
1 | version: '3.3'
2 |
3 | services:
4 | db:
5 | image: mysql:5.7
6 | volumes:
7 | - db_data:/var/lib/mysql
8 | restart: always
9 | environment:
10 | MYSQL_ROOT_PASSWORD: somewordpress
11 | MYSQL_DATABASE: wordpress
12 | MYSQL_USER: wordpress
13 | MYSQL_PASSWORD: wordpress
14 |
15 | wordpress:
16 | depends_on:
17 | - db
18 | image: wordpress:latest
19 | ports:
20 | - "8000:80"
21 | restart: always
22 | environment:
23 | WORDPRESS_DB_HOST: db:3306
24 | WORDPRESS_DB_USER: wordpress
25 | WORDPRESS_DB_PASSWORD: wordpress
26 | volumes:
27 | db_data:
28 |
--------------------------------------------------------------------------------
/docker-entrypoint.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | set -euo pipefail
3 |
4 | # usage: file_env VAR [DEFAULT]
5 | # ie: file_env 'XYZ_DB_PASSWORD' 'example'
6 | # (will allow for "$XYZ_DB_PASSWORD_FILE" to fill in the value of
7 | # "$XYZ_DB_PASSWORD" from a file, especially for Docker's secrets feature)
8 | file_env() {
9 | local var="$1"
10 | local fileVar="${var}_FILE"
11 | local def="${2:-}"
12 | if [ "${!var:-}" ] && [ "${!fileVar:-}" ]; then
13 | echo >&2 "error: both $var and $fileVar are set (but are exclusive)"
14 | exit 1
15 | fi
16 | local val="$def"
17 | if [ "${!var:-}" ]; then
18 | val="${!var}"
19 | elif [ "${!fileVar:-}" ]; then
20 | val="$(< "${!fileVar}")"
21 | fi
22 | export "$var"="$val"
23 | unset "$fileVar"
24 | }
25 |
26 | if [[ "$1" == apache2* ]] || [ "$1" == php-fpm ]; then
27 | if [ "$(id -u)" = '0' ]; then
28 | case "$1" in
29 | apache2*)
30 | user="${APACHE_RUN_USER:-www-data}"
31 | group="${APACHE_RUN_GROUP:-www-data}"
32 | ;;
33 | *) # php-fpm
34 | user='www-data'
35 | group='www-data'
36 | ;;
37 | esac
38 | else
39 | user="$(id -u)"
40 | group="$(id -g)"
41 | fi
42 |
43 | if ! [ -e index.php -a -e wp-includes/version.php ]; then
44 | echo >&2 "WordPress not found in $PWD - copying now..."
45 | if [ "$(ls -A)" ]; then
46 | echo >&2 "WARNING: $PWD is not empty - press Ctrl+C now if this is an error!"
47 | ( set -x; ls -A; sleep 10 )
48 | fi
49 | tar --create \
50 | --file - \
51 | --one-file-system \
52 | --directory /usr/src/wordpress \
53 | --owner "$user" --group "$group" \
54 | . | tar --extract --file -
55 | echo >&2 "Complete! WordPress has been successfully copied to $PWD"
56 |
57 |
58 | # Install BaltimoreCyberTrustRoot.crt.pem
59 | if [ ! -e BaltimoreCyberTrustRoot.crt.pem ]; then
60 | echo "Downloading BaltimoreCyberTrustroot.crt.pem"
61 | curl -o BaltimoreCyberTrustRoot.crt.pem -fsL "https://www.digicert.com/CACerts/BaltimoreCyberTrustRoot.crt.pem"
62 | fi
63 |
64 | # Install Redis Cache WordPress Plugin
65 | if [ ! -e wp-content/plugins/redis-cache ]; then
66 |
67 | # Update package repos
68 | apt-get update
69 |
70 | # Install unzip
71 | apt-get install unzip
72 |
73 | echo "Downloading https://downloads.wordpress.org/plugin/redis-cache.1.3.8.zip"
74 | curl -o redis-cache.1.3.8.zip -fsL "https://downloads.wordpress.org/plugin/redis-cache.1.3.8.zip"
75 |
76 | echo "Unzipping redis-cache.1.3.8.zip to /var/www/html/wp-content/plugins/"
77 | unzip -q redis-cache.1.3.8.zip -d /var/www/html/wp-content/plugins/
78 |
79 | echo "Removing redis-cache.1.3.8.zip"
80 | rm redis-cache.1.3.8.zip
81 | fi
82 |
83 | chown -R "$user:$group" /var/www/html
84 |
85 | if [ ! -e .htaccess ]; then
86 | # NOTE: The "Indexes" option is disabled in the php:apache base image
87 | cat > .htaccess <<-'EOF'
88 | # BEGIN WordPress
89 |
90 | RewriteEngine On
91 | RewriteBase /
92 | RewriteRule ^index\.php$ - [L]
93 | RewriteCond %{REQUEST_FILENAME} !-f
94 | RewriteCond %{REQUEST_FILENAME} !-d
95 | RewriteRule . /index.php [L]
96 |
97 | # END WordPress
98 | EOF
99 | chown "$user:$group" .htaccess
100 | fi
101 | fi
102 |
103 | # TODO handle WordPress upgrades magically in the same way, but only if wp-includes/version.php's $wp_version is less than /usr/src/wordpress/wp-includes/version.php's $wp_version
104 |
105 | # allow any of these "Authentication Unique Keys and Salts." to be specified via
106 | # environment variables with a "WORDPRESS_" prefix (ie, "WORDPRESS_AUTH_KEY")
107 | uniqueEnvs=(
108 | AUTH_KEY
109 | SECURE_AUTH_KEY
110 | LOGGED_IN_KEY
111 | NONCE_KEY
112 | AUTH_SALT
113 | SECURE_AUTH_SALT
114 | LOGGED_IN_SALT
115 | NONCE_SALT
116 | )
117 | envs=(
118 | WORDPRESS_DB_HOST
119 | WORDPRESS_DB_USER
120 | WORDPRESS_DB_PASSWORD
121 | WORDPRESS_DB_NAME
122 | "${uniqueEnvs[@]/#/WORDPRESS_}"
123 | WORDPRESS_TABLE_PREFIX
124 | WORDPRESS_DEBUG
125 | )
126 | haveConfig=
127 | for e in "${envs[@]}"; do
128 | file_env "$e"
129 | if [ -z "$haveConfig" ] && [ -n "${!e}" ]; then
130 | haveConfig=1
131 | fi
132 | done
133 |
134 | # linking backwards-compatibility
135 | if [ -n "${!MYSQL_ENV_MYSQL_*}" ]; then
136 | haveConfig=1
137 | # host defaults to "mysql" below if unspecified
138 | : "${WORDPRESS_DB_USER:=${MYSQL_ENV_MYSQL_USER:-root}}"
139 | if [ "$WORDPRESS_DB_USER" = 'root' ]; then
140 | : "${WORDPRESS_DB_PASSWORD:=${MYSQL_ENV_MYSQL_ROOT_PASSWORD:-}}"
141 | else
142 | : "${WORDPRESS_DB_PASSWORD:=${MYSQL_ENV_MYSQL_PASSWORD:-}}"
143 | fi
144 | : "${WORDPRESS_DB_NAME:=${MYSQL_ENV_MYSQL_DATABASE:-}}"
145 | fi
146 |
147 | # only touch "wp-config.php" if we have environment-supplied configuration values
148 | if [ "$haveConfig" ]; then
149 | : "${WORDPRESS_DB_HOST:=mysql}"
150 | : "${WORDPRESS_DB_USER:=root}"
151 | : "${WORDPRESS_DB_PASSWORD:=}"
152 | : "${WORDPRESS_DB_NAME:=wordpress}"
153 |
154 | # version 4.4.1 decided to switch to windows line endings, that breaks our seds and awks
155 | # https://github.com/docker-library/wordpress/issues/116
156 | # https://github.com/WordPress/WordPress/commit/1acedc542fba2482bab88ec70d4bea4b997a92e4
157 | sed -ri -e 's/\r$//' wp-config*
158 |
159 | if [ ! -e wp-config.php ]; then
160 | awk '/^\/\*.*stop editing.*\*\/$/ && c == 0 { c = 1; system("cat") } { print }' wp-config-sample.php > wp-config.php <<'EOPHP'
161 |
162 | define('WP_REDIS_HOST', getenv('WP_REDIS_HOST'));
163 | define('MYSQL_SSL_CA', getenv('MYSQL_SSL_CA'));
164 | define('MYSQL_CLIENT_FLAGS', MYSQLI_CLIENT_SSL | MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT);
165 |
166 | // If we're behind a proxy server and using HTTPS, we need to alert Wordpress of that fact
167 | // see also http://codex.wordpress.org/Administration_Over_SSL#Using_a_Reverse_Proxy
168 | if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') {
169 | $_SERVER['HTTPS'] = 'on';
170 | }
171 |
172 | EOPHP
173 | chown "$user:$group" wp-config.php
174 | fi
175 |
176 | # see http://stackoverflow.com/a/2705678/433558
177 | sed_escape_lhs() {
178 | echo "$@" | sed -e 's/[]\/$*.^|[]/\\&/g'
179 | }
180 | sed_escape_rhs() {
181 | echo "$@" | sed -e 's/[\/&]/\\&/g'
182 | }
183 | php_escape() {
184 | local escaped="$(php -r 'var_export(('"$2"') $argv[1]);' -- "$1")"
185 | if [ "$2" = 'string' ] && [ "${escaped:0:1}" = "'" ]; then
186 | escaped="${escaped//$'\n'/"' + \"\\n\" + '"}"
187 | fi
188 | echo "$escaped"
189 | }
190 | set_config() {
191 | key="$1"
192 | value="$2"
193 | var_type="${3:-string}"
194 | start="(['\"])$(sed_escape_lhs "$key")\2\s*,"
195 | end="\);"
196 | if [ "${key:0:1}" = '$' ]; then
197 | start="^(\s*)$(sed_escape_lhs "$key")\s*="
198 | end=";"
199 | fi
200 | sed -ri -e "s/($start\s*).*($end)$/\1$(sed_escape_rhs "$(php_escape "$value" "$var_type")")\3/" wp-config.php
201 | }
202 |
203 | set_config 'DB_HOST' "$WORDPRESS_DB_HOST"
204 | set_config 'DB_USER' "$WORDPRESS_DB_USER"
205 | set_config 'DB_PASSWORD' "$WORDPRESS_DB_PASSWORD"
206 | set_config 'DB_NAME' "$WORDPRESS_DB_NAME"
207 |
208 | for unique in "${uniqueEnvs[@]}"; do
209 | uniqVar="WORDPRESS_$unique"
210 | if [ -n "${!uniqVar}" ]; then
211 | set_config "$unique" "${!uniqVar}"
212 | else
213 | # if not specified, let's generate a random value
214 | currentVal="$(sed -rn -e "s/define\((([\'\"])$unique\2\s*,\s*)(['\"])(.*)\3\);/\4/p" wp-config.php)"
215 | if [ "$currentVal" = 'put your unique phrase here' ]; then
216 | set_config "$unique" "$(head -c1m /dev/urandom | sha1sum | cut -d' ' -f1)"
217 | fi
218 | fi
219 | done
220 |
221 | if [ "$WORDPRESS_TABLE_PREFIX" ]; then
222 | set_config '$table_prefix' "$WORDPRESS_TABLE_PREFIX"
223 | fi
224 |
225 | if [ "$WORDPRESS_DEBUG" ]; then
226 | set_config 'WP_DEBUG' 1 boolean
227 | fi
228 |
229 | fi
230 |
231 | # now that we're definitely done writing configuration, let's clear out the relevant envrionment variables (so that stray "phpinfo()" calls don't leak secrets from our code)
232 | for e in "${envs[@]}"; do
233 | unset "$e"
234 | done
235 | fi
236 |
237 | exec "$@"
--------------------------------------------------------------------------------