Skip to content
Open
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
42 changes: 42 additions & 0 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Python + Docker

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: "3.10"

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt

- name: Run tests
run: pytest

docker:
runs-on: ubuntu-latest
needs: test # só roda o Docker se os testes passarem
steps:
- uses: actions/checkout@v4

- name: Build Docker image
run: docker build -t testandodocker .

- name: Run container
run: docker run -d -p 8000:80 --name test_container testandodocker

- name: Check container logs
run: docker logs test_container
2 changes: 1 addition & 1 deletion .idea/devops-puc.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM python:3

WORKDIR /usr/src/app

COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt

COPY . .

EXPOSE 80

CMD [ "uvicorn", "main:app", "--host", "0.0.0.0", "--port", "80" ]
7 changes: 7 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from fastapi import FastAPI

app = FastAPI()

@app.get("/")
def home():
return {"mensagem": "API funcionando no Docker!"}
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fastapi==0.111.1
uvicorn[standard]

13 changes: 13 additions & 0 deletions tests/test_01.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"""Testes automatizados para o módulo main."""

from main import read_root


def test_passando():
"""Teste que sempre passa."""
assert True

def test_read_root():
"""Teste da função read_root()."""
response = read_root()
assert response == {"hello": "world"}