This repository has been archived by the owner on Jun 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Makefile
121 lines (94 loc) · 4.36 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
SHELL ?= /bin/bash
.DEFAULT_GOAL := build
################################################################################
# Version details #
################################################################################
# This will reliably return the short SHA1 of HEAD or, if the working directory
# is dirty, will return that + "-dirty"
GIT_VERSION = $(shell git describe --always --abbrev=7 --dirty --match=NeVeRmAtCh)
################################################################################
# Go build details #
################################################################################
BASE_PACKAGE_NAME := github.com/brigadecore/brigade-github-app
################################################################################
# Containerized development environment-- or lack thereof #
################################################################################
ifneq ($(SKIP_DOCKER),true)
PROJECT_ROOT := $(dir $(realpath $(firstword $(MAKEFILE_LIST))))
# https://github.com/brigadecore/go-tools
# https://hub.docker.com/repository/docker/brigadecore/go-tools
DEV_IMAGE := brigadecore/go-tools:v0.1.0
DOCKER_CMD := docker run \
-it \
--rm \
-e SKIP_DOCKER=true \
-v $(PROJECT_ROOT):/go/src/$(BASE_PACKAGE_NAME) \
-w /go/src/$(BASE_PACKAGE_NAME) $(DEV_IMAGE)
endif
################################################################################
# Docker images we build and publish #
################################################################################
ifdef DOCKER_REGISTRY
DOCKER_REGISTRY := $(DOCKER_REGISTRY)/
endif
ifdef DOCKER_ORG
DOCKER_ORG := $(DOCKER_ORG)/
endif
DOCKER_IMAGE_PREFIX := $(DOCKER_REGISTRY)$(DOCKER_ORG)
ifdef VERSION
IMMUTABLE_DOCKER_TAG := $(VERSION)
MUTABLE_DOCKER_TAG := latest
else
IMMUTABLE_DOCKER_TAG := $(GIT_VERSION)
MUTABLE_DOCKER_TAG := edge
endif
################################################################################
# Utility targets #
################################################################################
.PHONY: redeploy
redeploy: test push-all-images
redeploy:
kubectl delete `kubectl get po -l app=github-app-test-brigade-github-app -o name`
@echo 'Waiting for pod to start... (20 seconds)'
sleep 20
kubectl logs -f `kubectl get po -l app=github-app-test-brigade-github-app -o name | tail -n 1 | sed 's/pod\///'`
.PHONY: resolve-dependencies
resolve-dependencies:
$(DOCKER_CMD) sh -c 'go mod tidy && go mod vendor'
################################################################################
# Tests #
################################################################################
# Verifies there are no discrepancies between desired dependencies and the
# tracked, vendored dependencies
.PHONY: verify-vendored-code
verify-vendored-code:
$(DOCKER_CMD) go mod verify
.PHONY: lint
lint:
$(DOCKER_CMD) golangci-lint run --config ./golangci.yml
.PHONY: test
test:
$(DOCKER_CMD) go test ./pkg/...
################################################################################
# Build / Publish #
################################################################################
IMAGES = brigade-github-app brigade-github-check-run
.PHONY: build
build: build-all-images
# To use build-all-images, you need to have Docker installed and configured. You
# should also set DOCKER_REGISTRY and DOCKER_ORG to your own personal registry
# if you are not pushing to the official upstream.
.PHONY: build-all-images
build-all-images: $(addsuffix -build-image,$(IMAGES))
%-build-image:
docker build -f Dockerfile.$* -t $(DOCKER_IMAGE_PREFIX)$*:$(IMMUTABLE_DOCKER_TAG) .
docker tag $(DOCKER_IMAGE_PREFIX)$*:$(IMMUTABLE_DOCKER_TAG) $(DOCKER_IMAGE_PREFIX)$*:$(MUTABLE_DOCKER_TAG)
.PHONY: push
push: push-all-images
# You must be logged into DOCKER_REGISTRY before you can push.
.PHONY: push-all-images
push-all-images: build-all-images
push-all-images: $(addsuffix -push-image,$(IMAGES))
%-push-image:
docker push $(DOCKER_IMAGE_PREFIX)$*:$(IMMUTABLE_DOCKER_TAG)
docker push $(DOCKER_IMAGE_PREFIX)$*:$(MUTABLE_DOCKER_TAG)