Commit 6c141436 authored by Dom Sekotill's avatar Dom Sekotill
Browse files

Merge branch 'develop' into 'master'

Merge ongoing development to "master"

See merge request !11
parents 58182bc6 0b523b93
Loading
Loading
Loading
Loading
Loading
+46 −22
Original line number Diff line number Diff line
@@ -16,45 +16,69 @@ before_script:

.build: &build
  stage: build
  only: &build-only
  script:
  - TARGET=${CI_JOB_NAME##*:}
  - BUILD_TAG=${CI_REGISTRY_IMAGE}/${TARGET}/build:${CI_PIPELINE_ID}
  - docker build .
    --pull=true
    --tag=${BUILD_TAG}
    --target=${TARGET}
    ${NGINX_VERSION:+--build-arg=nginx_version=$NGINX_VERSION}
    ${PHP_VERSION:+--build-arg=php_version=$PHP_VERSION}
    ${WORDPRESS_VERSION:+--build-arg=wp_version=$WORDPRESS_VERSION}
  - docker push ${BUILD_TAG}

.changes: &only-changes
  only: &change-files
    changes:
    - .gitlab-ci.yml
    - Dockerfile
    - data/*
    - plugins/*
    - scripts/*
  script:
  - docker build .
    --pull=true
    --tag=${CI_REGISTRY_IMAGE}/${CI_JOB_NAME#build-}/build:${CI_PIPELINE_ID}
    ${TARGET+--target=$TARGET}
  after_script:
  - docker push
    ${CI_REGISTRY_IMAGE}/${CI_JOB_NAME#build-}/build:${CI_PIPELINE_ID}

build-fastcgi:
  <<: *build
build-nginx:
  <<: *build
  variables:
    TARGET: nginx

.merge-requests: &only-merge-requests
  only:
    << : *change-files
    refs:
    - merge_requests

build-master:fastcgi:
  << : [ *build ]
  only: [ master, schedules ]
build-master:nginx:
  << : [ *build ]
  only: [ master, schedules ]

build-mr:fastcgi:
  << : [ *build, *only-merge-requests ]
build-mr:nginx:
  << : [ *build, *only-merge-requests ]

build:fastcgi:
  << : [ *build, *only-changes ]
  except: [ merge_requests, master, schedules ]
build:nginx:
  << : [ *build, *only-changes ]
  except: [ merge_requests, master, schedules ]


.push-tags: &push-tags
  stage: deploy
  only:
    <<: *build-only
    refs: [master, develop]
    << : *change-files
    refs: [ master, develop, schedules ]
  script: |
    BUILD_REPO=${CI_REGISTRY_IMAGE}/${CI_JOB_NAME#push-}/build:${CI_PIPELINE_ID}
    DEPLOY_REPO=${CI_REGISTRY_IMAGE}/${CI_JOB_NAME#push-}
    BUILD_REPO=${CI_REGISTRY_IMAGE}/${CI_JOB_NAME##*:}/build:${CI_PIPELINE_ID}
    DEPLOY_REPO=${CI_REGISTRY_IMAGE}/${CI_JOB_NAME##*:}
    VERSION=`eval "docker run --rm ${BUILD_REPO} ${GET_VERSION}"`
    . scripts/deploy.sh

push-fastcgi:
push:fastcgi:
  <<: *push-tags
  variables:
    GET_VERSION: wp core version
push-nginx:
push:nginx:
  <<: *push-tags
  variables:
    GET_VERSION: nginx -V 2>&1 | sed -n '/nginx version:/s/.*nginx\///p'
+9 −4
Original line number Diff line number Diff line
@@ -4,15 +4,19 @@ ARG nginx_version=latest
FROM nginx:${nginx_version} as nginx
LABEL uk.org.kodo.maintainer = "Dom Sekotill <dom.sekotill@kodo.org.uk>"
COPY data/nginx.conf /etc/nginx/conf.d/default.conf
COPY data/fastcgi.nginx.conf /etc/nginx/fastcgi.conf
COPY data/cache-bust.nginx.conf /etc/nginx/cache-bust.conf
COPY data/5*.html /app/html/


FROM php:7.3-fpm-alpine as deps
ARG php_version=
FROM php:${php_version:+$php_version-}fpm-alpine as deps
RUN --mount=type=bind,source=scripts/install-deps.sh,target=/stage /stage

FROM deps as compile
RUN --mount=type=bind,source=scripts/compile.sh,target=/stage /stage

FROM deps
FROM deps as fastcgi

LABEL uk.org.kodo.maintainer "Dom Sekotill <dom.sekotill@kodo.org.uk>"

@@ -20,13 +24,14 @@ ARG wp_version=latest
WORKDIR /app
ENV WORDPRESS_ROOT=/app

COPY scripts/wp.sh /usr/local/bin/wp
COPY --from=compile /usr/local/etc/php /usr/local/etc/php
COPY --from=compile /usr/local/lib/php /usr/local/lib/php
COPY scripts/wp.sh /usr/local/bin/wp
COPY data/composer.json /app/composer.json
RUN --mount=type=bind,source=scripts/install-wp.sh,target=/stage \
    /stage ${wp_version}

COPY plugins/probe.php wp-content/mu-plugins/
COPY plugins/* wp-content/mu-plugins/
COPY data/fpm.conf /usr/local/etc/php-fpm.d/image.conf
COPY data/opcache.ini /usr/local/etc/php/conf.d/opcache-recommended.ini
COPY data/wp-config.php /usr/share/wordpress/wp-config.php

data/502.html

0 → 100644
+107 −0
Original line number Diff line number Diff line
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" class="wp-toolbar" lang="en-GB">
	<head>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1" />
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" />
		<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
		<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" defer="defer"></script>
		<title>Site Unavailable</title>
		<script>
			var check = false;

			function sleep(delay_ms) {
				return new Promise((resolve) => setTimeout(resolve, delay_ms));
			}

			function head(url) {
				return new Promise((resolve, reject) => {
					jQuery.ajax({
						url: url,
						method: 'HEAD',
						success: resolve,
						error: reject,
					});
				})
			}

			$(document).ready(function() {
				$('#checkModal')
					.on('hide.bs.modal', function() {
						check = false;
					})
					.on('shown.bs.modal', async function() {
						check = true;
						while (check) {
							await sleep(1000);
							try {
								await head('#');
							} catch (err) {
								if (err.status === undefined)
									throw err;
								if (err.status == 502)
									continue;
							}
							// non-502 code received
							window.location.reload();
						}
					})
					.modal('show');
			});
		</script>
		<style>
			.vertical-center {
				min-height: 100%;
				min-height:100vh;
				display: flex;
				align-items: center;
			}
		</style>
	</head>
	<body>
		<div class="modal fade" tabindex="-1" id="checkModal" role="dialog" aria-labelledby="#checkModalLabel">
			<div class="modal-dialog" role="document">
				<div class="modal-content">

					<!-- header -->
					<div class="modal-header">
						<h4 class="modal-title" id="checkModalLabel">Site Unavailable</h4>
					</div>

					<!-- body -->
					<div class="modal-body">
						<p>The page will reload automatically when the site becomes
							available &#x2026;</p>
					</div>

					<!-- footer -->
					<div class="modal-footer">
						<button type="button" class="btn btn-danger" data-dismiss="modal">
							<span class="spinner-border spinner-border-sm"></span>
							Cancel
						</button>
					</div>

				</div>
			</div>
		</div>

		<div class="vertical-center">
			<div class="container">

				<div class="d-flex justify-content-center align-items-center">
					<div class="p-2">
						<h1>Site Unavailable</h1>
						<p>This site is currently unavailable</p>
						<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#checkModal">
							Check availability
						</button>
					</div>
				</div>

			</div>
		</div>

	</body>
</html>
+1 −0
Original line number Diff line number Diff line
add_header X-Clacks-Overhead "GNU Terry Pratchett";

data/composer.json

0 → 100644
+21 −0
Original line number Diff line number Diff line
{
	"type": "project",
	"license": "MPL-2.0",
	"repositories": [
		{
			"type": "gitlab",
			"url": "https://code.kodo.org.uk/singing-chimes.co.uk/s3-uploads"
		}
	],
	"require": {
		"humanmade/s3-uploads": "dev-develop"
	},
	"config": {
		"gitlab-domains": [ "code.kodo.org.uk" ]
	},
	"extra": {
		"installer-paths": {
			"wp-content/mu-plugins/{$name}/": [ "type:wordpress-plugin" ]
		}
	}
}
Loading