Skip to content

Commit

Permalink
Merge pull request #58 from TukiLaCosa/dockerize-app
Browse files Browse the repository at this point in the history
Testing automatico y Dockerizacion de la app
  • Loading branch information
anelioalvarez authored Nov 8, 2023
2 parents e3cf59c + 2c5eeb4 commit 7e0a0de
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Byte-compiled / optimized / DLL files
__pycache__
*.pyc
*.pyo
*.pyd

# Tests directory
./app/tests/

# Database file
./app/database/*.sqlite
38 changes: 38 additions & 0 deletions .github/workflows/testing-ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Tuki Testing CI
on: [push]

jobs:
test:
runs-on: ubuntu-latest

env:
ENVIRONMENT: test
TEST_DIRECTORY: ${{ github.workspace }}/app/tests
TEST_DB_FILE: ${{ github.workspace }}/app/database/database_test.sqlite

steps:
- uses: actions/checkout@v3

- name: Install and caching poetry dependencies
run: pipx install poetry

- uses: actions/setup-python@v4
with:
python-version: "3.10"
cache: "poetry"
- run: poetry install

- name: Test Game module
run: |
poetry run coverage run -m pytest $TEST_DIRECTORY/game_tests
rm -f $TEST_DB_FILE
- name: Test Player module
run: |
poetry run coverage run -m pytest $TEST_DIRECTORY/player_tests
rm -f $TEST_DB_FILE
- name: Test Card module
run: |
poetry run coverage run -m pytest $TEST_DIRECTORY/card_tests
rm -f $TEST_DB_FILE
23 changes: 23 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM python:3.10-slim as requirements-stage

WORKDIR /tmp

RUN pip install poetry

COPY ./pyproject.toml ./poetry.lock* ./

RUN poetry export -f requirements.txt --output requirements.txt --without-hashes

FROM python:3.10-slim

WORKDIR /code

COPY --from=requirements-stage /tmp/requirements.txt ./requirements.txt

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

COPY ./app ./app

EXPOSE 8000

CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,15 @@ In the Makefile, you have the following targets:

**Remember to create a .env file with the necessary environment variables before using the Makefile**
**To know the necessary environment variables you can see the `.env.example` file.**


## Running the Application in Containers - Docker

### Building the Docker Image
`docker build -t backend-tuki .`

### Run a container based on the built image
`docker run --name backend-tuki-container -p 8000:8000 backend-tuki`

### Running the Application in Containers - Docker Compose
`docker-compose up --build`
16 changes: 16 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version: '3.8'

services:
api:
build:
dockerfile: Dockerfile
context: .
volumes:
- database:/code/app/database/
env_file:
- .env
ports:
- 8000:8000

volumes:
database:

0 comments on commit 7e0a0de

Please sign in to comment.