Skip to content

Commit 9ba00c9

Browse files
committed
Merge branch 'update/protocol-build' into develop
2 parents 1b34c06 + 61c76d2 commit 9ba00c9

13 files changed

+188
-113
lines changed

.env-example

+17-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,24 @@
11
# Target build/use environment
22
APP_ENV=local
3-
BUILD_IMAGE=php-5.6-apache
4-
BUILD_IMAGE_TAG=v0.0.3
3+
# set the PHP version for descriptions & such
4+
PHP_VERSION=5.6
5+
6+
# Docker build & compose details
7+
DOCKER_COMPOSE_BUILD_FILE=docker-compose-build.yaml
8+
DOCKER_COMPOSE_FILE=docker-compose.yaml
9+
DOCKER_BUILD_FILE=php-5-6-apache.Dockerfile
10+
DOCKER_BUILD_REPO=docker_user/docker_repo
11+
APACHE_PHP56_DOCKER_BUILD_DESC="PHP ${PHP_VERSION} & Apache Web Server"
12+
APACHE_PHP56_DOCKER_BUILD_TARGET=build-php-56-apache
13+
APACHE_PHP56_DOCKER_BUILD_IMAGE=php-5.6-apache
14+
APACHE_PHP56_DOCKER_BUILD_IMAGE_TAG=v0.0.1
15+
16+
# Docker compose image details
17+
APACHE_PHP56_DOCKER_IMAGE="${APACHE_PHP56_DOCKER_BUILD_IMAGE}"
18+
APACHE_PHP56_DOCKER_IMAGE_TAG="${APACHE_PHP56_DOCKER_BUILD_IMAGE_TAG}"
519

620
# Making the npm versions changeable
7-
NPM_VERSION=6.4.1
21+
NPM_VERSION="6.4.1"
822

923
# App webserver ports
1024
APP_PORT=8080

README.md

+49-42
Original file line numberDiff line numberDiff line change
@@ -28,44 +28,71 @@ PHP Extensions:
2828
- zip
2929
- yaml
3030

31-
## Build Image
31+
## Build & Compose Up
3232

33-
Build the ***Docker Image*** without using ***cached*** versions of previous image build stages.
34-
35-
### Helper Script
33+
Note that the `php-5-6-apache` is the Docker Compose Service to ***Build***.
3634

