1- .PHONY : clean deploy deps gcloud-auth image imagepush lint run stagedeploy test testci testcover
2-
31# The version that will be used in docker tags (e.g. to push a
42# go-httpbin:latest image use `make imagepush VERSION=latest)`
5- VERSION ?= $(shell git rev-parse --short HEAD)
6-
7- # Override these values to deploy to a different Cloud Run project
8- GCLOUD_PROJECT ?= httpbingo
9- GCLOUD_ACCOUNT ?=
[email protected] 10- GCLOUD_REGION ?= us-central1
11-
12- # The version tag for the Cloud Run deployment (override this to adjust
13- # pre-production URLs)
14- GCLOUD_TAG ?= "v-$(VERSION ) "
15-
16- # Run gcloud in a container to avoid needing to install the SDK locally
17- GCLOUD_COMMAND ?= ./bin/gcloud
18-
19- # We push docker images to both docker hub and gcr.io
20- DOCKER_TAG_DOCKERHUB ?= mccutchen/go-httpbin:$(VERSION )
21- DOCKER_TAG_GCLOUD ?= gcr.io/$(GCLOUD_PROJECT ) /go-httpbin:$(VERSION )
3+ VERSION ?= $(shell git rev-parse --short HEAD)
4+ DOCKER_TAG ?= mccutchen/go-httpbin:$(VERSION )
225
236# Built binaries will be placed here
247DIST_PATH ?= dist
@@ -41,22 +24,26 @@ GO_SOURCES = $(wildcard **/*.go)
4124# =============================================================================
4225build : $(DIST_PATH ) /go-httpbin
4326
27+ buildtests : $(DIST_PATH ) /go-httpbin.test
28+
4429$(DIST_PATH ) /go-httpbin : $(GO_SOURCES )
4530 mkdir -p $(DIST_PATH )
4631 CGO_ENABLED=0 go build -ldflags=" -s -w" -o $(DIST_PATH ) /go-httpbin ./cmd/go-httpbin
4732
48- buildtests :
33+ $( DIST_PATH ) /go-httpbin.test : $( GO_SOURCES )
4934 CGO_ENABLED=0 go test -ldflags=" -s -w" -v -c -o $(DIST_PATH ) /go-httpbin.test ./httpbin
5035
5136clean :
5237 rm -rf $(DIST_PATH ) $(COVERAGE_PATH )
38+ .PHONY : clean
5339
5440
5541# =============================================================================
5642# test & lint
5743# =============================================================================
5844test :
5945 go test $(TEST_ARGS ) ./...
46+ .PHONY : test
6047
6148
6249# Test command to run for continuous integration, which includes code coverage
@@ -65,77 +52,45 @@ test:
6552testci : build
6653 go test $(TEST_ARGS ) $(COVERAGE_ARGS ) ./...
6754 git diff --exit-code
55+ .PHONY : testci
6856
6957testcover : testci
7058 go tool cover -html=$(COVERAGE_PATH )
59+ .PHONY : testcover
7160
7261lint : $(TOOL_GOLINT ) $(TOOL_STATICCHECK )
7362 test -z " $$ (gofmt -d -s -e .)" || (echo " Error: gofmt failed" ; gofmt -d -s -e . ; exit 1)
7463 go vet ./...
7564 $(TOOL_GOLINT ) -set_exit_status ./...
7665 $(TOOL_STATICCHECK ) ./...
66+ .PHONY : lint
7767
7868
7969# =============================================================================
8070# run locally
8171# =============================================================================
8272run : build
8373 $(DIST_PATH ) /go-httpbin
74+ .PHONY : run
8475
8576watch : $(TOOL_REFLEX )
8677 reflex -s -r ' \.(go|html)$$' make run
87-
88-
89- # =============================================================================
90- # deploy to fly.io
91- # =============================================================================
92- deploy :
93- flyctl deploy --strategy=rolling
94-
95-
96- # =============================================================================
97- # deploy to google cloud run
98- # =============================================================================
99- deploy-cloud-run : gcloud-auth imagepush
100- $(GCLOUD_COMMAND ) beta run deploy \
101- $(GCLOUD_PROJECT ) \
102- --image=$(DOCKER_TAG_GCLOUD ) \
103- --revision-suffix=$(VERSION ) \
104- --tag=$(GCLOUD_TAG ) \
105- --project=$(GCLOUD_PROJECT ) \
106- --region=$(GCLOUD_REGION ) \
107- --allow-unauthenticated \
108- --platform=managed
109- $(GCLOUD_COMMAND ) run services update-traffic --to-latest
110-
111- stagedeploy-cloud-run : gcloud-auth imagepush
112- $(GCLOUD_COMMAND ) beta run deploy \
113- $(GCLOUD_PROJECT ) \
114- --image=$(DOCKER_TAG_GCLOUD ) \
115- --revision-suffix=$(VERSION ) \
116- --tag=$(GCLOUD_TAG ) \
117- --project=$(GCLOUD_PROJECT ) \
118- --region=$(GCLOUD_REGION ) \
119- --allow-unauthenticated \
120- --platform=managed \
121- --no-traffic
122-
123- gcloud-auth :
124- @$(GCLOUD_COMMAND ) auth list | grep ' ^\*' | grep -q $(GCLOUD_ACCOUNT ) || $(GCLOUD_COMMAND ) auth login $(GCLOUD_ACCOUNT )
125- @$(GCLOUD_COMMAND ) auth print-access-token | docker login -u oauth2accesstoken --password-stdin https://gcr.io
78+ .PHONY : watch
12679
12780
12881# =============================================================================
12982# docker images
13083# =============================================================================
13184image :
132- DOCKER_BUILDKIT=1 docker build -t $(DOCKER_TAG_DOCKERHUB ) .
85+ DOCKER_BUILDKIT=1 docker build -t $(DOCKER_TAG ) .
86+ .PHONY : image
13387
13488imagepush :
13589 docker buildx create --name httpbin
13690 docker buildx use httpbin
137- docker buildx build --push --platform linux/amd64,linux/arm64 -t $(DOCKER_TAG_DOCKERHUB ) .
91+ docker buildx build --push --platform linux/amd64,linux/arm64 -t $(DOCKER_TAG ) .
13892 docker buildx rm httpbin
93+ .PHONY : imagepush
13994
14095
14196# =============================================================================
0 commit comments