-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
142 lines (121 loc) · 3.41 KB
/
Copy pathMakefile
File metadata and controls
142 lines (121 loc) · 3.41 KB
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
SHELL:=bash
.ONESHELL:
.SHELLFLAGS := -eu -o pipefail -c
.DELETE_ON_ERROR:
MAKEFLAGS += --warn-undefined-variables
MAKEFLAGS += --no-builtin-rules
.DEFAULT_GOAL = all
# -----------------------------------------------------------------------------
# XServer authentication
XSOCK=/tmp/.X11-unix
XCOOKIE=$(shell xauth list)
# -----------------------------------------------------------------------------
# Validations
DOCKER_EXISTS := $(shell command -v docker 2> /dev/null)
ifndef DOCKER_EXISTS
$(error "Please install 'docker'!")
endif
GIT_EXISTS := $(shell command -v git 2> /dev/null)
ifndef DOCKER_EXISTS
$(error "Please install 'git'!")
endif
# -----------------------------------------------------------------------------
# Configs
# The name of the docker image must be lowercase
name := "$(shell basename $(CURDIR) | tr '[A-Z]' '[a-z]')"
DOCKER_USER ?=
DOCKER_TOKEN ?=
# User
UID:=$(shell id -u)
GID:=$(shell id -g)
# Tag
tag:="$(shell git rev-parse --short HEAD)"
# Repository info
isGitRepoDirty := "$(shell git status --porcelain)"
# Beautify output
ifeq ("$(origin V)", "command line")
VERBOSE := $(V)
endif
ifndef VERBOSE
VERBOSE := 0
endif
ifeq ($(VERBOSE),1)
dockerBuildQuiet :=
Q :=
else
dockerBuildQuiet := --quiet
Q := @
endif
# -----------------------------------------------------------------------------
# Rules
.PHONY: all
all: build
@:
.PHONY: build
build: build-normal build-slim
.PHONY: build-normal
build-normal:
${Q}echo "Building '${name}'"
${Q}docker buildx build --rm ${dockerBuildQuiet} \
--build-arg SLIM_BUILD=0 \
-t ${name}:${tag} \
-t ${name}:latest \
.
.PHONY: build-slim
build-slim:
${Q}echo "Building '${name}' slim, without wine"
${Q}docker buildx build --rm ${dockerBuildQuiet} \
--build-arg SLIM_BUILD=1 \
-t ${name}:${tag}-slim \
-t ${name}:latest-slim \
.
.PHONY: push
push: build
${Q}status=$$(git status --porcelain); \
if [ ! -z "$${status}" ]; \
then \
echo "ERROR: Working directory is dirty!"; \
exit 1; \
fi
${Q}echo "Logging to dockerhub"
ifeq ("${DOCKER_USER}","")
${Q}echo "DOCKER_USERNAME is not set"
exit 1
endif
ifeq ("${DOCKER_TOKEN}","")
${Q}echo "Docker registry password:"
${Q}docker login --username ${DOCKER_USER}
else
${Q}echo "${DOCKER_TOKEN}" | docker login --username ${DOCKER_USER} --password-stdin
endif
${Q}echo "Applying dockerhub tags to the local image"
${Q}for t in ${tag} latest ${tag}-slim latest-slim; do \
docker tag ${name}:$${t} ${DOCKER_USER}/${name}:$${t}; \
done
${Q}echo "Pushing '${DOCKER_USER}/${name}'"
${Q}for t in ${tag} latest ${tag}-slim latest-slim; do \
docker push ${DOCKER_USER}/${name}:$${t}; \
done
.PHONY: run
run: build-normal
${Q}echo "Running '${name}'"
${Q}docker run \
--interactive --tty --rm \
--net=host \
--name=${name} \
--user "${UID}:${GID}" \
-e DISPLAY="${DISPLAY}" \
-e XCOOKIE="${XCOOKIE}" \
--volume=${XSOCK}:${XSOCK}:rw \
--volume=${PWD}:/workspace/:rw \
${name}
.PHONY: remove
remove:
${Q}echo "Removing '${name}'"
${Q}docker stop ${name}
${Q}docker rm ${name}
.PHONY: delete
delete:
${Q}echo "Deleting '${name}'"
${Q}docker image rm ${name}:${tag} ${name}:latest \
${name}:${tag}-slim ${name}:latest-slim