-
Notifications
You must be signed in to change notification settings - Fork 140
Expand file tree
/
Copy pathMakefile.docker
More file actions
109 lines (89 loc) · 3.93 KB
/
Copy pathMakefile.docker
File metadata and controls
109 lines (89 loc) · 3.93 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
# Shared Docker image infrastructure.
# Included by the top-level Makefile and by tests/Makefile.
# Repo root: the directory that contains this file, regardless of where make
# is invoked from (root, tests/, tests/tablespaces/, …).
REPO_ROOT := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
VERSION_FILE = $(REPO_ROOT)src/bin/pg_autoctl/git-version.h
ifeq ("$(wildcard $(VERSION_FILE))","")
DUMMY := $(shell git -C $(REPO_ROOT) update-index -q --refresh)
GIT_DIRTY := $(shell test -z "`git -C $(REPO_ROOT) diff-index --name-only HEAD --`" || echo "-dirty")
GIT_VVERSION := $(shell git -C $(REPO_ROOT) describe --match "v[0-9]*" HEAD 2>/dev/null)
GIT_DVERSION := $(shell echo $(GIT_VVERSION) | awk -Fv '{print $$2"$(GIT_DIRTY)"}')
GIT_VERSION := $(shell echo $(GIT_DVERSION) | sed -e 's/-/./g')
else
GIT_VERSION := $(shell awk -F '[ "]' '{print $$4}' $(VERSION_FILE))
endif
.PHONY: version
version: $(VERSION_FILE) ;
$(VERSION_FILE):
@echo "#define GIT_VERSION \"$(GIT_VERSION)\"" > $@
# Supported PostgreSQL versions:
PGVERSIONS = 14 15 16 17 18 19
# Default version:
PGVERSION ?= 19
# Base image that provides all Postgres versions + Citus builds.
# Override locally after building the base image under a different tag.
BASE ?= ghcr.io/hapostgres/pg_auto_failover/pgaf-base:bookworm
CONTAINER_NAME = pg_auto_failover
TEST_CONTAINER_NAME = pg_auto_failover_test
DOCKER_RUN_OPTS = --privileged --rm
# DOCKER BUILDS
#
# make build-base — build the base image (all PG versions + Citus)
# make build — build the 'run' image for every supported PG version
# make build-pg17 — build the 'run' image for PG 17 only
# make build-pytest — build the 'test' (Python) image for every PG version
# make build-pytest-pg17 — build the 'test' image for PG 17 only
# make build-pytest-image — build the 'test' image for PGVERSION (default latest)
.PHONY: build-base
build-base:
docker build -f $(REPO_ROOT)Dockerfile.base -t $(BASE) $(REPO_ROOT)
BUILD_TARGETS = $(patsubst %,build-pg%,$(PGVERSIONS))
BUILD_PYTEST_TARGETS = $(patsubst %,build-pytest-pg%,$(PGVERSIONS))
BUILD_CHECK_TARGETS = $(patsubst %,build-check-pg%,$(PGVERSIONS))
.PHONY: build
build: $(BUILD_TARGETS) ;
.PHONY: $(BUILD_TARGETS)
$(BUILD_TARGETS): version
docker build \
--build-arg PGVERSION=$(subst build-pg,,$@) \
--build-arg BASE=$(BASE) \
--target run \
-t $(CONTAINER_NAME):$(subst build-,,$@) $(REPO_ROOT)
.PHONY: build-check build-pytest build-pytest-image
build-check: $(BUILD_CHECK_TARGETS) ;
build-pytest: $(BUILD_PYTEST_TARGETS) ;
build-pytest-image: build-pytest-pg$(PGVERSION) ;
PGAFTEST_CONTAINER_NAME = pgaf
.PHONY: build-pgaftest
build-pgaftest: version
docker build \
--build-arg PGVERSION=$(PGVERSION) \
--build-arg BASE=$(BASE) \
--target pgaftest \
-t $(PGAFTEST_CONTAINER_NAME):pgaftest $(REPO_ROOT)
.PHONY: $(BUILD_PYTEST_TARGETS)
$(BUILD_PYTEST_TARGETS): version
docker build \
--build-arg PGVERSION=$(subst build-pytest-pg,,$@) \
--build-arg BASE=$(BASE) \
--target test \
-t $(TEST_CONTAINER_NAME):pg$(subst build-pytest-pg,,$@) $(REPO_ROOT)
.SECONDEXPANSION:
.PHONY: $(BUILD_CHECK_TARGETS)
$(BUILD_CHECK_TARGETS): version $$(subst build-check-,build-test-,$$@)
docker run --rm \
-t $(TEST_CONTAINER_NAME):$(subst build-check-,,$@) \
pg_autoctl version --json | jq ".pg_version" | xargs echo $(subst build-check-,,$@):
# make save-pytest-image; compresses the pytest image to a .tar.zst archive.
# Used in CI to pass the built image to downstream test jobs as an artifact.
.PHONY: save-pytest-image
save-pytest-image:
docker save $(TEST_CONTAINER_NAME):pg$(PGVERSION) \
| zstd -T0 -3 > $(TEST_CONTAINER_NAME)-pg$(PGVERSION).tar.zst
# make load-pytest-image; decompresses and loads a .tar.zst image archive.
# Used in CI test jobs that download the image from a prior build job.
.PHONY: load-pytest-image
load-pytest-image:
zstd -d --stdout $(TEST_CONTAINER_NAME)-pg$(PGVERSION).tar.zst \
| docker load