github.com/spotahome/redis-operator@v1.2.4/Makefile (about)

     1  VERSION := v1.2.4
     2  
     3  # Name of this service/application
     4  SERVICE_NAME := redis-operator
     5  
     6  # Docker image name for this project
     7  IMAGE_NAME := spotahome/$(SERVICE_NAME)
     8  
     9  # Repository url for this project
    10  REPOSITORY := quay.io/$(IMAGE_NAME)
    11  
    12  # Shell to use for running scripts
    13  SHELL := $(shell which bash)
    14  
    15  # Get docker path or an empty string
    16  DOCKER := $(shell command -v docker)
    17  
    18  # Get the main unix group for the user running make (to be used by docker-compose later)
    19  GID := $(shell id -g)
    20  
    21  # Get the unix user id for the user running make (to be used by docker-compose later)
    22  UID := $(shell id -u)
    23  
    24  # Commit hash from git
    25  COMMIT=$(shell git rev-parse HEAD)
    26  GITTAG_COMMIT := $(shell git rev-list --tags --max-count=1)
    27  GITTAG := $(shell git describe --abbrev=0 --tags ${GITTAG_COMMIT} 2>/dev/null || true)
    28  
    29  # Branch from git
    30  BRANCH=$(shell git rev-parse --abbrev-ref HEAD)
    31  
    32  TAG := $(GITTAG)
    33  ifneq ($(COMMIT), $(GITTAG_COMMIT))
    34      TAG := $(COMMIT)
    35  endif
    36  
    37  ifneq ($(shell git status --porcelain),)
    38      TAG := $(TAG)-dirty
    39  endif
    40  
    41  
    42  PROJECT_PACKAGE := github.com/spotahome/redis-operator
    43  CODEGEN_IMAGE := quay.io/slok/kube-code-generator:v1.23.0
    44  PORT := 9710
    45  
    46  # CMDs
    47  UNIT_TEST_CMD := go test `go list ./... | grep -v /vendor/` -v
    48  GO_GENERATE_CMD := go generate `go list ./... | grep -v /vendor/`
    49  GO_INTEGRATION_TEST_CMD := go test `go list ./... | grep test/integration` -v -tags='integration'
    50  GET_DEPS_CMD := dep ensure
    51  UPDATE_DEPS_CMD := dep ensure
    52  MOCKS_CMD := go generate ./mocks
    53  
    54  # environment dirs
    55  DEV_DIR := docker/development
    56  APP_DIR := docker/app
    57  
    58  # workdir
    59  WORKDIR := /go/src/github.com/spotahome/redis-operator
    60  
    61  # The default action of this Makefile is to build the development docker image
    62  .PHONY: default
    63  default: build
    64  
    65  # Run the development environment in non-daemonized mode (foreground)
    66  .PHONY: docker-build
    67  docker-build: deps-development
    68  	docker build \
    69  		--build-arg uid=$(UID) \
    70  		-t $(REPOSITORY)-dev:latest \
    71  		-t $(REPOSITORY)-dev:$(COMMIT) \
    72  		-f $(DEV_DIR)/Dockerfile \
    73  		.
    74  
    75  # Run a shell into the development docker image
    76  .PHONY: shell
    77  shell: docker-build
    78  	docker run -ti --rm -v ~/.kube:/.kube:ro -v $(PWD):$(WORKDIR) -u $(UID):$(UID) --name $(SERVICE_NAME) -p $(PORT):$(PORT) $(REPOSITORY)-dev /bin/bash
    79  
    80  # Build redis-failover executable file
    81  .PHONY: build
    82  build: docker-build
    83  	docker run -ti --rm -v $(PWD):$(WORKDIR) -u $(UID):$(UID) --name $(SERVICE_NAME) $(REPOSITORY)-dev ./scripts/build.sh
    84  
    85  # Run the development environment in the background
    86  .PHONY: run
    87  run: docker-build
    88  	docker run -ti --rm -v ~/.kube:/.kube:ro -v $(PWD):$(WORKDIR) -u $(UID):$(UID) --name $(SERVICE_NAME) -p $(PORT):$(PORT) $(REPOSITORY)-dev ./scripts/run.sh
    89  
    90  # Build the production image based on the public one
    91  .PHONY: image
    92  image: deps-development
    93  	docker build \
    94  	-t $(SERVICE_NAME) \
    95  	-t $(REPOSITORY):latest \
    96  	-t $(REPOSITORY):$(COMMIT) \
    97  	-t $(REPOSITORY):$(BRANCH) \
    98  	-f $(APP_DIR)/Dockerfile \
    99  	.
   100  
   101  .PHONY: image-release
   102  image-release:
   103  	docker buildx build \
   104  	--platform linux/amd64,linux/arm64,linux/arm/v7 \
   105  	--push \
   106  	--build-arg VERSION=$(TAG) \
   107  	-t $(REPOSITORY):latest \
   108  	-t $(REPOSITORY):$(COMMIT) \
   109  	-t $(REPOSITORY):$(TAG) \
   110  	-f $(APP_DIR)/Dockerfile \
   111  	.
   112  
   113  .PHONY: testing
   114  testing: image
   115  	docker push $(REPOSITORY):$(BRANCH)
   116  
   117  .PHONY: tag
   118  tag:
   119  	git tag $(VERSION)
   120  
   121  .PHONY: publish
   122  publish:
   123  	@COMMIT_VERSION="$$(git rev-list -n 1 $(VERSION))"; \
   124  	docker tag $(REPOSITORY):"$$COMMIT_VERSION" $(REPOSITORY):$(VERSION)
   125  	docker push $(REPOSITORY):$(VERSION)
   126  	docker push $(REPOSITORY):latest
   127  
   128  .PHONY: release
   129  release: tag image-release
   130  
   131  # Test stuff in dev
   132  .PHONY: unit-test
   133  unit-test: docker-build
   134  	docker run -ti --rm -v $(PWD):$(WORKDIR) -u $(UID):$(UID) --name $(SERVICE_NAME) $(REPOSITORY)-dev /bin/sh -c '$(UNIT_TEST_CMD)'
   135  
   136  .PHONY: ci-unit-test
   137  ci-unit-test:
   138  	$(UNIT_TEST_CMD)
   139  
   140  .PHONY: ci-integration-test
   141  ci-integration-test:
   142  	$(GO_INTEGRATION_TEST_CMD)
   143  
   144  .PHONY: integration-test
   145  integration-test:
   146  	./scripts/integration-tests.sh
   147  
   148  .PHONY: helm-test
   149  helm-test:
   150  	./scripts/helm-tests.sh
   151  
   152  # Run all tests
   153  .PHONY: test
   154  test: ci-unit-test ci-integration-test helm-test
   155  
   156  .PHONY: go-generate
   157  go-generate: docker-build
   158  	docker run -ti --rm -v $(PWD):$(WORKDIR) -u $(UID):$(UID) --name $(SERVICE_NAME) $(REPOSITORY)-dev /bin/sh -c '$(GO_GENERATE_CMD)'
   159  
   160  .PHONY: generate
   161  generate: go-generate
   162  
   163  .PHONY: get-deps
   164  get-deps: docker-build
   165  	docker run -ti --rm -v $(PWD):$(WORKDIR) -u $(UID):$(UID) --name $(SERVICE_NAME) $(REPOSITORY)-dev /bin/sh -c '$(GET_DEPS_CMD)'
   166  
   167  .PHONY: update-deps
   168  update-deps: docker-build
   169  	docker run -ti --rm -v $(PWD):$(WORKDIR) -u $(UID):$(UID) --name $(SERVICE_NAME) $(REPOSITORY)-dev /bin/sh -c '$(UPDATE_DEPS_CMD)'
   170  
   171  .PHONY: mocks
   172  mocks: docker-build
   173  	docker run -ti --rm -v $(PWD):$(WORKDIR) -u $(UID):$(UID) --name $(SERVICE_NAME) $(REPOSITORY)-dev /bin/sh -c '$(MOCKS_CMD)'
   174  
   175  .PHONY: deps-development
   176  # Test if the dependencies we need to run this Makefile are installed
   177  deps-development:
   178  ifndef DOCKER
   179  	@echo "Docker is not available. Please install docker"
   180  	@exit 1
   181  endif
   182  
   183  # Generate kubernetes code for types..
   184  .PHONY: update-codegen
   185  update-codegen:
   186  	@echo ">> Generating code for Kubernetes CRD types..."
   187  	docker run --rm -it \
   188  	-v $(PWD):/go/src/$(PROJECT_PACKAGE) \
   189  	-e PROJECT_PACKAGE=$(PROJECT_PACKAGE) \
   190  	-e CLIENT_GENERATOR_OUT=$(PROJECT_PACKAGE)/client/k8s \
   191  	-e APIS_ROOT=$(PROJECT_PACKAGE)/api \
   192  	-e GROUPS_VERSION="redisfailover:v1" \
   193  	-e GENERATION_TARGETS="deepcopy,client" \
   194  	$(CODEGEN_IMAGE)
   195  
   196  generate-crd:
   197  	docker run -it --rm \
   198  	-v $(PWD):/go/src/$(PROJECT_PACKAGE) \
   199  	-e GO_PROJECT_ROOT=/go/src/$(PROJECT_PACKAGE) \
   200  	-e CRD_TYPES_PATH=/go/src/$(PROJECT_PACKAGE)/api \
   201  	-e CRD_OUT_PATH=/go/src/$(PROJECT_PACKAGE)/manifests \
   202  	$(CODEGEN_IMAGE) update-crd.sh
   203  	cp -f manifests/databases.spotahome.com_redisfailovers.yaml manifests/kustomize/base