Skip to content
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

40 func/setup prod #23

Closed
wants to merge 8 commits into from
Closed
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
51 changes: 51 additions & 0 deletions .github/workflows/deployEC2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Deploy to AWS EC2
on:
push:
branches:
- main
pull_request:
branches:
- main
env:
AWS_PRIVATE_KEY: ${{ secrets.KEYAWS }}
SSH_OPTIONS: '-o StrictHostKeyChecking=no -i key.pem ubuntu@98.80.44.121'

jobs:
deploy:
runs-on: ubuntu-24.04
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set permissions for private key
run: |
echo "${{ env.AWS_PRIVATE_KEY }}" > key.pem
chmod 600 key.pem

- name: Create target directory on AWS instance
run: |
ssh ${{ env.SSH_OPTIONS }} 'mkdir -p /home/ubuntu/tupan-back/'

- name: Create .env file
run: |
echo "DB_USER=${{ secrets.DB_USERNAME }}" >> .env
echo "DB_PASSWORD=${{ secrets.DB_PASSWORD }}" >> .env
echo "DB_NAME=${{ secrets.DB_NAME }}" >> .env
echo "DB_HOST=${{ secrets.DB_HOST }}" >> .env
echo "DB_PORT=${{ secrets.DB_PORT }}" >> .env

- name: Transfer code to AWS instance
run: |
rsync -av --exclude='.git' --exclude='.github' --exclude='.husky' -e "ssh -o StrictHostKeyChecking=no -i key.pem" ./ ubuntu@98.80.44.121:/home/ubuntu/tupan-back

- name: Stop running containers
run: |
ssh ${{ env.SSH_OPTIONS }} 'cd /home/ubuntu/tupan-back/ && sudo docker-compose down'

- name: Run Docker Compose
run: |
ssh ${{ env.SSH_OPTIONS }} 'cd /home/ubuntu/tupan-back/ && sudo docker-compose up'

- name: Cleanup SSH key
run: |
rm -f key.pem
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ name: Django CI

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
branches:
- '*'

jobs:
build:
Expand Down
20 changes: 20 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM python:3.11

# Definir o diretório de trabalho dentro do container
WORKDIR /app

# Copiar o arquivo de requisitos para o container
COPY requirements.txt /app/

# Instalar as dependências
RUN pip install --upgrade pip && pip install -r requirements.txt

# Copiar o código da aplicação
COPY . /app/

# Expôr a porta que o Django vai usar
EXPOSE 8000

# Comando para rodar o servidor
CMD ["python", "src/tupan/manage.py", "runserver", "0.0.0.0:8000"]

29 changes: 29 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
version: '3'

services:
web:
image: tupan-back
build: .
command: python src/tupan/manage.py runserver 0.0.0.0:8000
volumes:
- .:/app
ports:
- "8000:8000"
environment:
- DEBUG=True
- DATABASE_URL=postgres://postgres:fatec@db:5432:/tupan
restart: always
db:
image: postgres
environment:
POSTGRES_DB: tupan
POSTGRES_USER: postgres
POSTGRES_PASSWORD: fatec
ports:
- "5432:5432"
volumes:
- postgres_data:/var/lib/postgresql/data/
restart: always
volumes:
postgres_data:

Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Generated by Django 5.1.1 on 2024-10-11 10:34

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('alertas', '0002_medicao'),
]

operations = [
migrations.AlterField(
model_name='alerta',
name='condicao',
field=models.CharField(help_text='Condição para o alerta acontecer', max_length=4),
),
migrations.AlterField(
model_name='alerta',
name='nome',
field=models.CharField(help_text='Nome do alerta', max_length=127, unique=True),
),
migrations.AlterField(
model_name='historicoalerta',
name='timestamp',
field=models.BigIntegerField(help_text='Data/hora do alerta em timestamp'),
),
migrations.AlterField(
model_name='historicoalerta',
name='timestamp_convertido',
field=models.DateTimeField(blank=True, help_text='Data/hora do alerta em datetime', null=True),
),
migrations.AlterField(
model_name='medicao',
name='dados',
field=models.CharField(help_text='Valor dos dados da medição', max_length=63),
),
migrations.AlterField(
model_name='medicao',
name='timestamp',
field=models.BigIntegerField(help_text='Data/hora da medição em timestamp'),
),
migrations.AlterField(
model_name='medicao',
name='timestamp_convertido',
field=models.DateTimeField(blank=True, help_text='Data/hora da medição em datetime', null=True),
),
]
7 changes: 2 additions & 5 deletions src/tupan/tupan/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []
ALLOWED_HOSTS = ["*"]

AUTH_USER_MODEL = 'usuarios.Usuario'

Expand Down Expand Up @@ -88,10 +88,7 @@
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

CORS_ALLOWED_ORIGINS = [
'http://localhost:3000',
]

CORS_ALLOW_ALL_ORIGINS = True
ROOT_URLCONF = 'tupan.urls'

TEMPLATES = [
Expand Down
Loading