Skip to content

Instantly share code, notes, and snippets.

@llitfkitfk
Last active December 11, 2019 07:48
Show Gist options
  • Save llitfkitfk/da78fae7bba1e2948664f8dadb13ec1b to your computer and use it in GitHub Desktop.
Save llitfkitfk/da78fae7bba1e2948664f8dadb13ec1b to your computer and use it in GitHub Desktop.
makefile collection
.DEFAULT_GOAL := help
.PHONY: help
help: ## list command:
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
.PHONY: start
start: ## start command
@echo "start"
APP_NAME=app
APP_BINARY=bin/$(APP_NAME)
APP_BINARY_UNIX=bin/$(APP_NAME)_unix_amd64
APP_BINARY_DARWIN=bin/$(APP_NAME)_darwin_amd64
APP_BINARY_WINDOWS=bin/$(APP_NAME)_windows_amd64.exe
.PHONY: run
run: build ## run
./$(APP_BINARY)
.PHONY: test
test: ## test
go test -v ./...
.PHONY: build
build: ## build
go build -o $(APP_BINARY) -v cmd/$(APP_NAME)/main.go
.PHONY: clean
clean: ## clean
rm -f $(APP_BINARY)
rm -f $(APP_BINARY_DARWIN)
rm -f $(APP_BINARY_UNIX)
rm -f $(APP_BINARY_WINDOWS)
.PHONY: run
run: build ## run
./$(APP_BINARY)
.PHONY: build-all
build-all: build-mac build-linux build-win
.PHONY: build-win
build-win: ## build win
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -o $(APP_BINARY_WINDOWS) -v cmd/$(APP_NAME)/main.go
.PHONY: build-mac
build-mac: ## build mac
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -o $(APP_BINARY_DARWIN) -v cmd/$(APP_NAME)/main.go
.PHONY: build-linux
build-linux: ## build linux
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o $(APP_BINARY_UNIX) -v cmd/$(APP_NAME)/main.go
.PHONY: build-arm
build-arm: ## build arm
CGO_ENABLED=0 GOOS=linux GOARM=7 GOARCH=arm go build -o $(APP_BINARY_ARM) -v cmd/$(APP_NAME)/main.go
APP_NAME=app
IMAGE_NAME=$(APP_NAME)
DOCKER_REPO=registry.swarm.staging.wizmacau.com/bevtech
IMAGE_VERSION=$(shell date +'%y.%m.%d')-$(shell git rev-parse --short HEAD)
.PHONY: build-docker
build-docker: ## Build the image
docker build -t $(IMAGE_NAME) .
.PHONY: docker
docker: build-docker tag-docker ## publish the `latest` taged container to docker hub
@echo 'publish latest to $(DOCKER_REPO)'
docker push $(DOCKER_REPO)/$(IMAGE_NAME):latest
@echo 'publish $(IMAGE_VERSION) to $(DOCKER_REPO)'
docker push $(DOCKER_REPO)/$(IMAGE_NAME):$(IMAGE_VERSION)
.PHONY: tag-docker
tag-docker: ## Generate container `{version}` tag
@echo 'create tag latest'
docker tag $(IMAGE_NAME) $(DOCKER_REPO)/$(IMAGE_NAME):latest
@echo 'create tag $(IMAGE_VERSION)'
docker tag $(IMAGE_NAME) $(DOCKER_REPO)/$(IMAGE_NAME):$(IMAGE_VERSION)
version: ## Output the current version
@echo $(IMAGE_VERSION)
.DEFAULT_GOAL := help
PLAYBOOKS_DOCKER_PREREQUISITE=10-docker-prerequisite.yml
TEST_PLAYBOOKS=$(PLAYBOOKS_WEB_SERVER_PREREQUISITE)
ANSIBLE_PLAYBOOK=ansible-playbook
# dry run or not
CHECKED?=--check -v
PLAYBOOKS_CHECK=$(CHECKED)
# using tags
TAGS?=all
PLAYBOOKS_TAGS=--tags $(TAGS)
PLAYBOOKS_CMD=$(ANSIBLE_PLAYBOOK) $(PLAYBOOKS_CHECK) $(PLAYBOOKS_TAGS)
########## info ##########
.PHONY: info-node
info-node: ## docker node info
@echo ">>> Info: docker node"
@ansible docker_swarm_deploy -m command -a "docker node ls"
.PHONY: info-labels
info-labels: ## docker labels info
@echo ">>> Info: docker service"
@ansible docker -m command -a "docker node inspect -f \{\{'.Spec.Labels'\}\} self"
.PHONY: info-service
info-service: ## docker service info
@echo ">>> Info: docker service"
@ansible docker_swarm_deploy -m command -a "docker service ls"
.PHONY: info-container
info-container: ## docker container info
@echo ">>> Info: docker containers"
ansible docker -m command -a "docker container ls -a"
.PHONY: info-network
info-network: ## docker network info
@echo ">>> Info: docker network"
@ansible docker -m command -a "docker network ls"
.PHONY: info-volume
info-volume: ## docker volume info
@echo ">>> Info: docker volume"
@ansible docker -m command -a "docker volume ls"
########## debug ##########
.PHONY: debug
debug: ## debug ansible playbooks
$(PLAYBOOKS_CMD) _debug.yml
########## clean ##########
.PHONY: clean-all
clean-all: clean-web-server clean-mysql-cluster clean-gfs-client clean-gfs-server clean-container clean-network clean-volume clean-docker ## clean all
.PHONY: clean-docker
clean-docker: ## clean docker daemon
@echo ">>> Waring: remove docker daemon"
-ansible docker -m command -a "systemctl stop docker"
-ansible docker -m file -a "path=/data/docker state=absent"
-ansible docker -m file -a "path=/var/lib/docker state=absent"
-ansible docker -m package -a "name=docker-ce state=absent"
.PHONY: clean-container
clean-container: ## clean docker container
@echo ">>> Waring: remove stopped container"
-ansible docker -m command -a "docker container prune -f"
.PHONY: clean-network
clean-network: ## clean docker network
@echo ">>> Waring: remove network"
-ansible docker -m command -a "docker network prune -f"
.PHONY: clean-volume
clean-volume: ## clean docker volume
@echo ">>> Waring: remove volume"
-ansible docker -m command -a "docker volume prune -f"
########## tunnel ##########
.PHONY: tunnel
tunnel: ## tunnel all
ssh -fN -L xxx:xxx.xxx.xxx.xxx:xx -p xxxx root@xxx.xxx.xxx.xxx
########## make sure ##########
PROMPT_MESSAGE?=Continue
.PHONY: sure
sure:
@read -p "$(PROMPT_MESSAGE)? [y/N]" yesOrNo; echo $$yesOrNo; \
if [ "$$yesOrNo" == "y" ] || [ "$$yesOrNo" == "Y" ]; then \
echo ""; \
else \
exit; \
fi
.PHONY: help
help:
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-33s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
.DEFAULT_GOAL := help
APP_NAME=app
VERSION=$(shell date +'%y.%m.%d')
DOCKER_REPO=containerize
.PHONY: build
build: ## Build the container
docker build -t $(APP_NAME) .
.PHONY: build-nc
build-nc: ## Build the container without caching
docker build --no-cache -t $(APP_NAME) .
.PHONY: run
run: ## Run container
docker run -it --rm --name="$(APP_NAME)" $(APP_NAME)
.PHONY: up
up: build run ## Run container (Alias to run)
.PHONY: stop
stop: ## Stop and remove a running container
docker stop $(APP_NAME); docker rm $(APP_NAME)
.PHONY: release
release: build-nc publish ## Make a release by building and publishing the `{version}` ans `latest` tagged containers
.PHONY: publish
publish: repo-login publish-latest publish-version ## Publish the `{version}` ans `latest` tagged containers to docker hub
.PHONY: publish-latest
publish-latest: tag-latest ## publish the `latest` taged container to docker hub
@echo 'publish $(VERSION) to $(DOCKER_REPO)'
docker push $(DOCKER_REPO)/$(APP_NAME):latest
.PHONY: publish-version
publish-version: tag-version ## publish the `version` taged container to docker hub
@echo 'publish latest to $(DOCKER_REPO)'
docker tag $(APP_NAME) $(DOCKER_REPO)/$(APP_NAME):$(VERSION)
.PHONY: tag-latest
tag-latest: ## Generate container `{version}` tag
@echo 'create tag latest'
docker tag $(APP_NAME) $(DOCKER_REPO)/$(APP_NAME):latest
.PHONY: tag-version
tag-version: ## Generate container `latest` tag
@echo 'create tag $(VERSION)'
docker tag $(APP_NAME) $(DOCKER_REPO)/$(APP_NAME):$(VERSION)
.PHONY: repo-login
repo-login: ## Auto login to docker hub
@docker login
version: ## Output the current version
@echo $(VERSION)
.PHONY: help
help: ## list command:
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
.DEFAULT_GOAL := help
APP_NAME=app
VERSION=$(shell date +'%y.%m.%d')
DOCKER_REPO=containerize
.PHONY: build
build: ## Build the container
docker-compose build --no-cache $(APP_NAME)
docker build -t $(APP_NAME) .
.PHONY: stop
stop: ## Stop running containers
docker stop $(APP_NAME)
.PHONY: rm
rm: stop ## Stop and remove running containers
docker rm $(APP_NAME)
.PHONY: clean
clean: ## Clean the generated/compiles files
echo "nothing clean ..."
.PHONY: run
run: stop ## Run container
docker run -it --rm --name="$(APP_NAME)" $(APP_NAME)
dev: ## Run container in development mode
docker-compose build --no-cache $(APP_NAME) && docker-compose run $(APP_NAME)
.PHONY: release
release: build publish ## Make a release by building and publishing the `{version}` ans `latest` tagged containers
.PHONY: publish
publish: repo-login publish-latest publish-version ## Publish the `{version}` ans `latest` tagged containers to docker hub
.PHONY: publish-latest
publish-latest: tag-latest ## publish the `latest` taged container to docker hub
@echo 'publish $(VERSION) to $(DOCKER_REPO)'
docker push $(DOCKER_REPO)/$(APP_NAME):latest
.PHONY: publish-version
publish-version: tag-version ## publish the `version` taged container to docker hub
@echo 'publish latest to $(DOCKER_REPO)'
docker tag $(APP_NAME) $(DOCKER_REPO)/$(APP_NAME):$(VERSION)
.PHONY: tag-latest
tag-latest: ## Generate container `{version}` tag
@echo 'create tag latest'
docker tag $(APP_NAME) $(DOCKER_REPO)/$(APP_NAME):latest
.PHONY: tag-version
tag-version: ## Generate container `latest` tag
@echo 'create tag $(VERSION)'
docker tag $(APP_NAME) $(DOCKER_REPO)/$(APP_NAME):$(VERSION)
.PHONY: repo-login
repo-login: ## Auto login to docker hub
@docker login
version: ## Output the current version
@echo $(VERSION)
.PHONY: help
help: ## list command:
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
.DEFAULT_GOAL := help
.PHONY: build
build: ## build react-native
yarn install
.PHONY: i18n
i18n: ## update i18n
yarn run i18n
.PHONY: android
android: ## run android
react-native run-android
.PHONY: ios
ios: ## run ios on iPhone 8
react-native run-ios --simulator "iPhone 8"
.PHONY: ios
pod: ## install ios pod dependency
cd ./ios && pod install
.PHONY: help
help: ## list command:
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment