Skip to content

Commit

Permalink
include dcape2 sources
Browse files Browse the repository at this point in the history
  • Loading branch information
LeKovr committed Jan 28, 2021
1 parent 0926cf7 commit a095b1c
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 147 deletions.
5 changes: 2 additions & 3 deletions .drone.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
kind: pipeline
type: docker
name: website
name: app

steps:

Expand All @@ -10,8 +10,7 @@ steps:
image: ${DCAPE_COMPOSE}
commands:
- . setup config
- . setup root
- make .drone-up
- make .drone-default
volumes:
- name: dockersock
path: /var/run/docker.sock
Expand Down
154 changes: 27 additions & 127 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,139 +1,39 @@
## dcape-app-nginx-sample Makefile:
## Static site served by nginx
#:
SHELL = /bin/sh
CFG ?= .env
CFGSAMPLE ?= $(CFG).sample
DOT := .
DASH := -
# app custom Makefile

IMAGE_VER ?= 1.19.4-alpine
APP_SITE ?= host.dev.lan
APP_TAG ?= $(subst $(DOT),$(DASH),$(APP_SITE))
USE_TLS ?= false
APP_ACME_DOMAIN ?= www.$(APP_SITE)
APP_ROOT ?= $(PWD)
DCAPE_TAG ?= dcape
DCAPE_NET ?= dcape
DC_VER ?= latest
# Docker repo & image name without version
IMAGE ?= nginx
# Docker image version
IMAGE_VER ?= 1.19.4-alpine
# Hostname for external access
APP_SITE ?= site.dev.lan
# Overwrite dcape-compose.yml
DCAPE_APP_DC_YML = dcape-compose.yml

# ------------------------------------------------------------------------------
# .env template
define CONFIG_DEF
# project config file, generated by make config
# app custom config

# website host
APP_SITE=$(APP_SITE)
PERSIST_FILES = html enable404.sh gzip.conf realip.conf
APP_ACME_DOMAIN ?= www.$(APP_SITE)

# Unique traefik router name
# Container name prefix
# Value is optional, derived from APP_SITE if empty
# APP_TAG=$(APP_TAG)

# Enable tls in traefik
# Values: [false]|true
USE_TLS=$(USE_TLS)
# ------------------------------------------------------------------------------
# .env template (custom part)
# inserted in .env.sample via 'make config'
define CONFIG_CUSTOM
# ------------------------------------------------------------------------------
# app custom config, generated by make config
# db:$(USE_DB) user:$(ADD_USER)

# Certificate domain (www.APP_SITE or *.APP_SITE)
APP_ACME_DOMAIN=$(APP_ACME_DOMAIN)

# nginx image version
IMAGE_VER=$(IMAGE_VER)

endef
export CONFIG_DEF

# -----------------------------------------------------------------------------

-include $(CFG)
export

.PHONY: all up down dc init config .drone-up start-hook stop update help

all: help

# -----------------------------------------------------------------------------
## Docker-compose commands
#:

## (re)start container
up:
up: CMD=up --force-recreate -d
up: dc

## stop (and remove) container
down:
down: CMD=rm -f -s
down: dc

# $$PWD usage allows host directory mounts in child containers
# Thish works if path is the same for host, docker, docker-compose and child container
## run $(CMD) via docker-compose
dc: docker-compose.yml
@echo $(APP_TAG)
@docker run --rm -i \
-v /var/run/docker.sock:/var/run/docker.sock \
-v $$PWD:$$PWD -w $$PWD \
-e DCAPE_TAG -e DCAPE_NET -e APP_ROOT -e APP_TAG \
docker/compose:$$DC_VER \
-p $$APP_TAG --env-file $(CFG) \
$(CMD)

# ------------------------------------------------------------------------------
## Application setup
#:

## generate config file
## (if not exists)
init:
@[ -f $(CFG) ] && { echo "$(CFG) already exists. Skipping" ; exit 0 ; } || true
@echo "$$CONFIG_DEF" > $(CFG)

## generate config sample
## (if .env exists, its values will be used)
config: $(CFGSAMPLE)

$(CFGSAMPLE):
@echo "$$CONFIG_DEF" > $(CFGSAMPLE)

# -----------------------------------------------------------------------------

# Run app inside drone
# Used in .drone.yml
# Do not use outside
.drone-up:
@echo "*** $@ ***"
@[ "$$PWD" = "$(APP_ROOT)" ] && { echo "APP_ROOT == PWD, so we're not inside drone. Aborting" ; exit 1 ; } || true
@cp -pr html enable404.sh gzip.conf realip.conf $(APP_ROOT)/
@docker-compose -p $(APP_TAG) up -d --force-recreate

# -----------------------------------------------------------------------------
## dcape v1 deploy targets
#:

## start container
start-hook: CMD=up -d
start-hook: dc
@echo "*** $@ ***"

## alias for `make down`
stop: down
@echo "*** $@ ***"

# git pull is enough here
## empty command
update:
@echo "*** $@ ***"

# ------------------------------------------------------------------------------
## Other
#:

# This code handles group header and target comment with one or two lines only
## list Makefile targets
## (this is default target)
help:
@grep -A 1 -h "^## " $(MAKEFILE_LIST) \
| sed -E 's/^--$$// ; /./{H;$$!d} ; x ; s/^\n## ([^\n]+)\n(## (.+)\n)*(.+):(.*)$$/" " "\4" "\1" "\3"/' \
| sed -E 's/^" " "#" "(.+)" "(.*)"$$/"" "" "" ""\n"\1 \2" "" "" ""/' \
| xargs printf "%s\033[36m%-15s\033[0m %s %s\n"
# Find and include DCAPE/apps/drone/dcape-app/Makefile
DCAPE_COMPOSE ?= dcape-compose
DCAPE_MAKEFILE ?= $(shell docker inspect -f "{{.Config.Labels.dcape_app_makefile}}" $(DCAPE_COMPOSE))
ifeq ($(shell test -e $(DCAPE_MAKEFILE) && echo -n yes),yes)
include $(DCAPE_MAKEFILE)
else
include /opt/dcape-app/Makefile
endif
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ This project contains
* reference versions of core files for all of **dcape** applications since **dcape** v2:
* [Makefile](Makefile)
* [.drone.yml](.drone.yml)
* [docker-compose.yml](docker-compose.yml)
* [dcape-compose.yml](dcape-compose.yml)
* samples for some nginx features:
* log real user's ip from traefik data
* send gzipped static files
Expand Down
19 changes: 3 additions & 16 deletions docker-compose.yml → dcape-compose.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
# custom app config
# overrides DCAPE/apps/drone/dcape-app/docker-compose.yml

version: '2'

services:
www:
image: nginx:${IMAGE_VER}
app:
labels:
- traefik.enable=true
- dcape.traefik.tag=${DCAPE_TAG}
- traefik.http.routers.${APP_TAG}.rule=Host(`${APP_SITE:?Must be set}`) || Host(`www.${APP_SITE}`)
# TLS support
- traefik.http.routers.${APP_TAG}.tls=${USE_TLS}
- traefik.http.routers.${APP_TAG}.tls.certresolver=letsEncrypt
- traefik.http.routers.${APP_TAG}.tls.domains[0].main=${APP_SITE}
- traefik.http.routers.${APP_TAG}.tls.domains[0].sans=${APP_ACME_DOMAIN}
# Redirect www.host -> host
- traefik.http.middlewares.${APP_TAG}-redirwww.redirectregex.regex=^http(s?)://www.${APP_SITE}/(.*)
- traefik.http.middlewares.${APP_TAG}-redirwww.redirectregex.replacement=http$${1}://${APP_SITE}/$${2}
- traefik.http.routers.${APP_TAG}.middlewares=${APP_TAG}-redirwww
volumes:
- /etc/timezone:/etc/timezone:ro
- /etc/localtime:/etc/localtime:ro
# Show user's rel IP in logs
- ${APP_ROOT}/realip.conf:/etc/nginx/conf.d/realip.conf:ro
# Send gzipped static
Expand All @@ -28,11 +23,3 @@ services:
- ${APP_ROOT}/enable404.sh:/docker-entrypoint.d/enable404.sh:ro
# Attach site content
- ${APP_ROOT}/html:/usr/share/nginx/html:ro
restart: always
networks:
- lan

networks:
lan:
external:
name: ${DCAPE_NET}

0 comments on commit a095b1c

Please sign in to comment.