first commit
This commit is contained in:
commit
5cd649b741
|
|
@ -0,0 +1,7 @@
|
||||||
|
FROM python:3.10
|
||||||
|
WORKDIR /app
|
||||||
|
COPY requirements.txt /app/requirements.txt
|
||||||
|
RUN pip install --no-cache-dir -r /app/requirements.txt
|
||||||
|
COPY . /app
|
||||||
|
|
||||||
|
CMD ["python", "app.py"]
|
||||||
|
|
@ -0,0 +1,25 @@
|
||||||
|
import psycopg2
|
||||||
|
|
||||||
|
print('Can`t establish connection to database')
|
||||||
|
|
||||||
|
'''
|
||||||
|
conn = psycopg2.connect(
|
||||||
|
dbname="kolchin",
|
||||||
|
user="kolchin",
|
||||||
|
password="postgres",
|
||||||
|
host="pg",
|
||||||
|
port="5432"
|
||||||
|
)
|
||||||
|
|
||||||
|
cursor = conn.cursor()
|
||||||
|
|
||||||
|
with conn.cursor() as curs:
|
||||||
|
curs.execute(CREATE TABLE IF NOT EXISTS tablee(
|
||||||
|
name varchar(10) NOT NULL,
|
||||||
|
surname varchar,
|
||||||
|
city varchar,
|
||||||
|
age smallint
|
||||||
|
);)
|
||||||
|
conn.commit()
|
||||||
|
conn.close()
|
||||||
|
'''
|
||||||
|
|
@ -0,0 +1,18 @@
|
||||||
|
--create database test_db;
|
||||||
|
--create user test_user with encrypted password '123';
|
||||||
|
--grant all privileges on database test_db to test_user;
|
||||||
|
CREATE TABLE IF NOT EXISTS test_table(
|
||||||
|
--id INT PRIMARY KEY,
|
||||||
|
name varchar(10) NOT NULL,
|
||||||
|
surname varchar,
|
||||||
|
city varchar,
|
||||||
|
age smallint
|
||||||
|
);
|
||||||
|
|
||||||
|
insert into test_table (name, surname, city, age)
|
||||||
|
values ('Aleksandr', 'Kolchin', 'Murmansk', 27), ('Dima', 'Ivanov', 'Moscow', 20), ('Petr', 'Sevanov', 'Omsk', 30), ('Oleg', 'Solop', 'Moscow', 25),
|
||||||
|
('Aleksandr', 'Bistrov', 'Kaliningrad', 22), ('Ivan', 'Kochev', 'Apatity', 33), ('Sergey', 'Sergeev', 'Piter', 25), ('Nikita', 'Korol', 'Voronezh', 25),
|
||||||
|
('Semen', 'Semenov', 'Yaroslavl', 26), ('Yaroslav', 'Vaneev', 'Kirov', 39), ('Oleg', 'Simonov', 'Moscow', 20), ('Nikita', 'Levin', 'Murmansk', 29),
|
||||||
|
('Sergey', 'Moiseev', 'Apatity', 19), ('Roman', 'Padorin', 'Orel', 32), ('Petr', 'Krychkov', 'Kandalaksha', 26), ('Stas', 'Kotin', 'Norilsk', 21),
|
||||||
|
('Boris', 'Kolyshkin', 'Polyarniy', 20), ('Konstantin', 'Lenin', 'Moscow', 25), ('Boris', 'Safonov', 'Severomorsk', 17), ('Ivan', 'Kolyshkin', 'Murmansk', 42);
|
||||||
|
|
||||||
|
|
@ -0,0 +1,51 @@
|
||||||
|
name: pg_and_pgadmin
|
||||||
|
services:
|
||||||
|
pg:
|
||||||
|
image: postgres:17.0-bookworm
|
||||||
|
container_name: postgres_new
|
||||||
|
environment:
|
||||||
|
POSTGRES_USER: kolchin
|
||||||
|
POSTGRES_PASSWORD: postgres
|
||||||
|
PGDATA: /var/lib/postgresql/data/pgdata
|
||||||
|
volumes:
|
||||||
|
- pg-data:/var/lib/postgresql/data
|
||||||
|
- ./db/:/docker-entrypoint-initdb.d
|
||||||
|
restart: unless-stopped
|
||||||
|
networks:
|
||||||
|
- pg-net
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD-SHELL", "pg_isready -U postgres"]
|
||||||
|
interval: 5s
|
||||||
|
timeout: 10s
|
||||||
|
retries: 3
|
||||||
|
pgadmin:
|
||||||
|
image: dpage/pgadmin4:8.12.0
|
||||||
|
container_name: pgadmin_new
|
||||||
|
environment:
|
||||||
|
PGADMIN_DEFAULT_EMAIL: user@example.com
|
||||||
|
PGADMIN_DEFAULT_PASSWORD: postgres
|
||||||
|
ports:
|
||||||
|
- 10501:80
|
||||||
|
restart: unless-stopped
|
||||||
|
networks:
|
||||||
|
- pg-net
|
||||||
|
depends_on:
|
||||||
|
pg:
|
||||||
|
condition: service_healthy
|
||||||
|
# app:
|
||||||
|
# build:
|
||||||
|
# context: ./
|
||||||
|
# args:
|
||||||
|
# PYTHON_VERSION: "3.10"
|
||||||
|
# UID: 10002
|
||||||
|
# container_name: python-app
|
||||||
|
# networks:
|
||||||
|
# - pg-net
|
||||||
|
# depends_on:
|
||||||
|
# pg:
|
||||||
|
# condition: service_healthy
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
pg-data:
|
||||||
|
networks:
|
||||||
|
pg-net:
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
psycopg2 == 2.8
|
||||||
Loading…
Reference in New Issue