Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
EvilWizard99 committed Nov 7, 2023
2 parents 7745500 + 9ba00c9 commit f982e19
Show file tree
Hide file tree
Showing 12 changed files with 187 additions and 112 deletions.
20 changes: 17 additions & 3 deletions .env-example
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
# Target build/use environment
APP_ENV=local
BUILD_IMAGE=php-5.6-apache
BUILD_IMAGE_TAG=v0.0.4
# set the PHP version for descriptions & such
PHP_VERSION=5.6

# Docker build & compose details
DOCKER_COMPOSE_BUILD_FILE=docker-compose-build.yaml
DOCKER_COMPOSE_FILE=docker-compose.yaml
DOCKER_BUILD_FILE=php-5-6-apache.Dockerfile
DOCKER_BUILD_REPO=docker_user/docker_repo
APACHE_PHP56_DOCKER_BUILD_DESC="PHP ${PHP_VERSION} & Apache Web Server"
APACHE_PHP56_DOCKER_BUILD_TARGET=build-php-56-apache
APACHE_PHP56_DOCKER_BUILD_IMAGE=php-5.6-apache
APACHE_PHP56_DOCKER_BUILD_IMAGE_TAG=v0.0.1

# Docker compose image details
APACHE_PHP56_DOCKER_IMAGE="${APACHE_PHP56_DOCKER_BUILD_IMAGE}"
APACHE_PHP56_DOCKER_IMAGE_TAG="${APACHE_PHP56_DOCKER_BUILD_IMAGE_TAG}"

# Making the npm versions changeable
NPM_VERSION=6.4.1
NPM_VERSION="6.4.1"

# App webserver ports
APP_PORT=8080
Expand Down
91 changes: 49 additions & 42 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,44 +28,71 @@ PHP Extensions:
- zip
- yaml

## Build Image
## Build & Compose Up

Build the ***Docker Image*** without using ***cached*** versions of previous image build stages.

### Helper Script
Note that the `php-5-6-apache` is the Docker Compose Service to ***Build***.

A helper script is available with the repo to force recreate the build & use the `docker-compose.yaml` file which reads the `.env` file.
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.

```bash
./build-web.sh
build-up-php-7.2-fpm.sh
```

### The long Way
Alternatively there is the *full Procedure*.

1. Build the Image using the `docker-compose-build.yaml` configuration.

```bash
docker-compose -f ./docker-compose-build.yaml build --no-cache php-5-6-apache
```

1. Compose *Up* using the `docker-compose-build.yaml` configuration will use the new built Image and `-d` to *detach*.

```bash
docker-compose -f ./docker-compose-build.yaml up -d
```

## Build Image The Long Way

Build the ***Docker Image*** without using ***cached*** versions of previous image build stages.


```bash
sudo docker build \
-f php-5-6-apache.Dockerfile \
--target php-5-6-build \
--target build-php-56-apache \
--build-arg APP_ENV=local \
--build-arg NPM_VERSION=6.4.1 \
--no-cache \
-t php-5-6-web-server:latest \
-t php-5-6-apache:latest \
.
```

**N.B.**

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

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

- Using `--target php-5-6-build`
- Using `--target build-php-56-apache`

To select the ***build target stage***[^multi_stage_builds_note] from the *Dockerfile*.

- Using `--no-cache`

To prevent using previous ***cached*** versions of image build stages.

- Using `--build-arg ARG=value`
- Using `--build-arg NPM_VERSION=6.4.1`

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.

- Using `-t php-5-6-apache:latest`

To set build argument values to use.
To ***name*** & ***tag*** the locally built docker image.

- Using `.`

To set the current location as the ***build context*** for the build process.

### Create A Container

Expand All @@ -76,8 +103,8 @@ sudo docker run \
-d \
--network host \
-v "$(pwd)"/public_html:/var/www/html \
--name php-5-6-web-server \
php-5-6-web-server:latest
--name php-5-6-apache \
php-5-6-apache:latest
```

**OR**
Expand All @@ -90,8 +117,8 @@ sudo docker run \
--network bridge \
-p 8080:80/tcp \
-v "$(pwd)"/public_html:/var/www/html \
--name php-5-6-web-server \
php-5-6-web-server:latest
--name php-5-6-apache \
php-5-6-apache:latest
```

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

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

- Using `--name php-5-6-web-server`
- Using `--name php-5-6-apache`

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

### Start Container

```bash
sudo docker start php-5-6-web-server
sudo docker start php-5-6-apache
```

### Stop Container

```bash
sudo docker stop php-5-6-web-server
```

## Docker Compose

A `docker-compose` configuration file is included to simplify the build & deployment of the image.

### Build - No Cache

This is only necessary when completely rebuilding the image to make sure all parts are rebuilt[^compose_name_note].

```bash
sudo docker-compose build --no-cache php-5-6-web-server
```

### Build & Up

This will try to use a local version or rebuild the image with current context.

```bash
sudo docker-compose up --build -d
sudo docker stop php-5-6-apache
```

## Connect To Container

```bash
sudo docker exec -it php-5-6-web-server /bin/bash
sudo docker exec -it php-5-6-apache /bin/bash
```

# Disclaimer
Expand All @@ -156,4 +163,4 @@ This Apache2 + PHP 5.6 build environment should ***NOT*** be used anywhere near
[^multi_stage_builds_note]: Used mostly in ***Multi Stage*** image builds.
[^compose_name_note]: The `php-5-6-web-server` container name to build the image for.
[^compose_name_note]: The `php-5-6-apache` container name to build the image for.
1 change: 1 addition & 0 deletions build-assets/etc/apt/sources.list
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
deb http://archive.debian.org/debian stretch main
Binary file added build-assets/pecl/yaml-1.3.0.tgz
Binary file not shown.
12 changes: 12 additions & 0 deletions build-up-php-5-6-apache.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash
# USAGE:
# build-up-php-5-6-apache.sh
#
# NOTE:
# Rebuild the Docker image & compose up.

# source the environment variables
set -o allexport; source "${PWD}/.env"; set +o allexport

# Use the EWC Protocol to build the image of the service & compose up
ewc-docker-build-up.sh "php-5-6-apache" "${APACHE_PHP56_DOCKER_BUILD_DESC:-PHP ${PHP_VERSION} & Apache Web Server}"
15 changes: 0 additions & 15 deletions build-web.sh

This file was deleted.

40 changes: 40 additions & 0 deletions docker-compose-build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
version: '3.7'

# Services/Containers to orchestrate in this composition
services:

# Basic PHP 5.6 & Apache2 Image Container
php-5-6-apache:
container_name: php-5-6-apache
tty: true
restart: unless-stopped
build:
context: .
target: ${APACHE_PHP56_DOCKER_BUILD_TARGET}
dockerfile: ${DOCKER_BUILD_FILE}
args:
- NPM_VERSION=${NPM_VERSION}
- APP_ENV=${APP_ENV}
labels:
ewc.name: "Web Server"
ewc.description: "${APACHE_PHP56_DOCKER_BUILD_DESC}"
ewc.php.version: "${PHP_VERSION}"
image: ${APACHE_PHP56_DOCKER_IMAGE}:${APACHE_PHP56_DOCKER_IMAGE_TAG}
environment:
- NPM_VERSION=${NPM_VERSION}
- APP_ENV=${APP_ENV}
working_dir: /var/www
ports:
- ${APP_PORT}:80
- ${APP_SSL_PORT}:443
volumes:
- ./public_html:/var/www/html
- ./docker-files/php/56.local.ini:/usr/local/etc/php.ini
networks:
- web-app-network

# Custom network for composed containers to communicate on
networks:
web-app-network:
driver: bridge

23 changes: 6 additions & 17 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,11 @@ version: '3.7'
services:

