github.com/verrazzano/verrazzano@v1.7.0/authproxy/Makefile (about)

     1  # Copyright (C) 2023, Oracle and/or its affiliates.
     2  # Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
     3  
     4  include ../make/quality.mk
     5  include ../make/generate.mk
     6  include ../make/retry.mk
     7  
     8  SCRIPT_DIR:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))/../build
     9  TOOLS_DIR:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))/../tools
    10  
    11  NAME:=verrazzano-authproxy
    12  REPO_NAME:=verrazzano-authproxy
    13  
    14  ifdef KUBECONFIG
    15    KUBECONFIG ?= ${KUBECONFIG}
    16  else
    17    KUBECONFIG ?= ${HOME}/.kube/config
    18  endif
    19  
    20  ifndef DOCKER_IMAGE_FULLNAME
    21  DOCKER_IMAGE_NAME ?= ${NAME}-dev
    22  DOCKER_IMAGE_FULLNAME=${DOCKER_IMAGE_NAME}
    23  ifeq ($(MAKECMDGOALS),$(filter $(MAKECMDGOALS),docker-push push-tag))
    24  	ifndef DOCKER_REPO
    25  		$(error DOCKER_REPO must be defined as the name of the Docker repository where image will be pushed)
    26  	endif
    27  	ifndef DOCKER_NAMESPACE
    28  		$(error DOCKER_NAMESPACE must be defined as the name of the Docker namespace where image will be pushed)
    29  	endif
    30  endif
    31  ifdef DOCKER_NAMESPACE
    32  DOCKER_IMAGE_FULLNAME := ${DOCKER_NAMESPACE}/${DOCKER_IMAGE_FULLNAME}
    33  endif
    34  ifdef DOCKER_REPO
    35  DOCKER_IMAGE_FULLNAME := ${DOCKER_REPO}/${DOCKER_IMAGE_FULLNAME}
    36  endif
    37  endif
    38  
    39  DOCKER_IMAGE_TAG ?= local-$(shell git rev-parse --short HEAD)
    40  
    41  ifndef RELEASE_BRANCH
    42  	RELEASE_BRANCH=$(shell git rev-parse --abbrev-ref HEAD)
    43  endif
    44  
    45  VZ_BASE_IMAGE ?= ghcr.io/verrazzano/verrazzano-base:v1.0.0-20230327155846-4653b27
    46  
    47  DIST_DIR:=dist
    48  GO ?= CGO_ENABLED=0 GO111MODULE=on GOPRIVATE=github.com/verrazzano go
    49  GO_LDFLAGS ?= -extldflags -static -X main.buildVersion=${BUILDVERSION} -X main.buildDate=${BUILDDATE}
    50  
    51  .PHONY: build
    52  build: go-fmt go-vet
    53  	go build -o bin/manager main.go
    54  
    55  # Run against the configured Kubernetes cluster in ~/.kube/config
    56  .PHONY: run
    57  run:
    58  	$(GO) run main.go --kubeconfig=${KUBECONFIG}
    59  
    60  #
    61  # Go build related tasks
    62  #
    63  .PHONY: go-build
    64  go-build:
    65  	$(GO) build \
    66  		-ldflags "${GO_LDFLAGS}" \
    67  		-o out/$(shell uname)_$(shell uname -m)/verrazzano-authproxy \
    68  		main.go
    69  
    70  .PHONY: go-build-linux
    71  go-build-linux:
    72  	GOOS=linux GOARCH=amd64 $(GO) build \
    73  		-ldflags "-s -w ${GO_LDFLAGS}" \
    74  		-o out/linux_amd64/verrazzano-authproxy \
    75  		main.go
    76  
    77  .PHONY: go-build-linux-debug
    78  go-build-linux-debug:
    79  	GOOS=linux GOARCH=amd64 $(GO) build \
    80  		-ldflags "${GO_LDFLAGS}" \
    81  		-o out/linux_amd64/verrazzano-authproxy \
    82  		main.go
    83  
    84  .PHONY: go-install
    85  go-install:
    86  	$(GO) install
    87  
    88  #
    89  # Docker-related tasks
    90  #
    91  .PHONY: docker-clean
    92  docker-clean:
    93  	rm -rf ${DIST_DIR}
    94  
    95  .PHONY: docker-build
    96  docker-build: go-build-linux docker-build-common
    97  
    98  .PHONY: docker-build-debug
    99  docker-build-debug: go-build-linux-debug docker-build-common
   100  
   101  .PHONY: docker-build-common
   102  docker-build-common:
   103  	# the TPL file needs to be copied into this dir so it is in the docker build context
   104  	cp ../THIRD_PARTY_LICENSES.txt .
   105  	docker build --pull \
   106  		--build-arg BASE_IMAGE="${VZ_BASE_IMAGE}" \
   107  		-t ${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_TAG} .
   108  
   109  .PHONY: docker-push
   110  docker-push: docker-build docker-push-common
   111  
   112  .PHONY: docker-push-debug
   113  docker-push-debug: docker-build-debug docker-push-common
   114  
   115  .PHONY: docker-push-common
   116  docker-push-common:
   117  	docker tag ${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_TAG} ${DOCKER_IMAGE_FULLNAME}:${DOCKER_IMAGE_TAG}
   118  	$(call retry_docker_push,${DOCKER_IMAGE_FULLNAME}:${DOCKER_IMAGE_TAG})
   119  
   120  ifeq ($(CREATE_LATEST_TAG), "1")
   121  	docker tag ${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_TAG} ${DOCKER_IMAGE_FULLNAME}:latest;
   122  	$(call retry_docker_push,${DOCKER_IMAGE_FULLNAME}:latest);
   123  endif
   124  
   125  #
   126  # Test-related tasks
   127  #
   128  .PHONY: unit-test
   129  unit-test: go-install
   130  	$(GO) test -v ./src/...
   131  
   132  #
   133  # Kubernetes-related tasks
   134  #
   135  .PHONY: push-tag
   136  push-tag:
   137  	PUBLISH_TAG="${DOCKER_IMAGE_TAG}"; \
   138  	echo "Tagging and pushing image ${DOCKER_IMAGE_FULLNAME}:$$PUBLISH_TAG"; \
   139  	docker pull "${DOCKER_IMAGE_FULLNAME}:${DOCKER_IMAGE_TAG}"; \
   140  	docker tag "${DOCKER_IMAGE_FULLNAME}:${DOCKER_IMAGE_TAG}" "${DOCKER_IMAGE_FULLNAME}:$$PUBLISH_TAG"; \
   141  	$(call retry_docker_push,"${DOCKER_IMAGE_FULLNAME}:$$PUBLISH_TAG")