Skip to content

Commit

Permalink
Added Docker image build. (#47)
Browse files Browse the repository at this point in the history
Closes #46.

Signed-off-by: Pavel Kirilin <win10@list.ru>
  • Loading branch information
s3rius committed Oct 15, 2021
1 parent b9022fa commit c1e5b67
Show file tree
Hide file tree
Showing 8 changed files with 220 additions and 114 deletions.
142 changes: 142 additions & 0 deletions .dockerignore
@@ -0,0 +1,142 @@
.idea
.vscode

*.sqlite3

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/
29 changes: 29 additions & 0 deletions .github/workflows/docker.yml
@@ -0,0 +1,29 @@
name: Release docker image

on:
push:
tags:
- "*"

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Get current tag
id: tag
uses: dawidd6/action-get-tag@v1
- name: Build and push
uses: docker/build-push-action@v2
with:
context: .
push: true
cache-from: s3rius/fastapi_template:latest
tags: |
s3rius/fastapi_template:latest
s3rius/fastapi_template:${{steps.tag.outputs.tag}}
2 changes: 0 additions & 2 deletions .gitignore
@@ -1,9 +1,7 @@
.idea
.vscode

{%- if cookiecutter.db_info.name == "sqlite" %}
*.sqlite3
{%- endif %}

# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down
39 changes: 39 additions & 0 deletions Dockerfile
@@ -0,0 +1,39 @@
FROM python:3.9.7-alpine3.13

RUN apk add --no-cache \
curl \
# For building dependencies. \
gcc \
musl-dev \
git \
g++ \
libffi-dev \
# For psycopg \
postgresql-dev \
# For mysql deps \
mariadb-connector-c-dev

RUN adduser --disabled-password fastapi_template
RUN mkdir /projects /src
RUN chown -R fastapi_template:fastapi_template /projects /src
USER fastapi_template

WORKDIR /src

ENV PATH ${PATH}:/home/fastapi_template/.local/bin

RUN pip install poetry==1.1.11

COPY . /src/
RUN pip install .

USER root
RUN rm -rfv /src
RUN apk del curl
USER fastapi_template

VOLUME /projects
WORKDIR /projects

ENTRYPOINT ["/home/fastapi_template/.local/bin/fastapi_template"]

5 changes: 5 additions & 0 deletions README.md
Expand Up @@ -29,6 +29,11 @@ python3 -m pip install .
python3 -m fastapi_template
```

Also you can use it with docker.
```bash
docker run --rm -it -v "$(pwd):/projects" s3rius/fastapi_template
```

<div align="center">
<img src="https://user-images.githubusercontent.com/18153319/137182689-ce714440-7576-46a0-8f96-862a8469a28c.gif"/>
<p>Templator in action</p>
Expand Down
12 changes: 4 additions & 8 deletions fastapi_template/template/hooks/post_gen_project.py
Expand Up @@ -4,7 +4,6 @@
import shutil
import subprocess

from pygit2 import init_repository
from termcolor import cprint, colored
from pathlib import Path

Expand Down Expand Up @@ -58,19 +57,16 @@ def replace_resources():


def init_repo():
repo_path = os.getcwd()
repo = init_repository(repo_path)
subprocess.run(["git", "init"], stdout=subprocess.PIPE)
cprint("Git repository initialized.", "green")
repo.index.add_all()
repo.index.write()
subprocess.run(["git", "add", "."], stdout=subprocess.PIPE)
cprint("Added files to index.", "green")
subprocess.run(["poetry", "install", "-n"])
subprocess.run(["poetry", "run", "pre-commit", "install"])
cprint("pre-commit installed.", "green")
subprocess.run(["poetry", "run", "pre-commit", "run", "-a"])
repo.index.add_all()
repo.index.write()

subprocess.run(["git", "add", "."], stdout=subprocess.PIPE)
subprocess.run(["git", "commit", "-m", "Initial commit"], stdout=subprocess.PIPE)

if __name__ == "__main__":
delete_resources_for_disabled_features()
Expand Down

0 comments on commit c1e5b67

Please sign in to comment.