-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
123 lines (103 loc) · 4.52 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
122
123
# Tests
DAEMONTEMP := $(shell mktemp -d)
DAEMONPARAMS = \
--commit-interval 1m \
--commit-offset 30s \
--force-after-intervals 10 \
--zeitgitter-servers "gitta diversity zeitgitter.proxmox.by alpeinsoft-timestamps=https://zeitgitter.alpeinsoft.ch" \
--zeitgitter-sleep 2.5 \
--repository ${DAEMONTEMP} \
${EXTRA_DAEMONPARAMS}
# To check that environment variables are also consulted
DAEMONENV = AUTOBLOCKCHAINIFY_IDENTITY="Test User <[email protected]>"
all:
@echo 'Nothing needs to be done for "all"'
@echo 'Use "apt", "python-package", "docker-dev", "docker-multiarch", or "test" instead'
# ----- Installing
apt:
apt install git python3-pygit2 python3-gnupg python3-configargparse python3-nose
python-package wheel:
${RM} -f dist/*
./setup.py sdist bdist_wheel
pypi: python-package
twine upload dist/*
# ----- Testing
test tests: unit-tests system-tests
unit-tests:
nosetests3
system-tests: kill-daemon
## Start daemon; check whether environment variables are consulted
${DAEMONENV} ./autoblockchainify.py ${DAEMONPARAMS} &
## Run tests with daemon
@for i in tests/[0-9][0-9]-*; do echo; echo ===== $$i ${DAEMONTEMP}; $$i ${DAEMONTEMP} || exit 1; done
## Cleanup
${RM} -r ${DAEMONTEMP}
killall autoblockchainify.py
kill-daemon:
-killall autoblockchainify.py 2>/dev/null; exit 0
run-test-daemon: kill-daemon
./autoblockchainify.py ${DAEMONPARAMS}
##################################
#
# Create multi-platform docker image. If you have native systems around, using
# them will be much more efficient at build time. See e.g.
# https://netfuture.ch/2020/05/multi-arch-docker-image-easy/
BUILDXDETECT1 = ${HOME}/.docker/cli-plugins/docker-buildx
BUILDXDETECT2 = /usr/libexec/docker/cli-plugins/docker-buildx
# Just one of the many files created
QEMUDETECT = /proc/sys/fs/binfmt_misc/qemu-m68k
# For version x.y.z, output "-t …:x.y -t …:x.y.z";
# for anything else, output nothing
BASETAG = zeitgitter/autoblockchainify
VERSIONTAGS = $(shell sed -n -e 's,^VERSION = .\(\([0-9]*.[0-9]*\).[0-9]*\).$$,-t ${BASETAG}:\1 -t ${BASETAG}:\2,p' autoblockchainify/version.py)
# VERSIONMATCH should either be empty (take whatever is most recent on PyPI),
# by overriding it on the command line, or set to `==<version>`, where
# `<version>` is extracted from `autoblockchainify/version.py`.
VERSIONMATCH = ==$(shell sed -n -e 's,^VERSION = .\([0-9]*.[0-9]*.[0-9]*\).*$$,\1,p' autoblockchainify/version.py)
# debian:bullseye-slim also supports
# linux/arm64/v8,linux/mips64le,linux/ppc64le,linux/s390x. If there is demand,
# I'll happily add them to the default build.
PLATFORMS = linux/amd64,linux/386,linux/arm64,linux/arm/v7,linux/arm/v6
docker-multiarch: qemu buildx docker-multiarch-builder
docker login
docker buildx build --builder docker-multiarch --pull --push \
--build-arg VERSIONMATCH=${VERSIONMATCH} \
--platform ${PLATFORMS} ${VERSIONTAGS} \
-t ${BASETAG}:latest autoblockchainify
.PHONY: qemu buildx docker-multiarch-builder
qemu: ${QEMUDETECT}
${QEMUDETECT}:
docker pull multiarch/qemu-user-static
docker run --privileged multiarch/qemu-user-static --reset -p yes
docker ps -a | sed -n 's, *multiarch/qemu-user-static.*,,p' \
| (xargs docker rm 2>&1 || \
echo "Cannot remove docker container on ZFS; retry after next reboot") \
| grep -v 'dataset is busy'
buildx:
@if [ ! -x ${BUILDXDETECT1} -a ! -x ${BUILDXDETECT2} ]; then \
echo '*** `docker buildx` missing. See `https://github.com/docker/buildx#installing`'; \
exit 1; \
fi
docker-multiarch-builder: qemu buildx
if ! docker buildx ls | grep -w docker-multiarch > /dev/null; then \
docker buildx create --name docker-multiarch && \
docker buildx inspect --builder docker-multiarch --bootstrap; \
fi
# Create a docker image from the current tree
docker-dev:gen-docker-dev
sudo docker build --tag autoblockchainify:dev autoblockchainify-dev
gen-docker-dev:python-package
${RM} -rf autoblockchainify-dev
mkdir -p autoblockchainify-dev blockchain-dev
cp autoblockchainify/stamper.asc dist/autoblockchainify-*.whl autoblockchainify-dev
for i in Dockerfile; do \
(echo "### THIS FILE WAS AUTOGENERATED, CHANGES WILL BE LOST ###" && \
sed -e 's/^##DEVONLY## *//' -e '/##PRODONLY##$$/d' \
-e '/^ARG VERSIONMATCH/d' \
< autoblockchainify/$$i ) > autoblockchainify-dev/$$i; done
for i in migrate.sh run.sh health.sh; do \
(head -1 autoblockchainify/$$i && \
echo "### THIS FILE WAS AUTOGENERATED, CHANGES WILL BE LOST ###" && \
sed -e 's/^##DEVONLY## *//' -e '/##PRODONLY##$$/d' \
< autoblockchainify/$$i ) > autoblockchainify-dev/$$i && \
chmod +x autoblockchainify-dev/$$i; done