Created
September 16, 2019 02:30
-
-
Save duduribeiro/18e0f119f395eaf0c14a187cfa1912ed to your computer and use it in GitHub Desktop.
Makefile
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
default: all | |
.PHONY: default all fetch_dump | |
date := `date '+%Y-%m-%d'` | |
TARGET_IMAGE ?= my_app | |
all: check_vars fetch_dump generate_image push_to_registry clean finished | |
check_vars: | |
@test -n "$(DB_ENDPOINT)" || (echo "You need to set DB_ENDPOINT environment variable" >&2 && exit 1) | |
@test -n "$(DB_NAME)" || (echo "You need to set DB_NAME environment variable" >&2 && exit 1) | |
@test -n "$(DESTINATION_REPOSITORY)" || (echo "You need to set DESTINATION_REPOSITORY environment variable" >&2 && exit 1) | |
fetch_dump: DB_USER ?= postgres | |
fetch_dump: | |
@echo "" | |
@echo "====== Fetching remote dump ======" | |
@PGPASSWORD="$(DB_PASSWORD)" pg_dump -h $(DB_ENDPOINT) -d $(DB_NAME) -U $(DB_USER) > dump.sql | |
generate_image: | |
generate_image: | |
@docker build . -t $(TARGET_IMAGE):latest -t $(DESTINATION_REPOSITORY)/$(TARGET_IMAGE):latest -t $(DESTINATION_REPOSITORY)/$(TARGET_IMAGE):$(date) | |
push_to_registry: | |
@echo "" | |
@echo "====== Pushing image to repository ======" | |
@docker push $(DESTINATION_REPOSITORY)/$(TARGET_IMAGE) | |
clean: | |
@echo "" | |
@echo "====== Cleaning used files ======" | |
@rm -f dump.sql | |
finished: | |
@echo "" | |
@echo "Finished with success. Pushed image to $(DESTINATION_REPOSITORY)/$(TARGET_IMAGE)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment