Skip to content

Commit

Permalink
build: added docker compose to easy local testing
Browse files Browse the repository at this point in the history
  • Loading branch information
juarezr committed Mar 13, 2024
1 parent 44d1e77 commit b5c764d
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 6 deletions.
95 changes: 95 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#!/usr/bin/env -S bash -x -c 'docker compose --file docker-compose.yml up --detach'

#region commands -----------------------------------------------------------------------------------

#$ docker compose --file docker-compose.yml up --detach
#$ docker compose --file docker-compose.yml down --remove-orphans -v --rmi local

#$ docker exec --tty --interactive --privileged petl-xxxxxx /bin/bash

#$ docker exec -it petl-postgres psql -U petl --dbname=petl
#$ docker exec -it petl-msyql mysql --user=petl --database=petl --password=test

#endregion -----------------------------------------------------------------------------------------

#region docker composer ----------------------------------------------------------------------------

---
services:
postgres:
container_name: petl-postgres
hostname: petl_postgres
image: postgres:latest
environment:
- POSTGRES_USER=petl
- POSTGRES_PASSWORD=test
- POSTGRES_DB=petl
- POSTGRES_HOST_AUTH_METHOD=password
ports:
- "5432:5432/tcp"
restart: "unless-stopped"
stdin_open: true
tty: true
healthcheck:
test: ["CMD", "psql", "--host=localhost", "--username=petl", "--dbname=petl", "-c", "select 1 as ok"]
interval: 20s
timeout: 10s
retries: 5
start_period: 2s

mysql:
container_name: petl-mysql
hostname: petl_mysql
image: mysql:latest
ports:
- "3306:3306/tcp"
- "33060:33060/tcp"
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
MYSQL_DATABASE: "petl"
MYSQL_USER: "petl"
MYSQL_PASSWORD: "test"
MYSQL_ROOT_PASSWORD: "pass0"
restart: "unless-stopped"
stdin_open: true
tty: true
healthcheck:
test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"]
interval: 20s
timeout: 10s
retries: 5
start_period: 2s

samba:
container_name: petl-samba
hostname: petl_samba
image: dperson/samba
ports:
- "137:137/udp"
- "138:138/udp"
- "139:139/tcp"
- "445:445/tcp"
tmpfs:
- /tmp
restart: unless-stopped
stdin_open: true
tty: true
volumes:
- /mnt:/mnt:z
- /mnt2:/mnt2:z
command: '-s "public;/mnt;yes;no;yes;all" -s "mount2;/mnt2" -u "petl;test" -p'

sftp:
container_name: petl-sftp
hostname: petl_sftp
image: atmoz/sftp
ports:
- "22:22/tcp"
tmpfs:
- /tmp
restart: unless-stopped
stdin_open: true
tty: true
command: 'petl:test:::public'

#endregion -----------------------------------------------------------------------------------------
35 changes: 29 additions & 6 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,13 @@ commands =
sphinx-build -W -b singlehtml -d {envtmpdir}/doctrees . _build/singlehtml

[testenv:remote]
# Create test containers with the following commands:
# docker run -it --name samba -p 139:139 -p 445:445 -d "dperson/samba" -p -u "petl;test" -s "public;/public-dir;yes;no;yes;all"
# docker run -it --name sftp -p 22:22 -d atmoz/sftp petl:test:::public
#? Create individual containers with the following commands:
#$ docker run -it --name samba -p 139:139 -p 445:445 -d "dperson/samba" -p -u "petl;test" -s "public;/public-dir;yes;no;yes;all"
#$ docker run -it --name sftp -p 22:22 -d atmoz/sftp petl:test:::public
#? Or create both with:
#$ docker compose up --detach samba sftp
#? Stop and remove the containers with:
#$ docker compose down --remove-orphans -v --rmi local
setenv =
{[testenv]setenv}
PETL_TEST_SMB=smb://WORKGROUP;petl:test@localhost/public/
Expand All @@ -52,9 +56,11 @@ deps =
-rrequirements-remote.txt

[testenv:database]
# Create test containers with the following commands:
# docker run -it --name mysql -p 3306:3306 -p 33060:33060 -e MYSQL_ROOT_PASSWORD=pass0 -e MYSQL_DATABASE=petl -e MYSQL_USER=petl -e MYSQL_PASSWORD=test -d mysql:latest
# docker run -it --name postgres -p 5432:5432 -e POSTGRES_DB=petl -e POSTGRES_USER=petl -e POSTGRES_PASSWORD=test -d postgres:latest
#? Create individual test containers with the following commands:
#$ docker run -it --name mysql -p 3306:3306 -p 33060:33060 -e MYSQL_ROOT_PASSWORD=pass0 -e MYSQL_DATABASE=petl -e MYSQL_USER=petl -e MYSQL_PASSWORD=test -d mysql:latest
#$ docker run -it --name postgres -p 5432:5432 -e POSTGRES_DB=petl -e POSTGRES_USER=petl -e POSTGRES_PASSWORD=test -d postgres:latest
#? Or create both with:
#$ docker compose up --detach mysql postgres
setenv =
{[testenv]setenv}
commands =
Expand All @@ -63,6 +69,23 @@ deps =
-rrequirements-tests.txt
-rrequirements-database.txt

[testenv:compose]
#? Create test containers and run tests with the following commands:
#$ tox -e compose
setenv =
{[testenv:remote]setenv}
allowlist_externals =
docker
commands =
docker compose up --detach
pytest --cov=petl --cov-report lcov:lcov.info petl
coverage report -m
docker compose down --remove-orphans -v --rmi local
deps =
{[testenv]deps}
{[testenv:remote]deps}
{[testenv:database]deps}

[testenv:mysqldb]
basepython = python2.7
setenv =
Expand Down

0 comments on commit b5c764d

Please sign in to comment.