diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..526c8a3 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +*.sh text eol=lf \ No newline at end of file diff --git a/.gitignore b/.gitignore index a9a5aec..27b8322 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ tmp +.idea diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..34979ba --- /dev/null +++ b/.travis.yml @@ -0,0 +1,10 @@ +services: + - docker + +install: + - echo "$DOCKER_PASSWORD" | docker login -u jefftian --password-stdin + + +script: + - docker build -t jefftian/bucardo . + - docker push jefftian/bucardo diff --git a/Dockerfile b/Dockerfile index 64baca2..8f6986b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,22 +3,45 @@ FROM ubuntu:xenial LABEL maintainer="lucas@vieira.io" LABEL version="1.0" +ENV PG_VERSION 12 + +RUN apt-get update \ + && apt-get -y install software-properties-common wget jq netcat + +RUN add-apt-repository \ + "deb http://apt.postgresql.org/pub/repos/apt/ xenial-pgdg main" + +RUN wget -q -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - + RUN apt-get -y update \ && apt-get -y upgrade -RUN apt-get -y install postgresql-9.5 bucardo jq +RUN apt-get -y install postgresql-${PG_VERSION} postgresql-plperl-${PG_VERSION} libdbi-perl libpq-dev libdbd-pg-perl libdbix-safe-perl -COPY etc/pg_hba.conf /etc/postgresql/9.5/main/ +RUN apt-get -y install build-essential git +RUN git clone https://github.com/bucardo/bucardo +RUN cd bucardo && perl Makefile.PL && make && make install + +RUN apt-get -y install vim + +COPY etc/pg_hba.conf /etc/postgresql/${PG_VERSION}/main/ COPY etc/bucardorc /etc/bucardorc -RUN chown postgres /etc/postgresql/9.5/main/pg_hba.conf +RUN chown postgres /etc/postgresql/${PG_VERSION}/main/pg_hba.conf RUN chown postgres /etc/bucardorc -RUN chown postgres /var/log/bucardo +RUN mkdir -p /var/log/bucardo +RUN touch /var/log/bucardo/log.bucardo +RUN chown postgres /var/log/bucardo/log.bucardo RUN mkdir /var/run/bucardo && chown postgres /var/run/bucardo +RUN groupadd bucardo RUN usermod -aG bucardo postgres RUN service postgresql start \ - && su - postgres -c "bucardo install --batch" + && service postgresql status \ + && su - postgres -c "bucardo install --batch && bucardo set log_level=debug" + +COPY etc/bucardorc2 /etc/bucardorc +RUN chown postgres /etc/bucardorc COPY lib/entrypoint.sh /entrypoint.sh RUN chmod +x /entrypoint.sh diff --git a/build.bat b/build.bat new file mode 100644 index 0000000..336c3be --- /dev/null +++ b/build.bat @@ -0,0 +1 @@ +docker build -t jefftian/bucardo . \ No newline at end of file diff --git a/etc/bucardorc b/etc/bucardorc index 1829168..c8b9fa9 100644 --- a/etc/bucardorc +++ b/etc/bucardorc @@ -1,3 +1,3 @@ dbport = 5432 -dbuser = bucardo -dbname = bucardo +dbuser = postgres +dbname = bucardo \ No newline at end of file diff --git a/etc/bucardorc2 b/etc/bucardorc2 new file mode 100644 index 0000000..a620ffd --- /dev/null +++ b/etc/bucardorc2 @@ -0,0 +1,3 @@ +dbport = 5432 +dbuser = bucardo +dbname = bucardo \ No newline at end of file diff --git a/etc/pg_hba.conf b/etc/pg_hba.conf index d3e4e9d..6d5c7b5 100644 --- a/etc/pg_hba.conf +++ b/etc/pg_hba.conf @@ -3,3 +3,7 @@ local bucardo bucardo md5 local all all peer host all all 127.0.0.1/32 md5 host all all ::1/128 md5 + +local all all trust +host all all 127.0.0.1/32 trust +host all all ::1/128 trust diff --git a/lib/entrypoint.sh b/lib/entrypoint.sh index deab014..e9676ae 100644 --- a/lib/entrypoint.sh +++ b/lib/entrypoint.sh @@ -158,17 +158,26 @@ add_syncs_to_bucardo() { db_sync_string $sync_index local one_time_copy="$(one_time_copy_attr $sync_index)" run_bucardo_command "del sync sync$sync_index" + echo "will adding ..." + echo "add sync sync$sync_index \ + dbs=$DB_STRING \ + tables=$(sync_attr $sync_index tables list) \ + onetimecopy=$one_time_copy conflict_strategy=latest" + run_bucardo_command "add sync sync$sync_index \ dbs=$DB_STRING \ tables=$(sync_attr $sync_index tables list) \ - onetimecopy=$one_time_copy" + onetimecopy=$one_time_copy conflict_strategy=latest" + + echo "added" + sync_index=$(expr $sync_index + 1) done } start_bucardo() { echo "[CONTAINER] Starting Bucardo..." - run_bucardo_command "start" + run_bucardo_command "start --verbose" } bucardo_status() {