-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #48 from autopilotpattern/add-makefile
Update Nginx, add makefile
- Loading branch information
Showing
9 changed files
with
186 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# Makefile for shipping and testing the container image. | ||
|
||
MAKEFLAGS += --warn-undefined-variables | ||
.DEFAULT_GOAL := build | ||
.PHONY: * | ||
|
||
# we get these from CI environment if available, otherwise from git | ||
GIT_COMMIT ?= $(shell git rev-parse --short HEAD) | ||
GIT_BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD) | ||
WORKSPACE ?= $(shell pwd) | ||
|
||
namespace ?= autopilotpattern | ||
tag := branch-$(shell basename $(GIT_BRANCH)) | ||
imageWordpress := $(namespace)/wordpress | ||
imageNginx := $(namespace)/wordpress-nginx | ||
|
||
#dockerLocal := DOCKER_HOST= DOCKER_TLS_VERIFY= DOCKER_CERT_PATH= docker | ||
dockerLocal := docker | ||
#composeLocal := DOCKER_HOST= DOCKER_TLS_VERIFY= DOCKER_CERT_PATH= docker-compose | ||
composeLocal := docker-compose | ||
|
||
## Display this help message | ||
help: | ||
@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 | ||
|
||
|
||
# ------------------------------------------------ | ||
# Container builds | ||
|
||
## Builds the application container image locally | ||
build: | ||
$(dockerLocal) build -t=$(imageWordpress):$(tag) . | ||
cd nginx && $(dockerLocal) build -t=$(imageNginx):$(tag) . | ||
|
||
## Push the current application container images to the Docker Hub | ||
push: | ||
$(dockerLocal) push $(imageWordpress):$(tag) | ||
$(dockerLocal) push $(imageNginx):$(tag) | ||
|
||
## Tag the current images as 'latest' | ||
tag: | ||
$(dockerLocal) tag $(imageWordpress):$(tag) $(imageWordpress):latest | ||
$(dockerLocal) tag $(imageNginx):$(tag) $(imageNginx):latest | ||
|
||
## Push latest tag(s) to the Docker Hub | ||
ship: tag | ||
$(dockerLocal) push $(imageWordpress):$(tag) | ||
$(dockerLocal) push $(imageWordpress):latest | ||
$(dockerLocal) push $(imageNginx):$(tag) | ||
$(dockerLocal) push $(imageNginx):latest | ||
|
||
|
||
# ------------------------------------------------ | ||
# Test running | ||
|
||
## Pull the container images from the Docker Hub | ||
pull: | ||
$(dockerLocal) pull $(imageWordpress):$(tag) | ||
$(dockerLocal) pull $(imageNginx):$(tag) | ||
|
||
## Print environment for build debugging | ||
debug: | ||
@echo WORKSPACE=$(WORKSPACE) | ||
@echo GIT_COMMIT=$(GIT_COMMIT) | ||
@echo GIT_BRANCH=$(GIT_BRANCH) | ||
@echo namespace=$(namespace) | ||
@echo tag=$(tag) | ||
@echo imageWordpress=$(imageWordpress) | ||
@echo imageNginx=$(imageNginx) | ||
|
||
# ------------------------------------------------------- | ||
# helper functions for testing if variables are defined | ||
# | ||
check_var = $(foreach 1,$1,$(__check_var)) | ||
__check_var = $(if $(value $1),,\ | ||
$(error Missing $1 $(if $(value 2),$(strip $2)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.DS_Store | ||
**/.DS_Store | ||
_env* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# a minimal Nginx container including containerbuddy and a simple virtulhost config | ||
FROM autopilotpattern/nginx:1-r6.1.0 | ||
FROM autopilotpattern/nginx:1.13-r7.0.1 | ||
|
||
# Add our configuration files | ||
COPY etc /etc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
{{ $acme_domain := env "ACME_DOMAIN" }} | ||
{{ $ssl_ready := env "SSL_READY" }} | ||
|
||
# If we're listening on https, define an http listener that redirects everything to https | ||
{{ if eq $ssl_ready "true" }} | ||
server { | ||
server_name _; | ||
listen 80; | ||
|
||
include /etc/nginx/health.conf; | ||
|
||
location / { | ||
return 301 https://$host$request_uri; | ||
} | ||
} | ||
{{ end }} | ||
|
||
# The main server block | ||
server { | ||
server_name _; | ||
# Listen on port 80 unless we have certificates installed, then listen on 443 | ||
listen {{ if ne $ssl_ready "true" }}80{{ else }}443 ssl{{ end }}; | ||
|
||
include /etc/nginx/health.conf; | ||
|
||
location /.well-known/acme-challenge { | ||
alias /var/www/acme/challenge; | ||
} | ||
|
||
{{ if service "wordpress" }} | ||
rewrite ^/wp-admin/?(.*) /wordpress/wp-admin/$1; | ||
|
||
location ^~ / { | ||
proxy_pass http://wordpress; | ||
proxy_redirect off; | ||
proxy_set_header Host $http_host; | ||
proxy_set_header X-Forwarded-Proto $scheme; | ||
proxy_set_header X-Real-IP $remote_addr; | ||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
}{{ else }} | ||
# return 503 errors if we don't have our expected back-end | ||
location / { | ||
return 503; | ||
}{{ end }} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# This is an example Nginx configuration template file. | ||
# Adjust the values below as required for your application. | ||
|
||
user nginx; | ||
worker_processes 1; | ||
|
||
error_log /var/log/nginx/error.log warn; | ||
pid /var/run/nginx.pid; | ||
|
||
events { | ||
worker_connections 1024; | ||
} | ||
|
||
http { | ||
include /etc/nginx/mime.types; | ||
default_type application/octet-stream; | ||
|
||
map $status $isNot2xx { | ||
~^2 0; | ||
default 1; | ||
} | ||
|
||
log_format main '$remote_addr - $remote_user [$time_local] "$request" ' | ||
'$status $body_bytes_sent "$http_referer" ' | ||
'"$http_user_agent" "$http_x_forwarded_for" ' | ||
'$upstream_addr'; | ||
|
||
access_log /var/log/nginx/access.log main; | ||
|
||
sendfile on; | ||
keepalive_timeout 65; | ||
|
||
{{ $ssl_ready := env "SSL_READY" }} | ||
|
||
{{ if eq $ssl_ready "true" }} | ||
include ssl.conf; | ||
{{ end }} | ||
|
||
{{ if service "wordpress" }} | ||
upstream wordpress { | ||
# write the address:port pairs for each healthy wordpress node | ||
{{range service "wordpress"}} | ||
server {{.Address}}:{{.Port}}; | ||
{{end}} | ||
}{{ end }} | ||
|
||
include conf.d/*.conf; | ||
} |