Last active
February 17, 2020 03:05
-
-
Save peter-dolkens/4b89c5a732ef1ea4fcb714252037e4ba to your computer and use it in GitHub Desktop.
Sample Makefile - Jekyll Blog
This file contains hidden or 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
| SHELL := /usr/bin/env bash | |
| .PHONY : all | |
| SECRETS_ENV_FILE=environment_variables/secrets//.env | |
| GLOBAL_ENV_FILE=environment_variables/global//.env | |
| include ${SECRETS_ENV_FILE} | |
| include ${GLOBAL_ENV_FILE} | |
| ############################################################################### | |
| # HELP | |
| ############################################################################### | |
| # COLORS | |
| GREEN := $(shell tput -Txterm setaf 2) | |
| YELLOW := $(shell tput -Txterm setaf 3) | |
| WHITE := $(shell tput -Txterm setaf 7) | |
| RESET := $(shell tput -Txterm sgr0) | |
| TARGET_MAX_CHAR_NUM=20 | |
| ## Show help | |
| help: | |
| @echo '' | |
| @echo 'Usage:' | |
| @echo ' make ${YELLOW}<target>${RESET} ${GREEN}<description>${RESET}' | |
| @echo '' | |
| @echo 'Targets:' | |
| @awk '/^[a-zA-Z\-_0-9]+:/ { \ | |
| helpMessage = match(lastLine, /^## (.*)/); \ | |
| if (helpMessage) { \ | |
| helpCommand = substr($$1, 0, index($$1, ":")); \ | |
| helpMessage = substr(lastLine, RSTART + 3, RLENGTH); \ | |
| printf " ${YELLOW}%-$(TARGET_MAX_CHAR_NUM)s${RESET} ${GREEN}%s${RESET}\n", helpCommand, helpMessage; \ | |
| } \ | |
| } \ | |
| { lastLine = $$0 }' $(MAKEFILE_LIST) | |
| ## Make local docker image for deployment | |
| image: | |
| docker build --build-arg WORKING_DIR=${WORKING_DIR} \ | |
| -t ${DEPLOY_IMAGE_NAME} . | |
| ## Step into local image for debugging | |
| debug: | |
| MSYS_NO_PATHCONV=1 \ | |
| MSYS2_ARG_CONV_EXC="*" \ | |
| docker run -it --env-file ${SECRETS_ENV_FILE} \ | |
| --env-file ${GLOBAL_ENV_FILE} \ | |
| --env ACTION=debug \ | |
| -v data:/data/teamcity_server/datadir \ | |
| -v logs:/opt/teamcity/logs \ | |
| -v $(shell pwd):${WORKING_DIR} \ | |
| --rm ${DEPLOY_IMAGE_NAME} \ | |
| bash | |
| ## Launch TeamCity on port 8080 | |
| launch: | |
| MSYS_NO_PATHCONV=1 \ | |
| MSYS2_ARG_CONV_EXC="*" \ | |
| docker run -it --name teamcity-linux-server \ | |
| --env-file ${SECRETS_ENV_FILE} \ | |
| --env-file ${GLOBAL_ENV_FILE} \ | |
| -v data:/data/teamcity_server/datadir \ | |
| -v logs:/opt/teamcity/logs \ | |
| -p ${SERVER_PORT}:8111 \ | |
| ${DEPLOY_IMAGE_NAME} | |
| ## Cleanup TeamCity volumes and containers | |
| cleanup: | |
| -docker stop teamcity-linux-server | |
| -docker rm teamcity-linux-server | |
| -docker volume rm logs | |
| -docker volume rm data |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment