diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..110f70aaf --- /dev/null +++ b/Dockerfile @@ -0,0 +1,21 @@ +ARG PLATFORM +ARG VERSION + +FROM --platform=$PLATFORM postgres:$VERSION + +COPY ansible/ /tmp/ansible/ + +RUN apt update && \ + apt install -y ansible && \ + cd /tmp/ansible && \ + ansible-playbook playbook-docker.yml && \ + apt -y update && \ + apt -y upgrade && \ + apt -y autoremove && \ + apt -y autoclean && \ + apt install -y default-jdk-headless && \ + rm -rf /tmp/* /var/lib/apt/lists/* /var/tmp/* + +ENV LANGUAGE=en_US.UTF-8 +ENV LANG=en_US.UTF-8 +ENV LC_ALL=en_US.UTF-8 \ No newline at end of file diff --git a/ansible/files/docker_mnt/init.sh b/ansible/files/docker_mnt/init.sh deleted file mode 100644 index fd12bbe4a..000000000 --- a/ansible/files/docker_mnt/init.sh +++ /dev/null @@ -1,3 +0,0 @@ -cat /etc/postgresql/postgresql.conf > $PGDATA/postgresql.conf -echo "host replication $POSTGRES_USER 0.0.0.0/0 trust" >> $PGDATA/pg_hba.conf -echo "host all all 127.0.0.1/32 trust" >> $PGDATA/pg_hba.conf \ No newline at end of file diff --git a/ansible/playbook-docker.yml b/ansible/playbook-docker.yml index ea699339f..abeb15428 100644 --- a/ansible/playbook-docker.yml +++ b/ansible/playbook-docker.yml @@ -1,26 +1,5 @@ -- name: Preparing Docker container - hosts: localhost - tasks: - - name: Pull Postgres Image - docker_container: - name: "supabase-postgres-build" - image: "postgres:13.3" - env: - LANGUAGE: "en_US.UTF-8" - LANG: "en_US.UTF-8" - LC_ALL: "en_US.UTF-8" - state: started - memory: 4G - memory_swap: 6G - command: tail -f /dev/null - - name: Add Postgres Image to Ansible Hosts - add_host: - name: "supabase-postgres-build" - ansible_connection: docker - ansible_ssh_user: root - - name: Build Supabase Postgres - hosts: "supabase-postgres-build" + hosts: localhost gather_facts: false vars_files: @@ -34,19 +13,4 @@ import_tasks: tasks/setup-extensions.yml - name: Cleanup container - import_tasks: tasks/docker/cleanup.yml - -- name: Create supabase/postgres docker image - hosts: localhost - tasks: - - name: Commit Docker image - command: docker commit --change='CMD ["postgres"]' "supabase-postgres-build" "supabase/postgres" - -- name: Clean Up Postgres Image - hosts: localhost - tasks: - - name: Remove Running Base Image - docker_container: - name: supabase-postgres-build - state: absent - force_kill: yes \ No newline at end of file + import_tasks: tasks/docker/cleanup.yml \ No newline at end of file diff --git a/ansible/tasks/docker/cleanup.yml b/ansible/tasks/docker/cleanup.yml index 4552d8030..177a5f847 100644 --- a/ansible/tasks/docker/cleanup.yml +++ b/ansible/tasks/docker/cleanup.yml @@ -1,5 +1,3 @@ - - - name: Cleanup - remove build dependencies apt: pkg: @@ -17,51 +15,4 @@ - cmake - ninja-build - python - state: absent - -- name: Cleanup - apt update and apt upgrade - apt: update_cache=yes upgrade=yes - # SEE http://archive.vn/DKJjs#parameter-upgrade - -- name: Cleanup - remove dependencies that are no longer required - apt: - autoremove: yes - -- name: Cleanup - remove useless packages from the cache - apt: - autoclean: yes - -- name: Cleanup - reinstall headless jdk - apt: - pkg: - - default-jdk-headless - update_cache: yes - install_recommends: no - -- name: Cleanup - find all files in /tmp - find: - paths: /tmp - file_type: any - register: tmp_items_to_delete - -- name: Cleanup - delete all items in /tmp - file: - path: "/tmp/{{ item.path | basename }}" - state: absent - force: yes - with_items: "{{ tmp_items_to_delete.files }}" - -- name: Cleanup - find all files in /var/lib/apt/lists/* - find: - paths: /var/lib/apt/lists - file_type: any - register: var_items_to_delete - -- name: Cleanup - delete all items in /tmp - file: - path: "/var/lib/apt/lists/{{ item.path | basename }}" - state: absent - force: yes - with_items: "{{ var_items_to_delete.files }}" - - \ No newline at end of file + state: absent \ No newline at end of file diff --git a/ansible/tasks/docker/setup.yml b/ansible/tasks/docker/setup.yml index d669f8870..433680285 100644 --- a/ansible/tasks/docker/setup.yml +++ b/ansible/tasks/docker/setup.yml @@ -30,7 +30,17 @@ - name: Setup - import postgresql.conf synchronize: src: files/postgresql_config/postgresql.conf.j2 - dest: etc/postgresql/postgresql.conf + dest: /etc/postgresql/postgresql.conf + +- name: Setup - import postgresql.conf + synchronize: + src: files/postgresql_config/pg_hba.conf.j2 + dest: /etc/postgresql/pg_hba.conf + +- name: Setup - import postgresql.conf + synchronize: + src: files/postgresql_config/pg_ident.conf.j2 + dest: /etc/postgresql/pg_ident.conf - set_fact: regex_string: "#unix_socket_directories = '/tmp'" @@ -48,22 +58,3 @@ path: /etc/postgresql/postgresql.conf regexp: '{{ regex_string }}' replace: unix_socket_directories = '/var/run/postgresql' - -- name: Setup - modify hba_file directory - become: yes - replace: - path: /etc/postgresql/postgresql.conf - regexp: hba_file = '/etc/postgresql/pg_hba.conf' - replace: hba_file = '/var/lib/postgresql/data/pg_hba.conf' - -- name: Setup - modify ident_file directory - become: yes - replace: - path: /etc/postgresql/postgresql.conf - regexp: ident_file = '/etc/postgresql/pg_ident.conf' - replace: ident_file = '/var/lib/postgresql/data/pg_ident.conf' - -- name: Setup - add init script to /docker-entrypoint-initdb.d - synchronize: - src: files/docker_mnt/init.sh - dest: /docker-entrypoint-initdb.d/init.sh \ No newline at end of file diff --git a/ansible/tasks/postgres-extensions/13-plv8.yml b/ansible/tasks/postgres-extensions/13-plv8.yml index 36c11a449..48e8830f0 100644 --- a/ansible/tasks/postgres-extensions/13-plv8.yml +++ b/ansible/tasks/postgres-extensions/13-plv8.yml @@ -35,6 +35,7 @@ dest: /lib/aarch64-linux-gnu/libc++.so state: link when: platform == "arm64" + ignore_errors: yes # not needed for docker build - name: plv8 - build make: