Skip to content

Commit ba35a08

Browse files
nyurikolksdr
andauthored
docker build improvements (#5)
* docker build improvements Improved docker build to use parametrized docker image base, allowing custom base images Makefile target changes: * deb: performs a clean and runs `pg_buildext` to update `control` file before packaging * deb-docker instead of deb-in-docker, and can be parametrized - both the base image and extra packages * deb-latest runs in docker using `docker:latest` image * deb-sid runs in docker using `docker:sid` image ----- TODO for another PR: When trying to build an image using Ubuntu (i guess just to see if it works), I get an error `Invalid cross-device link`. The probable cause is because docker maps two directories one inside the other, so perhaps there is a problem there. Not sure why it works fine with Debian base images. Maybe @olksdr knows? ``` $ make deb-docker base=ubuntu:latest .... dpkg-deb: building package 'postgresql-10-gzip' in '../postgresql-10-gzip_1.0.0_amd64.deb'. dpkg-deb: building package 'postgresql-10-gzip-dbgsym' in 'debian/.debhelper/scratch-space/build-postgresql-10-gzip/postgresql-10-gzip-dbgsym_1.0.0_amd64.deb'. Renaming postgresql-10-gzip-dbgsym_1.0.0_amd64.deb to postgresql-10-gzip-dbgsym_1.0.0_amd64.ddeb dh_builddeb: mv debian/.debhelper/scratch-space/build-postgresql-10-gzip/postgresql-10-gzip-dbgsym_1.0.0_amd64.deb ../postgresql-10-gzip-dbgsym_1.0.0_amd64.ddeb: Invalid cross-device link dh_builddeb: Aborting due to earlier error debian/rules:19: recipe for target 'binary-arch' failed make[1]: *** [binary-arch] Error 2 make[1]: Leaving directory '/build/pgsql-gzip' dpkg-buildpackage: error: fakeroot debian/rules binary-arch subprocess returned exit status 2 Makefile:46: recipe for target 'deb' failed ``` * Update README.md Co-Authored-By: Oleksandr <[email protected]> * Updated based on Olek's feedback Remove the extras, but keep the base image (mostly useful for testing). I will submit another PR in a few min to choose postgres version * forgot minor cleanup Co-authored-by: Oleksandr <[email protected]>
1 parent 7c26e8b commit ba35a08

File tree

7 files changed

+77
-55
lines changed

7 files changed

+77
-55
lines changed

.dockerignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Nothing should be passed to the docker build
2+
*

.gitignore

+12-8
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
1-
*.o
2-
*.so
1+
*.a
2+
*.bc
33
*.dll
44
*.dylib
5+
*.o
56
*.obj
6-
*.a
77
*.pc
8+
*.so
9+
build*
10+
debian/.debhelper/
11+
debian/control
12+
debian/files
13+
debian/postgresql-*
14+
log/
15+
output_iso/
816
regression.diffs
917
regression.out
1018
results/
19+
target/
1120
tmp_check/
1221
tmp_check_iso/
13-
output_iso/
14-
log/
15-
target/
16-
build*
17-
*.bc

Dockerfile

+16-9
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
1-
FROM debian:sid
1+
# This argument will usually be set by the Makefile. Override example:
2+
# make deb-docker base=debian:latest
3+
ARG BASE_IMAGE=debian:sid
4+
FROM ${BASE_IMAGE}
25

3-
RUN apt-get update -qq && \
4-
apt-get install -y \
5-
build-essential \
6-
fakeroot \
7-
pkg-config \
8-
devscripts \
9-
zlib1g-dev \
10-
postgresql-server-dev-all
6+
ARG BASE_IMAGE
7+
RUN set -eux ;\
8+
echo "Using BASE_IMAGE=$BASE_IMAGE" ;\
9+
DEBIAN_FRONTEND=noninteractive apt-get update -qq ;\
10+
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
11+
build-essential \
12+
fakeroot \
13+
pkg-config \
14+
debhelper \
15+
devscripts \
16+
zlib1g-dev \
17+
postgresql-server-dev-all
1118

1219
WORKDIR /build/pgsql-gzip

Makefile

+16-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# Make sure we do not run any code when using deb-in-docker target
2-
ifneq ($(MAKECMDGOALS),"deb-in-docker")
1+
# Make sure we do not run any code when using deb-* target
2+
ifeq (,$(findstring deb-,$(MAKECMDGOALS)))
33

44
# Detect pkg-config on the path
55
PKGCONFIG := $(shell type -p pkg-config || echo NONE)
@@ -32,7 +32,7 @@ LIBS += $(ZLIB_LIB)
3232
SHLIB_LINK := $(LIBS)
3333

3434
ifdef DEBUG
35-
COPT += -O0 -g
35+
COPT += -O0 -g
3636
endif
3737

3838
PGXS := $(shell $(PG_CONFIG) --pgxs)
@@ -42,14 +42,18 @@ endif
4242

4343

4444
.PHONY: deb
45-
deb:
45+
deb: clean
46+
pg_buildext updatecontrol
4647
dpkg-buildpackage -B
4748

48-
.PHONY: deb-in-docker
49-
deb-in-docker: .image
50-
mkdir -p "$$(pwd)/target"
51-
docker run --rm -ti -v"$$(pwd)/target:/build" -v "$$(pwd):/build/pgsql-gzip" deb-builder make deb
52-
53-
.PHONY: .image
54-
.image:
55-
docker build -t deb-builder .
49+
# Name of the base Docker image to use. Uses debian:sid by default
50+
base ?= debian:sid
51+
52+
.PHONY: deb-docker
53+
deb-docker:
54+
@echo "*** Using base=$(base)"
55+
docker build "--build-arg=BASE_IMAGE=$(base)" -t pgsql-gzip-$(base) .
56+
# Create a temp dir that we will remove later. Otherwise docker will create a root-owned dir.
57+
mkdir -p "$$(pwd)/target/pgsql-gzip"
58+
docker run --rm -ti -u $$(id -u $${USER}):$$(id -g $${USER}) -v "$$(pwd)/target:/build" -v "$$(pwd):/build/pgsql-gzip" pgsql-gzip-$(base) make deb
59+
rmdir "$$(pwd)/target/pgsql-gzip" || true

README.md

+27-7
Original file line numberDiff line numberDiff line change
@@ -61,21 +61,41 @@ To convert a `bytea` back into an equivalent `text` you must use the `encode()`
6161

6262
### UNIX
6363

64-
If you have PostgreSQL devel packages and zlib installed, you should have `pg_config` on your path, so you should be able to just run `make`, then `make install`, then in your database `CREATE EXTENSION gzip`.
64+
If you have PostgreSQL devel packages (`postgresql-server-dev-all`) and zlib (`zlib1g-dev`) installed, you should have `pg_config` on your path, so you should be able to just run `make`, then `make install`, then in your database `CREATE EXTENSION gzip`.
6565

6666
If your `libz` is installed in a non-standard location, you may need to edit `ZLIB_PATH` in the `Makefile`.
6767

68-
#### Debain/Ubuntu
68+
### Debain/Ubuntu
6969

70-
To build the DEB package make use you have following dependencies installed as well:
70+
```bash
71+
sudo apt-get install build-essential zlib1g-dev postgresql-server-dev-all pkg-config
72+
make
73+
make install
74+
psql ... -c "CREATE EXTENSION gzip"
75+
```
76+
77+
To build the DEB package you will also need `fakeroot` and `devscripts`. See [Dockerfile](./Dockerfile) for a full list.
7178

7279
```bash
73-
> apt-get install build-essential fakeroot devscripts
80+
sudo apt-get install build-essential zlib1g-dev postgresql-server-dev-all pkg-config fakeroot devscripts
81+
make
82+
make deb
83+
dpkg -i <path to package>.deb
7484
```
7585

76-
And you will be able to run the `make deb` and get the packege wich can be installed with `dpkg -i <path to package>.deb`
86+
And you will be able to run the `make deb` and get the packege wich can be installed with ``
87+
88+
89+
#### deb package build using Docker
7790

91+
Makefile has targets for building the DEB package using Docker image with different base images. This approach only requires `make` and `docker` to be available on the host.
7892

79-
#### In Docker
93+
```bash
94+
make deb-latest # Uses debian:sid
95+
```
96+
97+
To build an image using a different base, supply it with a parameter:
8098

81-
Makefile has a special target for building the DEB packager directly in the docker by running `make deb-in-docker`. Where the `debian:sid` will be used to prepare the image with all the dependencies and the `make deb` target will be run inside it.
99+
```bash
100+
make deb-docker base=debian:latest
101+
```

debian/changelog

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
pgsql-gzip (1.0.0) unstable; urgency=medium
1+
pgsql-gzip (1.0.1) unstable; urgency=medium
2+
* DEB package cleanup, docker build improvements, readme updates [Yuri Astrakhan <[email protected]>]
3+
-- Yuri Astrakhan <[email protected]> Tue, 21 Apr 2020 22:21:00 +0000
24

5+
pgsql-gzip (1.0.0) unstable; urgency=medium
36
* Initial release of the DEB package
4-
57
-- Oleksandr Kylymnychenko <[email protected]> Fri, 20 Mar 2020 13:18:29 +0000

debian/control

-17
This file was deleted.

0 commit comments

Comments
 (0)