Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build ARM docker images #30

Closed
viniciusd opened this issue Aug 9, 2023 · 12 comments · Fixed by #160
Closed

Build ARM docker images #30

viniciusd opened this issue Aug 9, 2023 · 12 comments · Fixed by #160

Comments

@viniciusd
Copy link

I was trying to run pgmq on my MacBook, and I noticed pgmq doesn't support ARM docker images.

The current Docker manifest on quay.io is:

{
	"schemaVersion": 2,
	"mediaType": "application/vnd.docker.distribution.manifest.v2+json",
	"config": {
		"mediaType": "application/vnd.docker.container.image.v1+json",
		"size": 7269,
		"digest": "sha256:3f0d3cf9de2a09d00fd4c9d2aecb1e5dbcaf20c591066fb8d42547007112f8c7"
	},
	"layers": [
		// [...]
	]
}

projectcalico/calico#4227 might be helpful here.

The image itself builds successfully on ARM:

docker build -t tembo-pgmq .                                                                                                                                                                                   [i]
[+] Building 264.9s (21/21) FINISHED
 => [internal] load build definition from Dockerfile                                                                                                                                                            0.0s
 => => transferring dockerfile: 2.18kB                                                                                                                                                                          0.0s
 => [internal] load .dockerignore                                                                                                                                                                               0.0s
 => => transferring context: 2B                                                                                                                                                                                 0.0s
 => [internal] load metadata for quay.io/coredb/ubuntu:22.04                                                                                                                                                    0.0s
 => [internal] load build context                                                                                                                                                                               0.0s
 => => transferring context: 52.30kB                                                                                                                                                                            0.0s
 => CACHED [builder 1/4] FROM quay.io/coredb/ubuntu:22.04                                                                                                                                                       0.0s
 => [builder 2/4] RUN apt-get update && apt-get install -y curl pkg-config libssl-dev build-essential libclang-dev clang software-properties-common                                                            56.3s
 => [builder 3/4] RUN curl https://sh.rustup.rs -sSf | sh -s -- -y                                                                                                                                             17.0s
 => [builder 4/4] RUN /root/.cargo/bin/cargo install pg-trunk                                                                                                                                                 110.1s
 => [stage-1  2/13] COPY --from=builder /root/.cargo/bin/trunk /usr/bin/trunk                                                                                                                                   0.1s
 => [stage-1  3/13] RUN set -eux;  groupadd -r postgres --gid=999;  useradd -r -g postgres --uid=999 --home-dir=/var/lib/postgresql --shell=/bin/bash postgres;  mkdir -p /var/lib/postgresql;  chown -R postg  0.2s
 => [stage-1  4/13] RUN apt-get update && apt-get install -y         curl ca-certificates gnupg lsb-release         && rm -rf /var/lib/apt/lists/*                                                             16.6s
 => [stage-1  5/13] RUN curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor | tee /etc/apt/trusted.gpg.d/apt.postgresql.org.gpg > /dev/null                                                 0.7s
 => [stage-1  6/13] RUN echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list                                                                     0.4s
 => [stage-1  7/13] RUN set -eux;  apt-get update; apt-get install -y --no-install-recommends locales; rm -rf /var/lib/apt/lists/*;  localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UT  7.9s
 => [stage-1  8/13] RUN mkdir /docker-entrypoint-initdb.d                                                                                                                                                       0.3s
 => [stage-1  9/13] RUN apt-get update && apt-get install -y         build-essential         git         postgresql-server-dev-15         postgresql-contrib         postgresql-15         && rm -rf /var/lib  49.4s
 => [stage-1 10/13] COPY ./postgresql.conf /usr/share/postgresql/15/postgresql.conf.sample                                                                                                                      0.0s
 => [stage-1 11/13] RUN trunk install pg_partman                                                                                                                                                                1.2s
 => [stage-1 12/13] RUN trunk install pgmq --version 0.10.0                                                                                                                                                     1.7s
 => [stage-1 13/13] COPY docker-entrypoint.sh /usr/local/bin/                                                                                                                                                   0.0s
 => exporting to image                                                                                                                                                                                          2.7s
 => => exporting layers                                                                                                                                                                                         2.7s
 => => writing image sha256:f52315cee15d133f817cbdcbcdf7174d9c05cc8fc52182064b35339ba7ab6ded                                                                                                                    0.0s
 => => naming to docker.io/library/tembo-pgmq

But it fails to run. The error log on Docker is:

performing post-bootstrap initialization ... 2023-08-09T14:45:01.748776458Z 2023-08-09 14:45:01.748 UTC [27] FATAL:  could not access file "pg_partman_bgw": No such file or directory

This is due to pg_partman_bgw not being installed. Its installation fails due to tembo-io/trunk#377, which blocks this issue.

@ChuckHend
Copy link
Member

We can probably get around tembo-io/trunk#377 by installing pg_partman from source in the docker build instead of using trunk install for it.

@ChuckHend
Copy link
Member

It is messy but as an example, pg_partman is installed from source in CI

git clone https://github.com/pgpartman/pg_partman.git && \
cd pg_partman && \
sudo make install && cd ../
cp /usr/share/postgresql/14/extension/pg_partman* ~/.pgrx/15.3/pgrx-install/share/postgresql/extension/
cp /usr/lib/postgresql/14/lib/pg_partman_bgw.so ~/.pgrx/15.3/pgrx-install/lib/postgresql/

@viniciusd
Copy link
Author

I can definitely make these changes, but I do like the idea of building on top of trunk. After all, gotta eat your own dog food.

I would be fine with:

  1. A PR to build from source while trunk itself doesn't do multi-arch
  2. A PR to build both containers and upload them to quay.io
  3. Reverting (1) when trunk support is added

Or would you rather go with building from source + multi-arch on pgmq independent from trunk?

@ChuckHend
Copy link
Member

I can definitely make these changes, but I do like the idea of building on top of trunk. After all, gotta eat your own dog food.

I would be fine with:

  1. A PR to build from source while trunk itself doesn't do multi-arch
  2. A PR to build both containers and upload them to quay.io
  3. Reverting (1) when trunk support is added

Or would you rather go with building from source + multi-arch on pgmq independent from trunk?

No, just build from source as a temporary fix/until trunk install supports multi-arch. trunk build then trunk install --file might even work too.

@viniciusd
Copy link
Author

I am on it then. pg_partman installation is fine already.

But how do I trunk build pgmq?

I am trying trunk build straight from the pgmq directory, but I get the following error message:

0.718 Trunk.toml not found
0.718 Building from path .
0.720 Detected that we are building a pgrx extension
0.720 Detected pgrx version range 0.9.8
0.720 Using pgrx version 0.9.8
0.720 Building pgrx extension at path .
0.723 [/usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/pg-trunk-0.8.7/src/commands/containers.rs:343] &err = HyperResponseError {
0.723     err: hyper::Error(
0.723         Connect,
0.723         Os {
0.723             code: 2,
0.723             kind: NotFound,
0.723             message: "No such file or directory",
0.724         },
0.724     ),
0.724 }
0.724 thread 'main' panicked at 'error occurred: Other error: error trying to connect: No such file or directory (os error 2)
0.724
0.724 Caused by:
0.724     0: error trying to connect: No such file or directory (os error 2)
0.724     1: No such file or directory (os error 2)', /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/pg-trunk-0.8.7/src/main.rs:59:6
0.724 stack backtrace:
0.740    0: rust_begin_unwind
0.740              at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/panicking.rs:578:5
0.740    1: core::panicking::panic_fmt
0.740              at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/core/src/panicking.rs:67:14
0.740    2: core::result::unwrap_failed
0.740              at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/core/src/result.rs:1687:5
0.741    3: trunk::main
0.741 note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

I am looking into the code of containers.rs to try to figure it out as I have a high-level idea of how trunk build works thanks to @sjmiller609. The error message alone isn't very helpful as it doesn't indicate which file is missing.

I can delve into debugging it, but I am sure you are already familiar with building pgmq with trunk.

@ChuckHend
Copy link
Member

We build pgmq with trunk in ci,

run: trunk build

No extra flags, but there were some changes to the trunk cli and registry recently. Maybe check that you're on the latest version, >0.10, I believe.

Thank you for digging into this!

@ChuckHend
Copy link
Member

@viniciusd , hopefully we are able to support this via #160

@ChuckHend
Copy link
Member

@viniciusd, we ARM images for linux!

@viniciusd
Copy link
Author

@viniciusd, we ARM images for linux!

Thanks for the updates! I am trying to get my schedule in order to get back to OSS/tinkering around

@joelawm
Copy link
Contributor

joelawm commented Mar 30, 2024

While trying to install on a existing container postgres:16 I am doing the following and getting. @ChuckHend

# trunk install pgmq
Using pkglibdir: "/usr/lib/postgresql/16/lib"
Using sharedir: "/usr/share/postgresql/16"
Using Postgres version: 16
info: Downloading from: https://cdb-plat-use1-prod-pgtrunkio.s3.amazonaws.com/extensions/pgmq/pgmq-pg16-1.1.1.tar.gz
info: Dependent extensions to be installed: []
info: Installing pgmq 1.1.1

error: This package is not compatible with your architecture: aarch64, it is compatible with x86_64

I see above the PR 160 was only for linux arm so thats probably the cause. If we can get this working I don't mind doing a write up for it to help others. I think most people that would use pgmq would add it to a existing Postgres instance and not pull a new container but I could be wrong. Anyways love the PGMQ though it works super well on my linux machine!

@ChuckHend
Copy link
Member

hey @joelawm, I'm glad you like the project! trunk only supports x86 at the moment which means if you want to install pgmq on an existing postgres instance thats not running on x86, you'll most likely need to build it from source. Can you give that a try and let me know how it goes?

@joelawm
Copy link
Contributor

joelawm commented Mar 30, 2024

@ChuckHend oh of course yes I can! This is the documentation I was looking for haha

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants