-
Notifications
You must be signed in to change notification settings - Fork 22
/
Makefile
51 lines (47 loc) · 2.12 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
# !/usr/bin/make - f
SHELL := /usr/bin/env bash
SED := $(shell [[ `command -v gsed` ]] && echo gsed || echo sed)
REPO_API_URL ?= https://hub.docker.com/v2
REPO_NAMESPACE ?= utensils
REPO_USERNAME ?= utensils
IMAGE_NAME ?= envisaged
BASE_IMAGE ?= utensils/opengl:stable
TAG_SUFFIX ?= $(shell echo "-$(BASE_IMAGE)" | $(SED) 's|:|-|g' | $(SED) 's|/|_|g' 2>/dev/null )
VCS_REF := $(shell git rev-parse --short HEAD)
BUILD_DATE := $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
VERSION := $(shell git rev-parse --abbrev-ref HEAD | $(SED) 's|/|_|g' 2>/dev/null)
PLATFORMS ?= linux/amd64,linux/386
BUILD_OUTPUT ?= auto
# Default target is to build and push Envisaged to DockerHub.
.PHONY: default
default: build
# Build base images for all releases using buildx.
.PHONY: build
.SILENT: build
build:
docker buildx build \
--build-arg BASE_IMAGE=$(BASE_IMAGE) \
--build-arg BUILD_DATE=$(BUILD_DATE) \
--build-arg BUILD_DATE=$(VERSION) \
--build-arg VCS_REF=$(VCS_REF) \
--tag $(REPO_NAMESPACE)/$(IMAGE_NAME):$(VERSION)$(TAG_SUFFIX) \
--tag $(REPO_NAMESPACE)/$(IMAGE_NAME):$(VERSION) \
--tag $(REPO_NAMESPACE)/$(IMAGE_NAME):latest \
--platform $(PLATFORMS) \
--progress=$(BUILD_OUTPUT) \
--push \
--file Dockerfile .
# Update README on DockerHub registry.
.PHONY: push-readme
.SILENT: 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;