Compare commits
19 commits
more-tests
...
master
Author | SHA1 | Date | |
---|---|---|---|
2599224295 | |||
5f6b651e83 | |||
105e14a085 | |||
27f15d441a | |||
|
ea3f38010c | ||
|
0071d31d26 | ||
|
b299948bf8 | ||
|
99f4568e7e | ||
|
9753ac7c67 | ||
|
1611cc73df | ||
8f527a16a3 | |||
deb24ec5ae | |||
938e276821 | |||
|
cd9575d0a7 | ||
|
380ac9c214 | ||
|
35070eff29 | ||
|
4d8672aa8b | ||
e5f6c11ea9 | |||
37bb6e9c12 |
16 changed files with 60 additions and 66 deletions
2
LICENSE
2
LICENSE
|
@ -1,6 +1,6 @@
|
||||||
MIT License
|
MIT License
|
||||||
Copyright (c) 2022 Andreas Neue <an@dnix.de>
|
Copyright (c) 2022 Andreas Neue <an@dnix.de>
|
||||||
Copyright (c) 2022-23 the make-deploy authors (see CONTRIBUTORS)
|
Copyright (c) 2022-25 the make-deploy authors (see CONTRIBUTORS)
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
this software and associated documentation files (the "Software"), to deal in
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
|
|
24
Makefile
24
Makefile
|
@ -1,4 +1,7 @@
|
||||||
DEPLOY_START_DELAY = 0
|
DEPLOY_START_DELAY = 0
|
||||||
|
DEPLOY_PROJECT_DIR =
|
||||||
|
|
||||||
|
MANDATORY = DEPLOY_NAME DEPLOY_HOSTS DEPLOY_PATH SSH_USER
|
||||||
|
|
||||||
-include secrets.mk
|
-include secrets.mk
|
||||||
include config.mk
|
include config.mk
|
||||||
|
@ -9,20 +12,19 @@ ifeq ($(DEPLOY_TYPE), copy)
|
||||||
DEPLOY_TYPE = simple
|
DEPLOY_TYPE = simple
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
project_dir = $(DEPLOY_PATH)/$(DEPLOY_NAME)$(DEPLOY_PROJECT_DIR)
|
||||||
|
|
||||||
include make-deploy/$(DEPLOY_TYPE).mk
|
include make-deploy/$(DEPLOY_TYPE).mk
|
||||||
|
|
||||||
.PHONY: self-update mandatory cleanup prerequisites prepare build test deploy pre-deploy post-deploy pre-local post-local upload pull start stop restart reload
|
.PHONY: self-update mandatory cleanup prerequisites prepare build test deploy pre-deploy post-deploy pre-local post-local upload pull start stop restart reload notify
|
||||||
|
|
||||||
self-update:
|
self-update:
|
||||||
@- git submodule update --remote
|
@- git submodule update --remote
|
||||||
|
|
||||||
deploy: mandatory cleanup prepare build test upload pre-deploy pre-local pull start post-local post-deploy reload
|
deploy: mandatory cleanup prepare build test upload pre-deploy pre-local pull start notify post-local post-deploy reload
|
||||||
|
|
||||||
mandatory:
|
mandatory:
|
||||||
@- echo "\n### mandatory check"
|
@- echo "\n### mandatory check"
|
||||||
ifndef MANDATORY-$(DEPLOY_TYPE)
|
|
||||||
$(error MANDATORY-$(DEPLOY_TYPE) is not defined)
|
|
||||||
endif
|
|
||||||
@ $(foreach var,$(MANDATORY), \
|
@ $(foreach var,$(MANDATORY), \
|
||||||
if test -z "${$(var)}"; then \
|
if test -z "${$(var)}"; then \
|
||||||
echo "Missing mandatory variable: $(var)"; \
|
echo "Missing mandatory variable: $(var)"; \
|
||||||
|
@ -123,7 +125,17 @@ pull: pull-$(DEPLOY_TYPE)
|
||||||
start: start-$(DEPLOY_TYPE)
|
start: start-$(DEPLOY_TYPE)
|
||||||
|
|
||||||
stop: stop-$(DEPLOY_TYPE)
|
stop: stop-$(DEPLOY_TYPE)
|
||||||
|
|
||||||
|
notify:
|
||||||
|
ifdef DEPLOY_NOTIFY_HOSTS
|
||||||
|
ifdef DEPLOY_NOTIFY_MAIL
|
||||||
|
ifdef DEPLOY_NOTIFY_MSG
|
||||||
|
@- echo "\n### notify"
|
||||||
|
@- echo "$$DEPLOY_NOTIFY_MSG :: Please deploy manually on following hosts: $$DEPLOY_NOTIFY_HOSTS" | mail -s "make-deploy notification" $(DEPLOY_MAIL)
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
logs: logs-$(DEPLOY_TYPE)
|
logs: logs-$(DEPLOY_TYPE)
|
||||||
|
|
||||||
restart: restart-$(DEPLOY_TYPE)
|
restart: restart-$(DEPLOY_TYPE)
|
||||||
|
|
|
@ -2,8 +2,6 @@
|
||||||
|
|
||||||
A simple Makefile based deployment system.
|
A simple Makefile based deployment system.
|
||||||
|
|
||||||
**make-deploy** was initially hosted at https://git.dnix.de/an/make-deploy. Since it has become heavily used at chefkoch.de for system deployments, and lots of code is committed there, we moved the repo to https://git.chefkoch.net/pub/make-deploy. A mirror still exists at https://git.dnix.de/mirror/make-deploy.
|
|
||||||
|
|
||||||
**make-deploy** is licensed under the terms of the MIT-License. See [LICENSE](LICENSE) for info.
|
**make-deploy** is licensed under the terms of the MIT-License. See [LICENSE](LICENSE) for info.
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
@ -24,6 +22,7 @@ Example `config.mk`:
|
||||||
DEPLOY_PATH = /srv
|
DEPLOY_PATH = /srv
|
||||||
DEPLOY_TYPE = compose
|
DEPLOY_TYPE = compose
|
||||||
DEPLOY_HOSTS = server01.example.com server02.example.com
|
DEPLOY_HOSTS = server01.example.com server02.example.com
|
||||||
|
DEPLOY_SUBPATH = my-sub-path
|
||||||
|
|
||||||
DOCKER_IMAGE = dr.example.com/my-project:latest
|
DOCKER_IMAGE = dr.example.com/my-project:latest
|
||||||
DOCKER_LOGIN = 1
|
DOCKER_LOGIN = 1
|
||||||
|
@ -36,6 +35,8 @@ Example `secrets.mk`:
|
||||||
DOCKER_USER = root
|
DOCKER_USER = root
|
||||||
DOCKER_PASS = secret1234
|
DOCKER_PASS = secret1234
|
||||||
|
|
||||||
|
`DEPLOY_SUBPATH` is used to define a location for `DEPLOY_TYPE` = compose that states where the docker-compose.yml is placed at. If that variable is undefined, it is expected to be in projects root.
|
||||||
|
|
||||||
By setting `DEPLOY_CONFIG_OVERRIDE`, an alternative config can be loaded to override existing configuration settings. This is useful in script calling make deploy or in a `.gitlab-ci.yml` in order to control settings for different targets.
|
By setting `DEPLOY_CONFIG_OVERRIDE`, an alternative config can be loaded to override existing configuration settings. This is useful in script calling make deploy or in a `.gitlab-ci.yml` in order to control settings for different targets.
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
2
apt.mk
2
apt.mk
|
@ -1,4 +1,4 @@
|
||||||
MANDATORY-apt = DEPLOY_HOSTS SSH_USER APT_PACKAGES DEPLOY_NAME
|
MANDATORY = $(shell printenv MANDATORY) APT_PACKAGES
|
||||||
|
|
||||||
pull-apt:
|
pull-apt:
|
||||||
# nop
|
# nop
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
MANDATORY-compose-file = DEPLOY_HOSTS DEPLOY_TYPE SSH_USER DEPLOY_COMPOSE_FILE DEPLOY_COMPOSE_PROJECT
|
MANDATORY = $(shell printenv MANDATORY) SSH_USER DEPLOY_COMPOSE_FILE DEPLOY_COMPOSE_PROJECT
|
||||||
|
|
||||||
ifndef DOCKER_LOGIN
|
ifndef DOCKER_LOGIN
|
||||||
DOCKER_LOGIN = 0
|
DOCKER_LOGIN = 0
|
||||||
|
|
41
compose.mk
41
compose.mk
|
@ -1,16 +1,18 @@
|
||||||
MANDATORY-compose = DEPLOY_HOSTS DEPLOY_TYPE SSH_USER DEPLOY_NAME
|
ifdef DOCKER_LOGIN
|
||||||
|
MANDATORY = $(shell printenv MANDATORY) DOCKER_USER DOCKER_PASS DOCKER_REGISTRY
|
||||||
|
endif
|
||||||
|
|
||||||
ifndef DOCKER_LOGIN
|
ifndef DOCKER_LOGIN
|
||||||
DOCKER_LOGIN = 0
|
DOCKER_LOGIN = 0
|
||||||
endif
|
endif
|
||||||
|
|
||||||
pull-compose:
|
pull-compose:
|
||||||
@- echo "\n### pulling image(s)"
|
@echo "\n### pulling image(s)"
|
||||||
@- $(foreach host,$(DEPLOY_HOSTS), \
|
$(foreach host,$(DEPLOY_HOSTS), \
|
||||||
echo "$(host)"; \
|
echo "$(host)"; \
|
||||||
if test $(DOCKER_LOGIN) -eq 1 ; \
|
if test "$(DOCKER_LOGIN)" = "1" ; \
|
||||||
then \
|
then \
|
||||||
echo "\n#### perfom docker login with user $(DOCKER_USER) on $(DOCKER_REGISTRY)"; \
|
echo "\n#### perform docker login with user $(DOCKER_USER) on $(DOCKER_REGISTRY)"; \
|
||||||
ssh $(SSH_USER)@$(host) "docker login -u $(DOCKER_USER) -p $(DOCKER_PASS) $(DOCKER_REGISTRY)"; \
|
ssh $(SSH_USER)@$(host) "docker login -u $(DOCKER_USER) -p $(DOCKER_PASS) $(DOCKER_REGISTRY)"; \
|
||||||
fi; \
|
fi; \
|
||||||
if test -n "$(DOCKER_IMAGE)" ; \
|
if test -n "$(DOCKER_IMAGE)" ; \
|
||||||
|
@ -20,27 +22,24 @@ pull-compose:
|
||||||
)
|
)
|
||||||
|
|
||||||
start-compose:
|
start-compose:
|
||||||
@- echo "\n### starting service(s)"
|
@echo "\n### starting service(s)"
|
||||||
@- $(foreach host,$(DEPLOY_HOSTS), \
|
$(foreach host,$(DEPLOY_HOSTS), \
|
||||||
echo "$(host)"; \
|
echo "$(host)"; \
|
||||||
ssh $(SSH_USER)@$(host) "cd $(DEPLOY_PATH)/$(DEPLOY_NAME); docker-compose up -d"; \
|
ssh $(SSH_USER)@$(host) "cd $(project_dir); docker-compose up -d"; \
|
||||||
sleep $(DEPLOY_START_DELAY); \
|
sleep $(DEPLOY_START_DELAY); \
|
||||||
)
|
)
|
||||||
|
|
||||||
stop-compose:
|
|
||||||
@- echo "\n### stopping service(s)"
|
|
||||||
@- $(foreach host,$(DEPLOY_HOSTS), \
|
|
||||||
echo "$(host)"; \
|
|
||||||
ssh $(SSH_USER)@$(host) "cd $(DEPLOY_PATH)/$(DEPLOY_NAME); docker-compose down"; \
|
|
||||||
)
|
|
||||||
|
|
||||||
logs-compose:
|
logs-compose:
|
||||||
@- echo "\n### logs"
|
@echo "\n### logs"
|
||||||
@- ssh $(SSH_USER)@$(host) "cd $(DEPLOY_PATH)/$(DEPLOY_NAME); docker-compose logs -f $(service)"
|
$(foreach host,$(DEPLOY_HOSTS), \
|
||||||
|
|
||||||
restart-compose:
|
|
||||||
@- $(foreach host,$(DEPLOY_HOSTS), \
|
|
||||||
echo "$(host)"; \
|
echo "$(host)"; \
|
||||||
ssh $(SSH_USER)@$(host) "cd $(DEPLOY_PATH)/$(DEPLOY_NAME); docker-compose restart"; \
|
ssh $(SSH_USER)@$(host) "cd $(project_dir); docker-compose logs -f $(service)"; \
|
||||||
|
)
|
||||||
|
|
||||||
|
restart-compose:
|
||||||
|
@echo "\n### restarting service(s)"
|
||||||
|
$(foreach host,$(DEPLOY_HOSTS), \
|
||||||
|
echo "$(host)"; \
|
||||||
|
ssh $(SSH_USER)@$(host) "cd $(project_dir); docker-compose restart"; \
|
||||||
sleep $(DEPLOY_START_DELAY); \
|
sleep $(DEPLOY_START_DELAY); \
|
||||||
)
|
)
|
||||||
|
|
2
cron.mk
2
cron.mk
|
@ -1,4 +1,4 @@
|
||||||
MANDATORY-cron = true
|
MANDATORY = $(shell printenv MANDATORY) CRON_USER
|
||||||
|
|
||||||
start-cron:
|
start-cron:
|
||||||
@- echo "\n### starting..."
|
@- echo "\n### starting..."
|
||||||
|
|
2
helm.mk
2
helm.mk
|
@ -1,4 +1,4 @@
|
||||||
MANDATORY-helm = K8S_CONTEXT HELM_CHART_NAME HELM_CHART_PATH HELM_VALUES_FILE NAMESPACE
|
MANDATORY = $(shell printenv MANDATORY) K8S_CONTEXT HELM_CHART_NAME HELM_CHART_PATH HELM_VALUES_FILE K8S_NAMESPACE
|
||||||
# helm
|
# helm
|
||||||
#
|
#
|
||||||
# deploys helm charts on k8s via helm
|
# deploys helm charts on k8s via helm
|
||||||
|
|
7
k8s.mk
7
k8s.mk
|
@ -2,15 +2,16 @@
|
||||||
#
|
#
|
||||||
# deploys k8s
|
# deploys k8s
|
||||||
|
|
||||||
MANDATORY-k8s = K8S_CONTEXT
|
MANDATORY = $(shell printenv MANDATORY) K8S_CONTEXT
|
||||||
|
K8S_MANIFEST_FILENAME ?= kubernetes.yaml
|
||||||
|
|
||||||
start-k8s:
|
start-k8s:
|
||||||
@- echo "\n### starting deployment with k8s"
|
@- echo "\n### starting deployment with k8s"
|
||||||
@- echo "\n### setting kubernetes context to $(K8S_CONTEXT)"
|
@- echo "\n### setting kubernetes context to $(K8S_CONTEXT)"
|
||||||
@ kubectl config use-context $(K8S_CONTEXT)
|
@ kubectl config use-context $(K8S_CONTEXT)
|
||||||
|
|
||||||
@- echo "\n### run kubectl apply -f kubernetes.yaml and secrets.yaml"
|
@- echo "\n### run kubectl apply -f $(K8S_MANIFEST_FILENAME) and secrets.yaml"
|
||||||
@ cat kubernetes.yaml secrets.yaml | envsubst | kubectl apply -f -
|
@ cat $(K8S_MANIFEST_FILENAME) secrets.yaml | envsubst | kubectl apply $(K8S_ADDITIONAL_PARAMS) -f -
|
||||||
|
|
||||||
pull-k8s:
|
pull-k8s:
|
||||||
# nop
|
# nop
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
MANDATORY-kustomize = K8S_CONTEXT KUSTOMIZE_FOLDER NAMESPACE
|
MANDATORY = $(shell printenv MANDATORY) K8S_CONTEXT KUSTOMIZE_FOLDER NAMESPACE
|
||||||
# kustomize
|
# kustomize
|
||||||
#
|
#
|
||||||
# this uses kustomize to install stuff on k8s
|
# this uses kustomize to install stuff on k8s
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
MANDATORY-copy = DEPLOY_TYPE DEPLOY_HOSTS SSH_USER DEPLOY_PATH DEPLOY_NAME
|
# simple
|
||||||
MANDATORY-simple = $(MANDATORY-copy)
|
|
||||||
|
|
||||||
# copy
|
|
||||||
#
|
#
|
||||||
# this just rsyncs the stuff to the remote server(s) and runs
|
# this just rsyncs the stuff to the remote server(s) and runs
|
||||||
# build.sh, pre-/post-deploy, pre-/post-local, start.sh, etc.
|
# build.sh, pre-/post-deploy, pre-/post-local, start.sh, etc.
|
||||||
|
|
||||||
|
ifndef DEPLOY_StART_DELAY
|
||||||
|
DEPLOY_START_DELAY = 0
|
||||||
|
endif
|
||||||
|
|
||||||
pull-simple:
|
pull-simple:
|
||||||
# nop
|
# nop
|
||||||
|
|
||||||
|
|
2
swarm.mk
2
swarm.mk
|
@ -1,5 +1,3 @@
|
||||||
MANDATORY-swarm = DEPLOY_HOSTS DEPLOY_TYPE TAG
|
|
||||||
|
|
||||||
pull-swarm:
|
pull-swarm:
|
||||||
|
|
||||||
start-swarm:
|
start-swarm:
|
||||||
|
|
14
test.sh
14
test.sh
|
@ -30,7 +30,7 @@ function test_with_minimal_vars_compose(){
|
||||||
cp $TESTS/compose_config.mk config.mk
|
cp $TESTS/compose_config.mk config.mk
|
||||||
cp $TESTS/docker-compose.yml .
|
cp $TESTS/docker-compose.yml .
|
||||||
make deploy
|
make deploy
|
||||||
rm -f docker-compose.yml config.mk
|
rm -f docker-compose.yml
|
||||||
}
|
}
|
||||||
|
|
||||||
function test_with_minimal_vars_compose_file(){
|
function test_with_minimal_vars_compose_file(){
|
||||||
|
@ -38,16 +38,7 @@ function test_with_minimal_vars_compose_file(){
|
||||||
cp $TESTS/compose_file_config.mk config.mk
|
cp $TESTS/compose_file_config.mk config.mk
|
||||||
cp $TESTS/docker-compose.yml .
|
cp $TESTS/docker-compose.yml .
|
||||||
make deploy
|
make deploy
|
||||||
rm -f docker-compose.yml config.mk
|
rm -f docker-compose.yml
|
||||||
}
|
|
||||||
|
|
||||||
function test_with_minimal_vars_compose_and_tag(){
|
|
||||||
echo "::::::::: $FUNCNAME ::::::::::::"
|
|
||||||
cp $TESTS/compose_config.tag.mk config.mk
|
|
||||||
cp $TESTS/docker-compose.tag.yml docker-compose.yml
|
|
||||||
echo "TAG=3.17" > .env
|
|
||||||
make deploy
|
|
||||||
rm -f docker-compose.yml config.mk
|
|
||||||
}
|
}
|
||||||
|
|
||||||
prepdir
|
prepdir
|
||||||
|
@ -55,6 +46,5 @@ prepdir
|
||||||
test_with_minimal_vars_apt
|
test_with_minimal_vars_apt
|
||||||
test_with_minimal_vars_compose
|
test_with_minimal_vars_compose
|
||||||
test_with_minimal_vars_compose_file
|
test_with_minimal_vars_compose_file
|
||||||
test_with_minimal_vars_compose_and_tag
|
|
||||||
|
|
||||||
cleandir
|
cleandir
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
DEPLOY_NAME = make-deploy-test-compose-tag
|
|
||||||
DEPLOY_PATH = /tmp
|
|
||||||
DEPLOY_HOSTS = localhost
|
|
||||||
DEPLOY_TYPE = compose
|
|
||||||
SSH_USER = $(USER)
|
|
|
@ -1,4 +0,0 @@
|
||||||
services:
|
|
||||||
curl:
|
|
||||||
image: "alpine:${TAG}"
|
|
||||||
command: cat /etc/os-release
|
|
3
tf.mk
3
tf.mk
|
@ -1,4 +1,5 @@
|
||||||
MANDATORY-tf =
|
MANDATORY = $(shell printenv MANDATORY) TF_FLAGS
|
||||||
|
|
||||||
# tf
|
# tf
|
||||||
#
|
#
|
||||||
# deploys via tf apply
|
# deploys via tf apply
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue