Skip to content

Commit c6dd24a

Browse files
authored
Merge pull request #48 from autopilotpattern/add-makefile
Update Nginx, add makefile
2 parents 0c96844 + 230e710 commit c6dd24a

File tree

9 files changed

+186
-120
lines changed

9 files changed

+186
-120
lines changed

Dockerfile

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ COPY etc /etc
3838

3939
# Add Containerpilot and its configuration
4040
# Releases at https://github.com/joyent/containerpilot/releases
41-
ENV CONTAINERPILOT_VER 2.7.2
41+
ENV CONTAINERPILOT_VER 2.7.3
4242
ENV CONTAINERPILOT file:///etc/containerpilot.json
4343

4444
RUN set -ex \
45-
&& export CONTAINERPILOT_CHECKSUM=e886899467ced6d7c76027d58c7f7554c2fb2bcc \
45+
&& export CONTAINERPILOT_CHECKSUM=2511fdfed9c6826481a9048e8d34158e1d7728bf \
4646
&& curl --retry 7 --fail -Lso /tmp/containerpilot.tar.gz \
4747
"https://github.com/joyent/containerpilot/releases/download/${CONTAINERPILOT_VER}/containerpilot-${CONTAINERPILOT_VER}.tar.gz" \
4848
&& echo "${CONTAINERPILOT_CHECKSUM} /tmp/containerpilot.tar.gz" | sha1sum -c \
@@ -63,8 +63,8 @@ RUN set -ex \
6363
# Install Consul template
6464
# Releases at https://releases.hashicorp.com/consul-template/
6565
RUN set -ex \
66-
&& export CONSUL_TEMPLATE_VERSION=0.18.2 \
67-
&& export CONSUL_TEMPLATE_CHECKSUM=6fee6ab68108298b5c10e01357ea2a8e4821302df1ff9dd70dd9896b5c37217c \
66+
&& export CONSUL_TEMPLATE_VERSION=0.18.3 \
67+
&& export CONSUL_TEMPLATE_CHECKSUM=caf6018d7489d97d6cc2a1ac5f1cbd574c6db4cd61ed04b22b8db7b4bde64542 \
6868
&& curl --retry 7 --fail -Lso /tmp/consul-template.zip "https://releases.hashicorp.com/consul-template/${CONSUL_TEMPLATE_VERSION}/consul-template_${CONSUL_TEMPLATE_VERSION}_linux_amd64.zip" \
6969
&& echo "${CONSUL_TEMPLATE_CHECKSUM} /tmp/consul-template.zip" | sha256sum -c \
7070
&& unzip /tmp/consul-template.zip -d /usr/local/bin \
@@ -84,7 +84,8 @@ COPY /var/www/html /var/www/html
8484
RUN chown -R www-data:www-data /var/www/html/*
8585

8686
# Install WordPress via wp-cli & move the default themes to our content dir
87-
ENV WORDPRESS_VERSION 4.7.3
87+
# Releases at https://core.svn.wordpress.org/tags/ and https://wordpress.org/news/category/releases/
88+
ENV WORDPRESS_VERSION 4.7.5
8889
RUN set -ex \
8990
&& wp --allow-root core download --version=${WORDPRESS_VERSION} \
9091
&& mv /var/www/html/wordpress/wp-content/themes/* /var/www/html/content/themes/

Makefile

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Makefile for shipping and testing the container image.
2+
3+
MAKEFLAGS += --warn-undefined-variables
4+
.DEFAULT_GOAL := build
5+
.PHONY: *
6+
7+
# we get these from CI environment if available, otherwise from git
8+
GIT_COMMIT ?= $(shell git rev-parse --short HEAD)
9+
GIT_BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD)
10+
WORKSPACE ?= $(shell pwd)
11+
12+
namespace ?= autopilotpattern
13+
tag := branch-$(shell basename $(GIT_BRANCH))
14+
imageWordpress := $(namespace)/wordpress
15+
imageNginx := $(namespace)/wordpress-nginx
16+
17+
#dockerLocal := DOCKER_HOST= DOCKER_TLS_VERIFY= DOCKER_CERT_PATH= docker
18+
dockerLocal := docker
19+
#composeLocal := DOCKER_HOST= DOCKER_TLS_VERIFY= DOCKER_CERT_PATH= docker-compose
20+
composeLocal := docker-compose
21+
22+
## Display this help message
23+
help:
24+
@awk '/^##.*$$/,/[a-zA-Z_-]+:/' $(MAKEFILE_LIST) | awk '!(NR%2){print $$0p}{p=$$0}' | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' | sort
25+
26+
27+
# ------------------------------------------------
28+
# Container builds
29+
30+
## Builds the application container image locally
31+
build:
32+
$(dockerLocal) build -t=$(imageWordpress):$(tag) .
33+
cd nginx && $(dockerLocal) build -t=$(imageNginx):$(tag) .
34+
35+
## Push the current application container images to the Docker Hub
36+
push:
37+
$(dockerLocal) push $(imageWordpress):$(tag)
38+
$(dockerLocal) push $(imageNginx):$(tag)
39+
40+
## Tag the current images as 'latest'
41+
tag:
42+
$(dockerLocal) tag $(imageWordpress):$(tag) $(imageWordpress):latest
43+
$(dockerLocal) tag $(imageNginx):$(tag) $(imageNginx):latest
44+
45+
## Push latest tag(s) to the Docker Hub
46+
ship: tag
47+
$(dockerLocal) push $(imageWordpress):$(tag)
48+
$(dockerLocal) push $(imageWordpress):latest
49+
$(dockerLocal) push $(imageNginx):$(tag)
50+
$(dockerLocal) push $(imageNginx):latest
51+
52+
53+
# ------------------------------------------------
54+
# Test running
55+
56+
## Pull the container images from the Docker Hub
57+
pull:
58+
$(dockerLocal) pull $(imageWordpress):$(tag)
59+
$(dockerLocal) pull $(imageNginx):$(tag)
60+
61+
## Print environment for build debugging
62+
debug:
63+
@echo WORKSPACE=$(WORKSPACE)
64+
@echo GIT_COMMIT=$(GIT_COMMIT)
65+
@echo GIT_BRANCH=$(GIT_BRANCH)
66+
@echo namespace=$(namespace)
67+
@echo tag=$(tag)
68+
@echo imageWordpress=$(imageWordpress)
69+
@echo imageNginx=$(imageNginx)
70+
71+
# -------------------------------------------------------
72+
# helper functions for testing if variables are defined
73+
#
74+
check_var = $(foreach 1,$1,$(__check_var))
75+
__check_var = $(if $(value $1),,\
76+
$(error Missing $1 $(if $(value 2),$(strip $2))))

docker-compose.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# An demo version of WordPress for easy scaling
22
wordpress:
3-
image: autopilotpattern/wordpress:4.7.3-r4.0.0
3+
image: autopilotpattern/wordpress:latest
44
restart: always
55
env_file: _env
66
environment:
@@ -86,7 +86,7 @@ memcached:
8686

8787
# Nginx as a load-balancing tier and reverse proxy
8888
nginx:
89-
image: autopilotpattern/wordpress-nginx:4.7.3-r4.0.0
89+
image: autopilotpattern/wordpress-nginx:latest
9090
restart: always
9191
ports:
9292
- 80
@@ -103,7 +103,7 @@ nginx:
103103
# Prometheus is an open source performance monitoring tool
104104
# it is included here for demo purposes and is not required
105105
prometheus:
106-
image: autopilotpattern/prometheus:latest
106+
image: autopilotpattern/prometheus:branch-triton-support
107107
restart: always
108108
env_file: _env
109109
ports:

nginx/.dockerignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.DS_Store
2+
**/.DS_Store
3+
_env*

