Last active
November 23, 2023 21:47
-
-
Save nenodias/28ac55b9ad3fda43a9de63a9efb82d18 to your computer and use it in GitHub Desktop.
Python Docker Compose.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: '3' | |
services: | |
web: | |
image: python:3.5 | |
command: | |
- /bin/sh | |
- -c | |
- | | |
echo "Instalando postgresql" | |
export PGDATA=/opt/postgresql/data | |
wget https://gist.githubusercontent.com/nenodias/28ac55b9ad3fda43a9de63a9efb82d18/raw/c4c75e8b89d2a20b02e56a54d3446a69a2c00e29/postgres_install.py | |
chmod -Rf 777 /opt | |
useradd postgres | |
su -c "python postgres_install.py" -s /bin/sh postgres | |
echo "Concluído" | |
cd ${working_dir} | |
git clone https://github.com/nenodias/millenium.git project | |
cd project | |
git checkout deploy | |
git pull origin deploy | |
/usr/local/bin/pip install -r requirements.txt | |
echo "App starting" | |
/usr/local/bin/gunicorn wsgi:application --bind=0.0.0.0:8000 | |
environment: | |
DATABASE_URL: postgresql://[email protected]:5432/millenium | |
volumes: | |
- ./postgres-data:/opt/postgresql/data | |
- ${PWD}/project:/home/docker/ | |
working_dir: /home/docker/ | |
ports: | |
- "8000:8000" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""PGInstaller.""" | |
import time | |
import threading | |
import os | |
import sys | |
import subprocess | |
PG_FILE = "postgresql-9.6.4-1-linux-x64-binaries.tar.gz" | |
# PG_URL = "https://get.enterprisedb.com/\ | |
PG_URL = "http://192.168.0.38:8888/\ | |
postgresql/"+PG_FILE | |
PG_ROOT = '/opt/postgresql' | |
PG_DATA_ROOT = PG_ROOT + '/data' | |
PG_DIR = '/opt/pgsql' | |
PG_EXEC = PG_DIR + '/bin' | |
os.chdir('/opt') | |
# instalando | |
pgsql_valid = os.path.isdir(PG_DIR) and os.path.exists(PG_DIR) | |
if not pgsql_valid: | |
subprocess.call("wget "+PG_URL, shell=True) | |
subprocess.call('tar -zxvf '+PG_FILE, shell=True) | |
subprocess.call('rm -r '+PG_FILE, shell=True) | |
valid = os.path.isdir(PG_ROOT) and os.path.exists(PG_DATA_ROOT) | |
up = False | |
def iniciar_postgres(): | |
"""Method up postgres.""" | |
global up | |
try: | |
inicio = PG_EXEC+'/postgres' | |
chamada = inicio, ' -D ', PG_DATA_ROOT | |
chamada = "{0}".format(chamada) | |
p = subprocess.Popen( | |
['su', '-c', chamada, '/bin/sh', 'postgres'], | |
stdin=subprocess.PIPE, | |
shell=False | |
) | |
time.sleep(1) | |
up = True | |
p.communicate(input=b'\n') | |
except Exception as ex: | |
print(ex) | |
t1 = threading.Thread(target=iniciar_postgres, name='t_postgres') | |
if not valid: | |
os.mkdir(PG_ROOT) | |
os.mkdir(PG_DATA_ROOT) | |
subprocess.call(PG_EXEC+'/initdb ' + PG_DATA_ROOT, shell=True) | |
time.sleep(2) | |
t1.start() | |
while not up: | |
pass | |
subprocess.call(PG_EXEC+'/createuser postgres', shell=True) | |
subprocess.call(PG_EXEC+'/createdb millenium', shell=True) | |
sys.exit(1) | |
else: | |
t1.start() | |
sys.exit(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment