-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
33 additions
and
147 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 |
---|---|---|
@@ -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 |
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