nginx/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# a minimal Nginx container including containerbuddy and a simple virtulhost config
2-
FROM autopilotpattern/nginx:1-r6.1.0
2+
FROM autopilotpattern/nginx:1.13-r7.0.1
33

44
# Add our configuration files
55
COPY etc /etc

nginx/etc/containerpilot.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"consul": "{{ if .CONSUL_AGENT }}localhost{{ else }}{{ .CONSUL }}{{ end }}:8500",
3-
"preStart": "/usr/local/bin/reload.sh preStart",
3+
"preStart": "generate-config",
44
"logging": {"level": "DEBUG"},
55
"services": [
66
{
@@ -32,7 +32,7 @@
3232
{
3333
"name": "wordpress",
3434
"poll": 7,
35-
"onChange": "/usr/local/bin/reload.sh"
35+
"onChange": "reload"
3636
}
3737
],
3838
"coprocesses": [{{ if .CONSUL_AGENT }}
@@ -62,14 +62,14 @@
6262
"help": "Number of accepted connnections that were not handled",
6363
"type": "gauge",
6464
"poll": 5,
65-
"check": ["/usr/local/bin/sensor.sh", "unhandled"]
65+
"check": ["sensor", "unhandled"]
6666
},
6767
{
6868
"name": "nginx_connections_load",
6969
"help": "Ratio of active connections (less waiting) to the maximum worker connections",
7070
"type": "gauge",
7171
"poll": 5,
72-
"check": ["/usr/local/bin/sensor.sh", "connections_load"]
72+
"check": ["sensor", "connections_load"]
7373
}
7474
]
7575
},

