Skip to content

Enhancements to docker images #108

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

Merged
merged 9 commits into from
Nov 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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
3 changes: 0 additions & 3 deletions ansible/files/docker_mnt/init.sh

This file was deleted.

40 changes: 2 additions & 38 deletions ansible/playbook-docker.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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
import_tasks: tasks/docker/cleanup.yml
51 changes: 1 addition & 50 deletions ansible/tasks/docker/cleanup.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


- name: Cleanup - remove build dependencies
apt:
pkg:
Expand All @@ -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 }}"


state: absent
31 changes: 11 additions & 20 deletions ansible/tasks/docker/setup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'"
Expand All @@ -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
1 change: 1 addition & 0 deletions ansible/tasks/postgres-extensions/13-plv8.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down