Skip to content

Instantly share code, notes, and snippets.

@kingbuzzman
Last active July 7, 2022 11:18
Show Gist options
  • Save kingbuzzman/f74f8f0bc0bec07650770c55ec24e1a1 to your computer and use it in GitHub Desktop.
Save kingbuzzman/f74f8f0bc0bec07650770c55ec24e1a1 to your computer and use it in GitHub Desktop.
factoryboy docker local development
version: "3.8"
volumes:
pip_cache:
services:
mongo:
image: mongo
command: mongod --quiet --logpath /dev/null
postgres:
image: postgres:alpine
environment:
- POSTGRES_PASSWORD=password
py37: &pyenv
build:
context: .
dockerfile: Dockerfile.template
args:
PYTHON_VERSION: python:3.7
volumes:
- .:/factory_boy
tmpfs:
- /factory_boy/.tox,mode=777
depends_on:
- mongo
- postgres
environment:
- PYENV_NAME=py37
command: bash -c 'POSTGRES_DATABASE=factory_boy_test_$$PYENV_NAME tox -f $$PYENV_NAME-cov'
py38:
<<: *pyenv
build:
context: .
dockerfile: Dockerfile.template
args:
PYTHON_VERSION: python:3.8
environment:
- PYENV_NAME=py38
py39:
<<: *pyenv
build:
context: .
dockerfile: Dockerfile.template
args:
PYTHON_VERSION: python:3.9
environment:
- PYENV_NAME=py39
py310:
<<: *pyenv
build:
context: .
dockerfile: Dockerfile.template
args:
PYTHON_VERSION: python:3.10
environment:
- PYENV_NAME=py310
pypy37:
<<: *pyenv
build:
context: .
dockerfile: Dockerfile.template
args:
PYTHON_VERSION: pypy:3.7
environment:
- PYENV_NAME=pypy37
pypy38:
<<: *pyenv
build:
context: .
dockerfile: Dockerfile.template
args:
PYTHON_VERSION: pypy:3.8
environment:
- PYENV_NAME=pypy38
pypy39:
<<: *pyenv
build:
context: .
dockerfile: Dockerfile.template
args:
PYTHON_VERSION: pypy:3.9
environment:
- PYENV_NAME=pypy39
# syntax=docker/dockerfile:experimental
ARG PYTHON_VERSION
FROM ${PYTHON_VERSION}
ENV TOX_WORK_DIR=/tmp/.tox
ENV MONGO_HOST=mongo
ENV POSTGRES_HOST=postgres
RUN apt update && \
DEBIAN_FRONTEND=noninteractive apt install -y build-essential
RUN --mount=type=cache,target=/root/.cache/pip pip install -U pip tox-factor flake8 isort check-manifest
WORKDIR /factory_boy
@kingbuzzman
Copy link
Author

kingbuzzman commented Jun 25, 2022

To use this copy all the code below [yes the parenthesis also], and run it under your factoryboy directory:

(
    PATH_TO_THIS_GIST='https://gist.githubusercontent.com/kingbuzzman/f74f8f0bc0bec07650770c55ec24e1a1/raw'
    [ ! -f 'docker-compose.yml' ] && curl $PATH_TO_THIS_GIST/docker-compose.yml > docker-compose.yml
    [ ! -f 'Dockerfile.template' ] && curl $PATH_TO_THIS_GIST/Dockerfile.template > Dockerfile.template
    echo "All set, make sure you have 'docker' installed and remember to not commit the files 'docker-compose.yml' or 'Dockerfile.template'"
    echo
    echo "As an example, you can run tests for python 3.10 by doing:"
    echo "  docker compose run --rm py310"
    echo "  docker compose run --rm py310 tox -e py310-sqlite -e py310-django40-alchemy-mongo-sqlite"
)

And do NOT commit docker-compose.yml or Dockerfile.template!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment