Skip to content

Commit

Permalink
Merge pull request #128 from ministryofjustice/build-patch
Browse files Browse the repository at this point in the history
Build patch
  • Loading branch information
brown-a2 authored Nov 15, 2023
2 parents bc70a8d + 9322995 commit 1c1c30c
Show file tree
Hide file tree
Showing 12 changed files with 125 additions and 185 deletions.
8 changes: 8 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
# Directories
/wordpress

# Database files
*.sql

# Other
.git
.DS_Store
.env
.env.local
auth.json

# WordPress related
# We can't ignore these as we need them when building the image
!/wordpress/wp-content/plugins
!/wordpress/wp-content/themes
Expand Down
7 changes: 3 additions & 4 deletions .dory.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,17 @@ dory:
dnsmasq:
enabled: true
domains:
-
domain: docker
- domain: docker
address: 127.0.0.1
container_name: dory_dnsmasq
port: 53
kill_others: ask
kill_others: true
service_start_delay: 5
image: tripox/dory-dnsmasq:latest
nginx_proxy:
enabled: true
container_name: dory_dinghy_http_proxy
https_enabled: false
https_enabled: false
ssl_certs_dir: ''
port: 80
tls_port: 443
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/rw-build-image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ on:
required: true

jobs:

buildImage:
name: Build Image and push to ECR
runs-on: ubuntu-latest
Expand All @@ -87,7 +86,6 @@ jobs:
role-to-assume: ${{ secrets.ecr-role }}
aws-region: ${{ secrets.ecr-region }}


# Login to container repository
- name: Login to ECR
uses: aws-actions/amazon-ecr-login@v1
Expand Down Expand Up @@ -123,9 +121,11 @@ jobs:
npm run production --if-present --prefix ./wordpress/wp-content/themes/hale-dash
npm install --prefix ./wordpress/wp-content/themes/ppo
npm run production --if-present --prefix ./wordpress/wp-content/themes/ppo
npm install --prefix ./wordpress/wp-content/themes/sifocc
npm run production --if-present --prefix ./wordpress/wp-content/themes/sifocc
- name: Build and Push Wordpress Image
run: |
docker build --pull --no-cache --tag $REGISTRY/$REPOSITORY:hale-platform_wordpress-$IMAGE_TAG --file wp.dockerfile .
docker build --pull --no-cache --tag $REGISTRY/$REPOSITORY:hale-platform_wordpress-$IMAGE_TAG --file wordpress.dockerfile .
docker push $REGISTRY/$REPOSITORY:hale-platform_wordpress-$IMAGE_TAG
env:
REGISTRY: ${{ steps.login-ecr.outputs.registry }}
Expand Down
27 changes: 26 additions & 1 deletion bin/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,19 @@ while true; do
rm -rf $DIR
fi

# Determine the path for the .env file and create file. Do not overwrite if .env exists.
ENV_FILE_PATH="$(pwd)/.env"

# Check if .env file already exists
if [ ! -f "$ENV_FILE_PATH" ]; then
# Create .env only if it doesn't exist
echo "# Add in custom variables you want to run in the Docker container locally" > "$ENV_FILE_PATH"
echo "Generated .env file at $ENV_FILE_PATH"
else
# .env file already exists
echo ".env file already exists at $ENV_FILE_PATH. Skipping creation."
fi

# Install build dependancies
echo -e '\n######################'
echo -e '# Run Composer'
Expand All @@ -43,7 +56,19 @@ while true; do
echo -e '# Run NPM'
echo -e '######################\n'
npm install --prefix ./wordpress/wp-content/themes/hale
npm run build --prefix ./wordpress/wp-content/themes/hale
npm run production --if-present --prefix ./wordpress/wp-content/themes/hale
npm install --prefix ./wordpress/wp-content/themes/brookhouse
npm run production --if-present --prefix ./wordpress/wp-content/themes/brookhouse
npm install --prefix ./wordpress/wp-content/themes/lawcom
npm run production --if-present --prefix ./wordpress/wp-content/themes/lawcom
npm install --prefix ./wordpress/wp-content/themes/justicejobs
npm run production --if-present --prefix ./wordpress/wp-content/themes/justicejobs
npm install --prefix ./wordpress/wp-content/themes/hale-dash
npm run production --if-present --prefix ./wordpress/wp-content/themes/hale-dash
npm install --prefix ./wordpress/wp-content/themes/ppo
npm run production --if-present --prefix ./wordpress/wp-content/themes/ppo
npm install --prefix ./wordpress/wp-content/themes/sifocc
npm run production --if-present --prefix ./wordpress/wp-content/themes/sifocc

