docker file for postgresql

This commit is contained in:
tom moron
2024-08-11 20:35:58 +02:00
parent 3076c1514e
commit e16faf4f27
9 changed files with 66 additions and 4 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
*/.env

View File

@ -6,7 +6,7 @@
# By: tomoron <tomoron@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2024/07/13 16:18:56 by tomoron #+# #+# #
# Updated: 2024/08/10 15:24:25 by tomoron ### ########.fr #
# Updated: 2024/08/11 16:54:45 by tomoron ### ########.fr #
# #
# **************************************************************************** #
@ -20,16 +20,21 @@ build:
$(COMPOSE) build
up: build
mkdir -p ~/PTME_data
$(COMPOSE) up -d
up_att: build
mkdir -p ~/PTME_data
$(COMPOSE) up
down:
$(COMPOSE) down -v
fclean:
clean:
$(COMPOSE) down -v
docker system prune -af --volumes
fclean:clean
sudo rm -rf ~/PTME_data
re: fclean all
.PHONY: all build up up_att down fclean re

View File

@ -23,6 +23,23 @@ services:
ports:
- "9000:9000"
postgresql:
container_name: postgresql
env_file: .env
build:
context: requirements/postgresql
args:
DB_NAME: ${DB_NAME}
DB_USERNAME: ${DB_USERNAME}
DB_PASSWORD: ${DB_PASSWORD}
# volumes:
# - website_data:/var/www/djangoserver
networks:
- transcendence
restart: always
ports:
- "5432:5432"
volumes:
website_data:
driver: local

View File

@ -1,4 +1,4 @@
FROM debian:buster
FROM debian:bullseye
RUN apt update && apt upgrade -y

View File

@ -1,4 +1,4 @@
FROM nginx:latest
FROM nginx:bullseye
RUN mkdir -p /etc/nginx/ssl
RUN apt install -y openssl

View File

@ -0,0 +1,27 @@
FROM debian:bullseye
RUN apt update
RUN apt upgrade -y
RUN apt install postgresql postgresql-client -y
RUN sed -i 's/127.0.0.1\/32/0.0.0.0\/0/' /etc/postgresql/*/*/pg_hba.conf
RUN echo "listen_addresses = '*'" | tee -a /etc/postgresql/*/*/postgresql.conf
COPY setup.sh /root/setup.sh
COPY start.sh /root/start.sh
ARG DB_NAME=;
ARG DB_PASSWORD=;
ARG DB_USERNAME=;
ENV DB_NAME=${DB_NAME}
ENV DB_PASSWORD=${DB_PASSWORD}
ENV DB_USERNAME=${DB_USERNAME}
RUN sh /root/setup.sh
EXPOSE 5432
STOPSIGNAL SIGKILL
ENTRYPOINT ["/bin/sh","/root/start.sh"]

View File

@ -0,0 +1,7 @@
service postgresql start
su postgres << EOF
createdb $DB_NAME
psql -c "CREATE USER $DB_USERNAME WITH PASSWORD '$DB_PASSWORD'"
psql -c "GRANT ALL PRIVILEGES ON database $DB_NAME TO $DB_USERNAME"
EOF

View File

@ -0,0 +1,5 @@
service postgresql start
while :; do
sleep inf
done