nginx/etc/nginx/nginx.conf.ctmpl

Lines changed: 0 additions & 107 deletions
This file was deleted.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{{ $acme_domain := env "ACME_DOMAIN" }}
2+
{{ $ssl_ready := env "SSL_READY" }}
3+
4+
# If we're listening on https, define an http listener that redirects everything to https
5+
{{ if eq $ssl_ready "true" }}
6+
server {
7+
server_name _;
8+
listen 80;
9+
10+
include /etc/nginx/health.conf;
11+
12+
location / {
13+
return 301 https://$host$request_uri;
14+
}
15+
}
16+
{{ end }}
17+
18+
# The main server block
19+
server {
20+
server_name _;
21+
# Listen on port 80 unless we have certificates installed, then listen on 443
22+
listen {{ if ne $ssl_ready "true" }}80{{ else }}443 ssl{{ end }};
23+
24+
include /etc/nginx/health.conf;
25+
26+
location /.well-known/acme-challenge {
27+
alias /var/www/acme/challenge;
28+
}
29+
30+
{{ if service "wordpress" }}
31+
rewrite ^/wp-admin/?(.*) /wordpress/wp-admin/$1;
32+
33+
location ^~ / {
34+
proxy_pass http://wordpress;
35+
proxy_redirect off;
36+
proxy_set_header Host $http_host;
37+
proxy_set_header X-Forwarded-Proto $scheme;
38+
proxy_set_header X-Real-IP $remote_addr;
39+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
40+
}{{ else }}
41+
# return 503 errors if we don't have our expected back-end
42+
location / {
43+
return 503;
44+
}{{ end }}
45+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# This is an example Nginx configuration template file.
2+
# Adjust the values below as required for your application.
3+
4+
user nginx;
5+
worker_processes 1;
6+
7+
error_log /var/log/nginx/error.log warn;
8+
pid /var/run/nginx.pid;
9+
10+
events {
11+
worker_connections 1024;
12+
}
13+
14+
http {
15+
include /etc/nginx/mime.types;
16+
default_type application/octet-stream;
17+
18+
map $status $isNot2xx {
19+
~^2 0;
20+
default 1;
21+
}
22+
23+
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
24+
'$status $body_bytes_sent "$http_referer" '
25+
'"$http_user_agent" "$http_x_forwarded_for" '
26+
'$upstream_addr';
27+
28+
access_log /var/log/nginx/access.log main;
29+
30+
sendfile on;
31+
keepalive_timeout 65;
32+
33+
{{ $ssl_ready := env "SSL_READY" }}
34+
35+
{{ if eq $ssl_ready "true" }}
36+
include ssl.conf;
37+
{{ end }}
38+
39+
{{ if service "wordpress" }}
40+
upstream wordpress {
41+
# write the address:port pairs for each healthy wordpress node
42+
{{range service "wordpress"}}
43+
server {{.Address}}:{{.Port}};
44+
{{end}}
45+
}{{ end }}
46+
47+
include conf.d/*.conf;
48+
}

0 commit comments

Comments
 (0)