# Basic PHP 5.6 & Apache2 Image Container
php-5-6-web-server:
container_name: php-5-6-web-server
php-5-6-apache:
container_name: php-5-6-apache
tty: true
restart: unless-stopped
build:
context: .
target: php-5-6-build
dockerfile: php-5-6-apache.Dockerfile
args:
- NPM_VERSION=${NPM_VERSION}
- APP_ENV=${APP_ENV}
labels:
ewc.name: "Web Server"
ewc.description: "PHP & Apache Web Server"
ewc.php.version: "5.6"
image: $BUILD_IMAGE:$BUILD_IMAGE_TAG
image: ${APACHE_PHP56_DOCKER_IMAGE}:${APACHE_PHP56_DOCKER_IMAGE_TAG}
environment:
- NPM_VERSION=${NPM_VERSION}
- APP_ENV=${APP_ENV}
Expand All @@ -29,12 +18,12 @@ services:
- ${APP_SSL_PORT}:443
volumes:
- ./public_html:/var/www/html
- ./docker-files/php/local.ini:/usr/local/etc/php.ini
- ./docker-files/php/56.local.ini:/usr/local/etc/php.ini
networks:
- webapp_network
- web-app-network

# Custom network for composed containers to communicate on
networks:
webapp_network:
web-app-network:
driver: bridge

File renamed without changes.
15 changes: 0 additions & 15 deletions env-prep.sh

This file was deleted.

61 changes: 59 additions & 2 deletions php-5-6-apache.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM php:5.6-apache as php-5-6-build
FROM php:5.6-apache as build-php-56-apache

# Set some image labels
LABEL evilwizardcreations.image.authors="evil.wizard95@googlemail.com" \
Expand All @@ -10,6 +10,12 @@ ENV NPM_VERSION=$NPM_VERSION
# copy the specific Composer PHAR version from the Composer image into the PHP image
COPY --from=composer:1.7.1 /usr/bin/composer /usr/bin/composer

# The apt-get sources for this are so old it has been archived & needs chainging
COPY ./build-assets/etc/apt/sources.list /etc/apt/sources.list

# The pecl is so old it needs the local offline install now
COPY ./build-assets/pecl/yaml-1.3.0.tgz /tmp/yaml-1.3.0.tgz

# Download the nodejs setup & set that it's a docker env.
ENV NODE_ENV docker
# Node -v v8.12.0
Expand Down Expand Up @@ -38,5 +44,56 @@ RUN set -ex; \

# Install some php extensions from the docker built source.
RUN docker-php-ext-install gettext mysqli pdo_mysql zip
RUN pecl install yaml-1.3.0 && \
RUN pecl channel-update pecl.php.net && \
pecl install --offline /tmp/yaml-1.3.0.tgz && \
docker-php-ext-enable yaml && \
rm /tmp/yaml-1.3.0.tgz

# A test build to play with while getting it all working
FROM php:5.6-apache as build-php-56-apache-test

# Set some image labels
LABEL evilwizardcreations.image.authors="evil.wizard95@googlemail.com" \
evilwizardcreations.image.php.version="5.6"

ARG NPM_VERSION=6.4.1
ENV NPM_VERSION=$NPM_VERSION

# copy the specific Composer PHAR version from the Composer image into the PHP image
COPY --from=composer:1.7.1 /usr/bin/composer /usr/bin/composer

# The apt-get sources for this are so old it has been archived & needs chainging
COPY ./build-assets/etc/apt/sources.list /etc/apt/sources.list

# The pecl is so old it needs the local offline install now
COPY ./build-assets/pecl/yaml-1.3.0.tgz /tmp/yaml-1.3.0.tgz

# Download the nodejs setup & set that it's a docker env.
ENV NODE_ENV docker
# Node -v v8.12.0
#RUN curl --silent --location https://deb.nodesource.com/setup_8.x | bash

# Enable some apache modules.
RUN a2enmod rewrite; \
a2enmod headers; \
a2enmod ssl

RUN set -ex; \
apt-get update; \
apt-get install -y --no-install-recommends \
libxml2-dev \
libzip-dev \
libyaml-dev \
zip \
unzip \
git \
nodejs \
default-mysql-client \
vim; \
apt-get clean

# Install some php extensions from the docker built source.
RUN docker-php-ext-install gettext mysqli pdo_mysql zip
RUN pecl channel-update pecl.php.net && \
pecl install --offline /tmp/yaml-1.3.0.tgz && \
docker-php-ext-enable yaml
Loading

0 comments on commit f982e19

Please sign in to comment.