-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
53 lines (43 loc) · 1.16 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
# Variables
BINARY_NAME=timelapser
DOCKER_REPO=stone
IMAGE_NAME=$(DOCKER_REPO)/$(BINARY_NAME)
GIT_COMMIT=$(shell git rev-parse --short HEAD)
UUID := $(shell uuidgen)
DEVCONTAINER=ttl.sh/$(BINARY_NAME)-$(UUID):1h
VERSION?=1.0.0
# Go build flags
LDFLAGS=-ldflags "-X main.Version=$(VERSION) -X main.GitCommit=$(GIT_COMMIT)"
.PHONY: all build clean docker-build docker-push test
all: clean build
# Build the application locally
build:
CGO_ENABLED=0 go build $(LDFLAGS) -o $(BINARY_NAME) .
# Run tests
test:
go test -v ./...
# Clean build artifacts
clean:
rm -f $(BINARY_NAME)
go clean
# Build docker image
docker-build:
docker build \
--pull \
--build-arg VERSION=$(VERSION) \
--build-arg GIT_COMMIT=$(GIT_COMMIT) \
--label org.opencontainers.image.created=$(shell date -u +'%Y-%m-%dT%H:%M:%SZ') \
-t $(IMAGE_NAME):$(VERSION) \
-t $(IMAGE_NAME):latest \
.
# Push devcontainer to ttl.sh
docker-push-devcontainer:
docker tag $(IMAGE_NAME):$(VERSION) $(DEVCONTAINER)
docker push $(DEVCONTAINER)
# Push docker image
docker-push:
docker push $(IMAGE_NAME):$(VERSION)
docker push $(IMAGE_NAME):latest
# Development target for running locally
dev:
go run $(LDFLAGS) .