-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
66 lines (58 loc) · 2.51 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
#!/usr/bin/make -f
SHELL := /usr/bin/env bash
REPO_NAMESPACE ?= utensils
REPO_USERNAME ?= jamesbrink
REPO_API_URL ?= https://hub.docker.com/v2
IMAGE_NAME ?= hertz-lattice
BASE_IMAGE ?= utensils/opengl:stable-alpine-3.12
SED := $(shell [[ `command -v gsed` ]] && echo gsed || echo sed)
VERSION := $(shell git describe --tags --abbrev=0 2>/dev/null || git rev-parse --abbrev-ref HEAD | $(SED) 's|/|_|g' 2>/dev/null)
VCS_REF := $(shell git rev-parse --short HEAD 2>/dev/null || echo "0000000")
BUILD_DATE := $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
# Default target is to build container
.PHONY: default
default: build
# Build the docker image
.PHONY: build
build: list
docker build \
--build-arg BASE_IMAGE=$(BASE_IMAGE) \
--build-arg BUILD_DATE=$(BUILD_DATE) \
--build-arg VCS_REF=$(VCS_REF) \
--build-arg VERSION=$(VERSION) \
--tag $(REPO_NAMESPACE)/$(IMAGE_NAME):latest \
--tag $(REPO_NAMESPACE)/$(IMAGE_NAME):$(VCS_REF) \
--tag $(REPO_NAMESPACE)/$(IMAGE_NAME):$(VERSION) \
--file Dockerfile .
# List built images
.PHONY: list
list:
docker images $(REPO_NAMESPACE)/$(IMAGE_NAME) --filter "dangling=false"
# Run any tests
.PHONY: test
test:
docker run -t $(REPO_NAMESPACE)/$(IMAGE_NAME) env | grep VERSION | grep $(VERSION)
# Push images to repo
.PHONY: push
push:
echo "$$REPO_PASSWORD" | docker login -u "$(REPO_USERNAME)" --password-stdin; \
docker push $(REPO_NAMESPACE)/$(IMAGE_NAME):latest; \
docker push $(REPO_NAMESPACE)/$(IMAGE_NAME):$(VCS_REF); \
docker push $(REPO_NAMESPACE)/$(IMAGE_NAME):$(VERSION);
# Update README on registry
.PHONY: push-readme
push-readme:
echo "Authenticating to $(REPO_API_URL)"; \
token=$$(curl -s -X POST -H "Content-Type: application/json" -d '{"username": "$(REPO_USERNAME)", "password": "'"$$REPO_PASSWORD"'"}' $(REPO_API_URL)/users/login/ | jq -r .token); \
code=$$(jq -n --arg description "$$(<README.md)" '{"registry":"registry-1.docker.io","full_description": $$description }' | curl -s -o /dev/null -L -w "%{http_code}" $(REPO_API_URL)/repositories/$(REPO_NAMESPACE)/$(IMAGE_NAME)/ -d @- -X PATCH -H "Content-Type: application/json" -H "Authorization: JWT $$token"); \
if [ "$$code" != "200" ]; \
then \
echo "Failed to update README.md"; \
exit 1; \
else \
echo "Success"; \
fi;
# Remove existing images
.PHONY: clean
clean:
docker rmi $$(docker images $(REPO_NAMESPACE)/$(IMAGE_NAME) --format="{{.Repository}}:{{.Tag}}") --force