Skip to content

Commit ff6b43d

Browse files
committed
chore: added BUILD.md and Makefile
Signed-off-by: Gabriele Bartolini <[email protected]>
1 parent 1b12d93 commit ff6b43d

File tree

3 files changed

+157
-0
lines changed

3 files changed

+157
-0
lines changed

BUILD.md

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# Building Postgres Extensions Container Images for CloudNativePG
2+
3+
This guide explains how to build Postgres extensions operand images for
4+
[CloudNativePG](https://cloudnative-pg.io) using
5+
[Docker Bake](https://docs.docker.com/build/bake/) together with a
6+
[GitHub Actions workflow](.github/workflows/bake.yml).
7+
8+
Although it is not necessary, we recommend you use
9+
[GNU Make](https://www.gnu.org/software/make/) to build the images locally as
10+
outlined below.
11+
12+
## Prerequisites
13+
14+
This project depends on
15+
[`postgres-containers`](https://github.com/cloudnative-pg/postgres-containers).
16+
17+
Before you begin, ensure that you have met the
18+
[prerequisites](https://github.com/cloudnative-pg/postgres-containers/blob/main/BUILD.md#prerequisites)
19+
defined by that project, which primarily include:
20+
21+
1. **Docker:** Must be installed and running.
22+
2. **Docker Command Line:** The `docker` command must be executable.
23+
3. **Docker Buildx:** The `docker buildx` plugin must be available.
24+
4. **Docker Context:** A valid Docker context must be configured.
25+
26+
---
27+
28+
## Usage and Targets
29+
30+
The `Makefile` dynamically discovers all subdirectories that contain a
31+
`metadata.hcl` file (e.g., `./pgvector/metadata.hcl`) and creates individual
32+
build targets for each project.
33+
34+
### 1. Build Configuration Check (Dry Run)
35+
36+
To verify the configuration (running `docker buildx bake --check`) for all
37+
projects without building or pulling layers:
38+
39+
```bash
40+
make check
41+
```
42+
43+
### 2. Build All Projects
44+
45+
To check prerequisites and build all discovered projects:
46+
47+
```bash
48+
make
49+
# or
50+
make all
51+
````
52+
53+
### 3. Build a Specific Project
54+
55+
To build a single project (e.g., the directory named `pgvector`):
56+
57+
```bash
58+
make pgvector
59+
```
60+
61+
### 4. Push All Images
62+
63+
To build all images and immediately push them to the configured registry:
64+
65+
```bash
66+
make push
67+
```
68+
69+
### 5. Check Prerequisites Only
70+
71+
To verify that Docker and Buildx are correctly installed and configured:
72+
73+
```bash
74+
make prereqs
75+
```
76+
77+
### 6. Dry Run Mode
78+
79+
To see the commands that would be executed without running the actual `docker
80+
buildx bake` command, set the `DRY_RUN` flag:
81+
82+
```bash
83+
make DRY_RUN=true
84+
# or
85+
make pgvector DRY_RUN=true
86+
```

Makefile

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
.SUFFIXES:
2+
3+
# Find all directories containing metadata.hcl
4+
FILES := $(shell find . -type f -name metadata.hcl)
5+
DIRS := $(patsubst %/,%,$(patsubst ./%,%,$(dir $(FILES))))
6+
7+
.PHONY: all clean check prereqs $(DIRS)
8+
9+
# Colours
10+
GREEN := \033[0;32m
11+
BLUE := \033[0;34m
12+
RED := \033[0;31m
13+
NC := \033[0m
14+
15+
# Dry run flag
16+
DRY_RUN ?= false
17+
18+
# --------------------------
19+
# Prerequisite checks
20+
# --------------------------
21+
prereqs:
22+
@echo -e "$(BLUE)Checking prerequisites...$(NC)"
23+
@command -v docker >/dev/null 2>&1 || { echo -e "$(RED)Docker is not installed.$(NC)"; exit 1; }
24+
@docker --version >/dev/null 2>&1 || { echo -e "$(RED)Cannot run docker command.$(NC)"; exit 1; }
25+
@docker buildx version >/dev/null 2>&1 || { echo -e "$(RED)Docker Buildx not available.$(NC)"; exit 1; }
26+
@docker context inspect >/dev/null 2>&1 || { echo -e "$(RED)Docker context not configured.$(NC)"; exit 1; }
27+
@echo -e "$(GREEN)All prerequisites satisfied!$(NC)"
28+
29+
# --------------------------
30+
# Dry-run or verification
31+
# --------------------------
32+
check: prereqs
33+
@echo -e "$(BLUE)Performing bake --check for all projects...$(NC)"
34+
@$(foreach dir,$(DIRS), \
35+
echo -e "$(BLUE)[CHECK] $dir$(NC)"; \
36+
docker buildx bake -f $(dir)/metadata.hcl -f docker-bake.hcl --check; \
37+
)
38+
39+
# --------------------------
40+
# Push all images
41+
# --------------------------
42+
push: all
43+
@echo -e "$(BLUE)Performing bake --push for all projects...$(NC)"
44+
@$(foreach dir,$(DIRS), \
45+
echo -e "$(BLUE)[PUSH] $dir$(NC)"; \
46+
if [ "$(DRY_RUN)" = "true" ]; then \
47+
echo -e "$(GREEN)[DRY RUN] docker buildx bake -f $(dir)/metadata.hcl -f docker-bake.hcl --push$(NC)"; \
48+
else \
49+
docker buildx bake -f $(dir)/metadata.hcl -f docker-bake.hcl --push; \
50+
fi; \
51+
)
52+
53+
# --------------------------
54+
# Build targets
55+
# --------------------------
56+
all: prereqs $(DIRS)
57+
@echo -e "$(GREEN)======================================================$(NC)"
58+
@echo -e "$(GREEN)Build successful for all projects: $(DIRS)$(NC)"
59+
@echo -e "$(GREEN)======================================================$(NC)"
60+
61+
# Per-project build
62+
$(DIRS): %: %/metadata.hcl
63+
@echo -e "$(BLUE)--- Starting Docker Buildx Bake for target: $@ ---$(NC)"
64+
ifeq ($(DRY_RUN),true)
65+
@echo -e "$(GREEN)[DRY RUN] docker buildx bake -f $@/metadata.hcl -f docker-bake.hcl$(NC)"
66+
else
67+
docker buildx bake -f $@/metadata.hcl -f docker-bake.hcl
68+
endif
69+
@echo -e "$(GREEN)--- Successfully built $@ ---$(NC)"

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ container images** containing PostgreSQL extensions supported by
88
integrate seamlessly with the [`image volume extensions` feature](https://cloudnative-pg.io/documentation/current/imagevolume_extensions/)
99
in CloudNativePG.
1010

11+
For detailed instructions on building the images, see the [BUILD.md file](BUILD.md).
12+
1113
---
1214

1315
## Requirements

0 commit comments

Comments
 (0)