37-
A helper script is available with the repo to force recreate the build & use the `docker-compose.yaml` file which reads the `.env` file.
35+
There is a build script included that uses the local `.env` file & an [Evil Wizard Creations Protocol](https://bitbucket.org/evilwizardcreations/ewc-protocols) that makes this much simpler.
3836

3937
```bash
40-
./build-web.sh
38+
build-up-php-7.2-fpm.sh
4139
```
4240

43-
### The long Way
41+
Alternatively there is the *full Procedure*.
42+
43+
1. Build the Image using the `docker-compose-build.yaml` configuration.
44+
45+
```bash
46+
docker-compose -f ./docker-compose-build.yaml build --no-cache php-5-6-apache
47+
```
48+
49+
1. Compose *Up* using the `docker-compose-build.yaml` configuration will use the new built Image and `-d` to *detach*.
50+
51+
```bash
52+
docker-compose -f ./docker-compose-build.yaml up -d
53+
```
54+
55+
## Build Image The Long Way
56+
57+
Build the ***Docker Image*** without using ***cached*** versions of previous image build stages.
58+
4459

4560
```bash
4661
sudo docker build \
4762
-f php-5-6-apache.Dockerfile \
48-
--target php-5-6-build \
63+
--target build-php-56-apache \
4964
--build-arg APP_ENV=local \
5065
--build-arg NPM_VERSION=6.4.1 \
5166
--no-cache \
52-
-t php-5-6-web-server:latest \
67+
-t php-5-6-apache:latest \
5368
.
5469
```
5570

5671
**N.B.**
5772

5873
- Using `-f php-5-6-apache.Dockerfile`
5974

60-
To specify the *filename* to ***build*** otherwise it is expected to be named `Dockerfile`.
75+
To specify `php-5-6-apache.Dockerfile` as the *filename* to ***build*** otherwise it is expected to be named just `Dockerfile`.
6176

62-
- Using `--target php-5-6-build`
77+
- Using `--target build-php-56-apache`
6378

6479
To select the ***build target stage***[^multi_stage_builds_note] from the *Dockerfile*.
80+
81+
- Using `--no-cache`
82+
83+
To prevent using previous ***cached*** versions of image build stages.
6584

66-
- Using `--build-arg ARG=value`
85+
- Using `--build-arg NPM_VERSION=6.4.1`
86+
87+
To set build ***arguments*** & ***values*** to use during the build process. `NPM_VERSION=6.4.1` sets the ***Node Version*** to be used to ***6.4.1*** when rebuilding the image.
88+
89+
- Using `-t php-5-6-apache:latest`
6790

68-
To set build argument values to use.
91+
To ***name*** & ***tag*** the locally built docker image.
92+
93+
- Using `.`
94+
95+
To set the current location as the ***build context*** for the build process.
6996

7097
### Create A Container
7198

@@ -76,8 +103,8 @@ sudo docker run \
76103
-d \
77104
--network host \
78105
-v "$(pwd)"/public_html:/var/www/html \
79-
--name php-5-6-web-server \
80-
php-5-6-web-server:latest
106+
--name php-5-6-apache \
107+
php-5-6-apache:latest
81108
```
82109

83110
**OR**
@@ -90,8 +117,8 @@ sudo docker run \
90117
--network bridge \
91118
-p 8080:80/tcp \
92119
-v "$(pwd)"/public_html:/var/www/html \
93-
--name php-5-6-web-server \
94-
php-5-6-web-server:latest
120+
--name php-5-6-apache \
121+
php-5-6-apache:latest
95122
```
96123

97124
**N.B.**
@@ -104,46 +131,26 @@ sudo docker run \
104131

105132
To map port **8080** on the ***Host*** machine to port **80** on the ***Container*** using the ***bridge network***.
106133

107-
- Using `--name php-5-6-web-server`
134+
- Using `--name php-5-6-apache`
108135

109136
To name the ***Container*** being created.
110137

111138
### Start Container
112139

113140
```bash
114-
sudo docker start php-5-6-web-server
141+
sudo docker start php-5-6-apache
115142
```
116143

117144
### Stop Container
118145

119146
```bash
120-
sudo docker stop php-5-6-web-server
121-
```
122-
123-
## Docker Compose
124-
125-
A `docker-compose` configuration file is included to simplify the build & deployment of the image.
126-
127-
### Build - No Cache
128-
129-
This is only necessary when completely rebuilding the image to make sure all parts are rebuilt[^compose_name_note].
130-
131-
```bash
132-
sudo docker-compose build --no-cache php-5-6-web-server
133-
```
134-
135-
### Build & Up
136-
137-
This will try to use a local version or rebuild the image with current context.
138-
139-
```bash
140-
sudo docker-compose up --build -d
147+
sudo docker stop php-5-6-apache
141148
```
142149

143150
## Connect To Container
144151

145152
```bash
146-
sudo docker exec -it php-5-6-web-server /bin/bash
153+
sudo docker exec -it php-5-6-apache /bin/bash
147154
```
148155

149156
# Disclaimer
@@ -156,4 +163,4 @@ This Apache2 + PHP 5.6 build environment should ***NOT*** be used anywhere near
156163
157164
[^multi_stage_builds_note]: Used mostly in ***Multi Stage*** image builds.
158165
159-
[^compose_name_note]: The `php-5-6-web-server` container name to build the image for.
166+
[^compose_name_note]: The `php-5-6-apache` container name to build the image for.

build-assets/etc/apt/sources.list

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
deb http://archive.debian.org/debian stretch main

build-assets/pecl/yaml-1.3.0.tgz

36.2 KB
Binary file not shown.

build-up-php-5-6-apache.sh

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
# USAGE:
3+
# build-up-php-5-6-apache.sh
4+
#
5+
# NOTE:
6+
# Rebuild the Docker image & compose up.
7+
8+
# source the environment variables
9+
set -o allexport; source "${PWD}/.env"; set +o allexport
10+
11+
# Use the EWC Protocol to build the image of the service & compose up
12+
ewc-docker-build-up.sh "php-5-6-apache" "${APACHE_PHP56_DOCKER_BUILD_DESC:-PHP ${PHP_VERSION} & Apache Web Server}"

build-web.sh

-15
This file was deleted.

docker-compose-build.yaml

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
version: '3.7'
2+
3+
# Services/Containers to orchestrate in this composition
4+
services:
5+
6+
# Basic PHP 5.6 & Apache2 Image Container
7+
php-5-6-apache:
8+
container_name: php-5-6-apache
9+
tty: true
10+
restart: unless-stopped
11+
build:
12+
context: .
13+
target: ${APACHE_PHP56_DOCKER_BUILD_TARGET}
14+
dockerfile: ${DOCKER_BUILD_FILE}
15+
args:
16+
- NPM_VERSION=${NPM_VERSION}
17+
- APP_ENV=${APP_ENV}
18+
labels:
19+
ewc.name: "Web Server"
20+
ewc.description: "${APACHE_PHP56_DOCKER_BUILD_DESC}"
21+
ewc.php.version: "${PHP_VERSION}"
22+
image: ${APACHE_PHP56_DOCKER_IMAGE}:${APACHE_PHP56_DOCKER_IMAGE_TAG}
23+
environment:
24+
- NPM_VERSION=${NPM_VERSION}
25+
- APP_ENV=${APP_ENV}
26+
working_dir: /var/www
27+
ports:
28+
- ${APP_PORT}:80
29+
- ${APP_SSL_PORT}:443
30+
volumes:
31+
- ./public_html:/var/www/html
32+
- ./docker-files/php/56.local.ini:/usr/local/etc/php.ini
33+
networks:
34+
- web-app-network
35+
36+
# Custom network for composed containers to communicate on
37+
networks:
38+
web-app-network:
39+
driver: bridge
40+

docker-compose.yaml

+6-17
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,11 @@ version: '3.7'
44
services:
55

66
# Basic PHP 5.6 & Apache2 Image Container
7-
php-5-6-web-server:
8-
container_name: php-5-6-web-server
7+
php-5-6-apache:
8+
container_name: php-5-6-apache
99
tty: true
1010
restart: unless-stopped
11-
build:
12-
context: .
13-
target: php-5-6-build
14-
dockerfile: php-5-6-apache.Dockerfile
15-
args:
16-
- NPM_VERSION=${NPM_VERSION}
17-
- APP_ENV=${APP_ENV}
18-
labels:
19-
ewc.name: "Web Server"
20-
ewc.description: "PHP & Apache Web Server"
21-
ewc.php.version: "5.6"
22-
image: $BUILD_IMAGE:$BUILD_IMAGE_TAG
11+
image: ${APACHE_PHP56_DOCKER_IMAGE}:${APACHE_PHP56_DOCKER_IMAGE_TAG}
2312
environment:
2413
- NPM_VERSION=${NPM_VERSION}
2514
- APP_ENV=${APP_ENV}
@@ -29,12 +18,12 @@ services:
2918
- ${APP_SSL_PORT}:443
3019
volumes:
3120
- ./public_html:/var/www/html
32-
- ./docker-files/php/local.ini:/usr/local/etc/php.ini
21+
- ./docker-files/php/56.local.ini:/usr/local/etc/php.ini
3322
networks:
34-
- webapp_network
23+
- web-app-network
3524

3625
# Custom network for composed containers to communicate on
3726
networks:
38-
webapp_network:
27+
web-app-network:
3928
driver: bridge
4029

File renamed without changes.

env-prep.sh

-15
This file was deleted.

php-5-6-apache.Dockerfile

+59-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM php:5.6-apache as php-5-6-build
1+
FROM php:5.6-apache as build-php-56-apache
22

33
# Set some image labels
44
LABEL evilwizardcreations.image.authors="[email protected]" \
@@ -10,6 +10,12 @@ ENV NPM_VERSION=$NPM_VERSION
1010
# copy the specific Composer PHAR version from the Composer image into the PHP image
1111
COPY --from=composer:1.7.1 /usr/bin/composer /usr/bin/composer
1212

13+
# The apt-get sources for this are so old it has been archived & needs chainging
14+
COPY ./build-assets/etc/apt/sources.list /etc/apt/sources.list
15+
16+
# The pecl is so old it needs the local offline install now
17+
COPY ./build-assets/pecl/yaml-1.3.0.tgz /tmp/yaml-1.3.0.tgz
18+
1319
# Download the nodejs setup & set that it's a docker env.
1420
ENV NODE_ENV docker
1521
# Node -v v8.12.0
@@ -38,5 +44,56 @@ RUN set -ex; \
3844

3945
# Install some php extensions from the docker built source.
4046
RUN docker-php-ext-install gettext mysqli pdo_mysql zip
41-
RUN pecl install yaml-1.3.0 && \
47+
RUN pecl channel-update pecl.php.net && \
48+
pecl install --offline /tmp/yaml-1.3.0.tgz && \
49+
docker-php-ext-enable yaml && \
50+
rm /tmp/yaml-1.3.0.tgz
51+
52+
# A test build to play with while getting it all working
53+
FROM php:5.6-apache as build-php-56-apache-test
54+
55+
# Set some image labels
56+
LABEL evilwizardcreations.image.authors="[email protected]" \
57+
evilwizardcreations.image.php.version="5.6"
58+
59+
ARG NPM_VERSION=6.4.1
60+
ENV NPM_VERSION=$NPM_VERSION
61+
62+
# copy the specific Composer PHAR version from the Composer image into the PHP image
63+
COPY --from=composer:1.7.1 /usr/bin/composer /usr/bin/composer
64+
65+
# The apt-get sources for this are so old it has been archived & needs chainging
66+
COPY ./build-assets/etc/apt/sources.list /etc/apt/sources.list
67+
68+
# The pecl is so old it needs the local offline install now
69+
COPY ./build-assets/pecl/yaml-1.3.0.tgz /tmp/yaml-1.3.0.tgz
70+
71+
# Download the nodejs setup & set that it's a docker env.
72+
ENV NODE_ENV docker
73+
# Node -v v8.12.0
74+
#RUN curl --silent --location https://deb.nodesource.com/setup_8.x | bash
75+
76+
# Enable some apache modules.
77+
RUN a2enmod rewrite; \
78+
a2enmod headers; \
79+
a2enmod ssl
80+
81+
RUN set -ex; \
82+
apt-get update; \
83+
apt-get install -y --no-install-recommends \
84+
libxml2-dev \
85+
libzip-dev \
86+
libyaml-dev \
87+
zip \
88+
unzip \
89+
git \
90+
nodejs \
91+
default-mysql-client \
92+
vim; \
93+
apt-get clean
94+
95+
# Install some php extensions from the docker built source.
96+
RUN docker-php-ext-install gettext mysqli pdo_mysql zip
97+
RUN pecl channel-update pecl.php.net && \
98+
pecl install --offline /tmp/yaml-1.3.0.tgz && \
4299
docker-php-ext-enable yaml

0 commit comments

Comments
 (0)