# Test Docker is running locally
if ! docker info > /dev/null 2>&1; then
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"ministryofjustice/hale-components": "dev-main",
"ministryofjustice/hale-dash": "dev-main",
"ministryofjustice/ppo": "dev-main",
"ministryofjustice/sifocc": "dev-main",
"ministryofjustice/hale-components": "dev-main",
"wpackagist-plugin/advanced-custom-fields-table-field":"1.3.20",
"wpackagist-plugin/advanced-responsive-video-embedder": "*",
Expand Down
73 changes: 32 additions & 41 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
version: '3.9'

networks:
wordpress:

volumes:
database:
driver: local

services:
nginx:
container_name: nginx
platform: linux/arm64v8
build:
context: .
dockerfile: nginx.local.dockerfile
container_name: nginx
ports:
- 8080:8080
- 443:443
Expand All @@ -25,50 +16,39 @@ services:
depends_on:
- wordpress
- mariadb
networks:
- wordpress
env_file:
- .env.local
environment:
VIRTUAL_HOST: hale.docker
VIRTUAL_PORT: 443

mariadb:
image: mariadb:10.7.1-focal
container_name: mariadb
image: mariadb:11.1.2-jammy
ports:
- 3306:3306
env_file:
- .env.local
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
DB_NAME: wordpress
DB_USER: wordpress
DB_PASSWORD: wordpress
DB_HOST: mariadb:3306
VIRTUAL_PROTO: https
SERVICE_NAME: mariadb
SERVICE_TAGS: local
VIRTUAL_HOST: mariadb.docker
volumes:
- database:/var/lib/mysql
networks:
- wordpress

wordpress:
depends_on:
- mariadb
container_name: wordpress
platform: linux/amd64
build:
context: .
dockerfile: wp.dockerfile
container_name: wordpress
dockerfile: wordpress.dockerfile
volumes:
- ./wordpress:/var/www/html:delegated
networks:
- wordpress
- ./opt/php/php.ini:/usr/local/etc/php/conf.d/php.ini
depends_on:
- mariadb
env_file:
- .env.local
- .env
environment:
WORDPRESS_DB_HOST: mariadb:3306
WORDPRESS_DB_USER: wordpress
Expand All @@ -78,14 +58,25 @@ services:
WORDPRESS_ADMIN_PASSWORD: wordpress
WORDPRESS_ADMIN_EMAIL: "wordpress@hale.docker"
WP_ENVIRONMENT_TYPE: local
S3_UPLOADS_USE_LOCAL: "true"
S3_UPLOADS_USE_INSTANCE_PROFILE: "false"
S3_UPLOADS_REGION: ""
S3_UPLOADS_BUCKET: ""

phpmyadmin:
image: phpmyadmin/phpmyadmin
container_name: phpmyadmin
platform: linux/amd64
ports:
- 3000:80 # access at http://localhost:3000
environment:
PMA_HOST: mariadb
PMA_PORT: 3306
UPLOAD_LIMIT: 600M
MYSQL_ROOT_PASSWORD: root # login root/root
depends_on:
- mariadb

#wp:
#build:
# context: .
# dockerfile: wp.dockerfile
# container_name: wp
# entrypoint: ['wp', '--allow-root']
# volumes:
# - ./wordpress:/var/www/html:delegated
# networks:
# - wordpress
volumes:
database:
driver: local
46 changes: 4 additions & 42 deletions makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
## Docker
####################################################
### Local build config
####################################################

