pg_amqp
pg_amqp copied to clipboard
Alpine linux build fails
How can I build this repo in docker official alpine based postgres image. I am getting compile error:
gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -O2 -fpic -I. -I./ -I/usr/local/include/postgresql/server -I/usr/local/include/postgresql/internal -D_GNU_SOURCE -I/usr/include/libxml2 -c -o src/librabbitmq/amqp_socket.o src/librabbitmq/amqp_socket.c
In file included from src/librabbitmq/amqp_socket.c:10:0:
src/librabbitmq/amqp.h:177:36: warning: 'struct timeval' declared inside parameter list will not be visible outside of this definition or declaration
struct timeval *timeout);
^~~~~~~
src/librabbitmq/amqp_socket.c:23:5: error: conflicting types for 'amqp_open_socket'
int amqp_open_socket(char const *hostname,
^~~~~~~~~~~~~~~~
In file included from src/librabbitmq/amqp_socket.c:10:0:
src/librabbitmq/amqp.h:176:12: note: previous declaration of 'amqp_open_socket' was here
extern int amqp_open_socket(char const *hostname, int portnumber,
^~~~~~~~~~~~~~~~
make: *** [<builtin>: src/librabbitmq/amqp_socket.o] Error 1
Dockerfile content:
FROM postgres:9-alpine
RUN apk update && \
apk add git alpine-sdk && \
git clone https://github.com/omniti-labs/pg_amqp.git /tmp/pg_ampq && \
cd /tmp/pg_ampq && \
make && make install
Hey, This works for me. Added include to types.h:
FROM postgres:12-alpine as builder
RUN apk update && apk add git make gcc linux-headers libc-dev libxml2-dev alpine-sdk musl-dev
RUN git clone https://github.com/omniti-labs/pg_amqp.git workdir
ARG AMQP_H=src/librabbitmq/amqp.h
RUN cd workdir \
&& head -n 2 ${AMQP_H} > ${AMQP_H}.temp \
&& echo "#include <sys/types.h>" >> ${AMQP_H}.temp \
&& cat ${AMQP_H} | sed -e '1,3d' >> ${AMQP_H}.temp \
&& mv ${AMQP_H}.temp ${AMQP_H}
RUN cd workdir && make && make install
FROM postgres:12-alpine
COPY --from=builder /usr/local/lib/postgresql/pg_amqp.so /usr/local/lib/postgresql/pg_amqp.so
COPY --from=builder /usr/local/share/postgresql/extension /usr/local/share/postgresql/extension
COPY --from=builder /usr/local/share/doc/postgresql/extension /usr/local/share/doc/postgresql/extension
RUN chmod 755 /usr/local/lib/postgresql/pg_amqp.so \
&& chmod 644 /usr/local/share/postgresql/extension/amqp.control \
&& chmod 644 /usr/local/share/postgresql/extension/amqp--0.3.0--0.4.0.sql \
&& chmod 644 /usr/local/share/postgresql/extension/amqp--0.4.0--0.4.1.sql \
&& chmod 644 /usr/local/share/postgresql/extension/amqp--0.4.2.sql \
&& chmod 777 /usr/local/share/postgresql/extension/
I know that 777
is not recommended but it was for my local testing.
Hello, having the same issue and same error. @inbarbarkai even tried to run your dockerfile still the same error and terminate docker execution.
@sohrabq Here is a updated docker with the latest alpine
version.
# Docker file for postgres with pg_amqp extension installed and configured to use RabbitMQ
FROM postgres:alpine
RUN apk update && apk add git make gcc linux-headers libc-dev libxml2-dev alpine-sdk musl-dev postgresql-dev rabbitmq-c-dev
RUN git clone https://github.com/omniti-labs/pg_amqp.git workdir
ARG AMQP_H=src/librabbitmq/amqp.h
RUN cd workdir \
&& head -n 2 ${AMQP_H} > ${AMQP_H}.temp \
&& echo "#include <sys/types.h>" >> ${AMQP_H}.temp \
&& cat ${AMQP_H} | sed -e '1,3d' >> ${AMQP_H}.temp \
&& mv ${AMQP_H}.temp ${AMQP_H}
RUN cd workdir && make && make install