Skip to content

Commit

Permalink
Update registry makefiles
Browse files Browse the repository at this point in the history
  • Loading branch information
kmmndr committed Nov 14, 2020
1 parent 4645442 commit 3637c35
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 18 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Env file
*.env

docker-compose.override.yml
22 changes: 6 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,20 +1,10 @@
all: up passwd
default: help
include *.mk

.PHONY: pull
pull:
./remote.sh docker-compose pull

.PHONY: up
up: pull
./remote.sh docker-compose up -d

.PHONY: clean
clean:
./remote.sh docker-compose down
./remote.sh docker-compose kill
./remote.sh docker-compose rm
start: docker-compose-start ##- Start
deploy: docker-compose-deploy ##- Deploy (start remotely)

.PHONY: passwd
passwd:
passwd: environment
@echo "Changing password for user 'docker'"
./remote.sh docker-compose run --entrypoint htpasswd registry -cB /auth/htpasswd docker
$(load_env); docker-compose run --entrypoint htpasswd registry -cB /auth/htpasswd docker
35 changes: 35 additions & 0 deletions docker-compose.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
compose_files :=

.PHONY: docker-compose-pull
docker-compose-pull: environment ##- Pull latest containers
$(info *** Pulling containers ***)
-$(load_env); docker-compose ${compose_files} pull

.PHONY: docker-compose-build
docker-compose-build: environment ##- Build containers
$(info *** Building containers ***)
$(load_env); docker-compose ${compose_files} build

.PHONY: docker-compose-start
docker-compose-start: environment ##- Start containers
$(info *** Starting containers ***)
$(load_env); docker-compose ${compose_files} up -d

.PHONY: docker-compose-stop
docker-compose-stop: environment ##- Stop containers
$(info *** Stopping containers ***)
$(load_env); docker-compose ${compose_files} down

.PHONY: docker-compose-logs
docker-compose-logs: environment ##- Print containers logs
$(info *** Printing containers logs ***)
$(load_env); docker-compose ${compose_files} logs -f

.PHONY: docker-compose-check-remote-env
docker-compose-check-remote-env: environment ##- Check environment variables
$(info *** Checking env variables ***)
$(load_env); test $$DOCKER_HOST
$(load_env); test $$COMPOSE_PROJECT_NAME

.PHONY: docker-compose-deploy
docker-compose-deploy: docker-compose-check-remote-env docker-compose-start ##- Deploy containers
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ services:
- "traefik.port=5000"
- "traefik.enable=true"
# - "traefik.docker.network=traefik_network"
- "traefik.http.routers.registry.rule=Host(`${HOSTNAME:-localhost}`)"
- "traefik.http.routers.registry.rule=Host(`${APP_FQDN:-localhost}`)"
- "traefik.http.routers.registry.entrypoints=web"
- "traefik.http.routers.registry-tls.rule=Host(`${HOSTNAME:-localhost}`)"
- "traefik.http.routers.registry-tls.rule=Host(`${APP_FQDN:-localhost}`)"
- "traefik.http.routers.registry-tls.entrypoints=websecure"
- "traefik.http.routers.registry-tls.tls.certresolver=default"

Expand Down
25 changes: 25 additions & 0 deletions env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/sh
set -eu

stage=${1:-'default'}

cat <<EOF
COMPOSE_PROJECT_NAME=registry
EOF

case "$stage" in
"default")
cat <<-EOF
EOF
;;

"production")
cat <<-EOF
EOF
;;

*)
echo "Unknown stage $stage" >&2
exit 1
;;
esac
30 changes: 30 additions & 0 deletions environment.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
stage ?= default

.PHONY: environment
environment: ${stage}.env ##- Define environment variables
@test ${stage} || (echo 'stage not set'; exit 1)
@$(eval ENV_FILE?=./${stage}.env)
@$(eval load_env=set -a;. ${ENV_FILE};set +a)

%.env: env.sh
@echo "Env file $@ is not found or obsolete"
@echo "Please update it (review and touch, or call make [-e stage=${stage}] generate-env)"; exit 1

.PHONY: generate-env
generate-env: env.sh ##- Generate environment file ${stage}.env
@test ${stage} || (echo 'stage not set'; exit 1)
@./env.sh ${stage} > ${stage}.env
@$(eval OVERRIDE_ENV_FILE?=./override.env)
@[ -f "${OVERRIDE_ENV_FILE}" ] && echo "Appending environment override"; true
@(([ -x "${OVERRIDE_ENV_FILE}" ] && "${OVERRIDE_ENV_FILE}") || \
([ -r "${OVERRIDE_ENV_FILE}" ] && cat "${OVERRIDE_ENV_FILE}") || true) | tee -a ${stage}.env
@echo "Environment file ${stage}.env generated"

.PHONY: dump-env
dump-env: environment ##- Dump environment
@echo "dump ENV_FILE: ${ENV_FILE}"
$(load_env); env

.PHONY: shell-env
shell-env: environment ##- Start a local shell with environment
@$(load_env); PS1='env$$ ' ${SHELL}
4 changes: 4 additions & 0 deletions help.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
help: ##- Show this help.
@echo 'Usage: make <target> (see target list below)'
@echo
@sed -e '/#\{2\}-/!d; s/\\$$//; s/:[^#\t]*/:/; s/#\{2\}-*//' $(MAKEFILE_LIST)

0 comments on commit 3637c35

Please sign in to comment.