# Run site using Docker.
run:
docker-compose up -d
chmod +x bin/upload.sh
./bin/upload.sh

# Shutdown site using Docker.
# Shutdown site using Docker
down:
docker-compose down

Expand All @@ -26,43 +28,3 @@ shell:
# Remove all dangling <none> images
none:
docker rmi $(docker images -f "dangling=true" -q)

tagpush:
docker tag hale-platform_wordpress 754256621582.dkr.ecr.eu-west-2.amazonaws.com/jotw-content-devs/hale-platform-dev-ecr:hale-platform_wordpress && \
docker tag hale-platform_nginx 754256621582.dkr.ecr.eu-west-2.amazonaws.com/jotw-content-devs/hale-platform-dev-ecr:hale-platform_nginx && \
docker push 754256621582.dkr.ecr.eu-west-2.amazonaws.com/jotw-content-devs/hale-platform-dev-ecr:hale-platform_wordpress && \
docker push 754256621582.dkr.ecr.eu-west-2.amazonaws.com/jotw-content-devs/hale-platform-dev-ecr:hale-platform_nginx && \
aws ecr list-images --repository-name jotw-content-devs/hale-platform-dev-ecr


deploylocal:
chmod +x bin/deploy-local.sh && \
./bin/deploy-local.sh

deploydev:
chmod +x bin/deploy-dev.sh && \
./bin/deploy-dev.sh

## AWS

# List all the images in ECR for our hale-platform-dev-ecr namespace
ecr-images:
aws ecr list-images --repository-name jotw-content-devs/hale-platform-dev-ecr

# Run wp cli on the container
# Very handy little tool. TODO// make this
# more dynamic so you just have to add your
# wp cli commands
wpcli:
docker-compose run --rm wp user list

# Kubernetes

# Setup the ConfigMap
# kubectl create configmap wpconfig --from-env-file=.env

# Build and run site in k8s cluster.
# kubectl apply manifests/

# Delete and shutdown site in k8s cluster.
# kubectl delete -k ./
3 changes: 3 additions & 0 deletions opt/php/php.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
; php.ini
upload_max_filesize = 64M
post_max_size = 64M
5 changes: 3 additions & 2 deletions opt/php/www.conf
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@
; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
; will be used.
user = hale
group = hale
; ****These are ignored and off as they won't run when we are running the container as non-root.
;user = hale
;group = hale

; The address on which to accept FastCGI requests.
; Valid syntaxes are:
Expand Down
12 changes: 7 additions & 5 deletions opt/scripts/config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ wp config set FORCE_SSL_ADMIN true --raw
wp config set S3_UPLOADS_BUCKET "\$_SERVER['S3_UPLOADS_BUCKET']" --raw
wp config set S3_UPLOADS_REGION "\$_SERVER['S3_UPLOADS_REGION']" --raw
wp config set S3_UPLOADS_USE_INSTANCE_PROFILE "\$_SERVER['S3_UPLOADS_USE_INSTANCE_PROFILE']" --raw
wp config set QM_ENABLE_CAPS_PANEL true --raw

#WP core install
wp core multisite-install --title="Hale Multisite Platform" \
Expand All @@ -33,11 +34,12 @@ wp core update-db --network --url="${SERVER_NAME}"

# Setup Hale theme
wp theme enable hale --network --url="${SERVER_NAME}"
#wp theme enable hale --activate --url="$SERVER_NAME"

# Check plugins are activated
#wp plugin --network activate advanced-custom-fields-pro --url="${SERVER_NAME}"
#wp plugin --network activate wp-user-roles --url="${SERVER_NAME}"
#wp plugin --network activate wp-moj-blocks --url="${SERVER_NAME}"
# Activate greater capabilities for Query Monitor plugin
wp qm enable

# Delete default installed core themes and plugins
wp theme delete twentytwentyone twentytwentytwo
wp plugin delete akismet hello

exec "$@"
54 changes: 0 additions & 54 deletions template.env.local

This file was deleted.

Loading

0 comments on commit 1c1c30c

Please sign in to comment.