Skip to content

Commit c1e5b67

Browse files
authored
Added Docker image build. (#47)
Closes #46. Signed-off-by: Pavel Kirilin <win10@list.ru>
1 parent b9022fa commit c1e5b67

8 files changed

Lines changed: 220 additions & 114 deletions

File tree

.dockerignore

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
.idea
2+
.vscode
3+
4+
*.sqlite3
5+
6+
# Byte-compiled / optimized / DLL files
7+
__pycache__/
8+
*.py[cod]
9+
*$py.class
10+
11+
# C extensions
12+
*.so
13+
14+
# Distribution / packaging
15+
.Python
16+
build/
17+
develop-eggs/
18+
dist/
19+
downloads/
20+
eggs/
21+
.eggs/
22+
lib/
23+
lib64/
24+
parts/
25+
sdist/
26+
var/
27+
wheels/
28+
share/python-wheels/
29+
*.egg-info/
30+
.installed.cfg
31+
*.egg
32+
MANIFEST
33+
34+
# PyInstaller
35+
# Usually these files are written by a python script from a template
36+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
37+
*.manifest
38+
*.spec
39+
40+
# Installer logs
41+
pip-log.txt
42+
pip-delete-this-directory.txt
43+
44+
# Unit test / coverage reports
45+
htmlcov/
46+
.tox/
47+
.nox/
48+
.coverage
49+
.coverage.*
50+
.cache
51+
nosetests.xml
52+
coverage.xml
53+
*.cover
54+
*.py,cover
55+
.hypothesis/
56+
.pytest_cache/
57+
cover/
58+
59+
# Translations
60+
*.mo
61+
*.pot
62+
63+
# Django stuff:
64+
*.log
65+
local_settings.py
66+
db.sqlite3
67+
db.sqlite3-journal
68+
69+
# Flask stuff:
70+
instance/
71+
.webassets-cache
72+
73+
# Scrapy stuff:
74+
.scrapy
75+
76+
# Sphinx documentation
77+
docs/_build/
78+
79+
# PyBuilder
80+
.pybuilder/
81+
target/
82+
83+
# Jupyter Notebook
84+
.ipynb_checkpoints
85+
86+
# IPython
87+
profile_default/
88+
ipython_config.py
89+
90+
# pyenv
91+
# For a library or package, you might want to ignore these files since the code is
92+
# intended to run in multiple environments; otherwise, check them in:
93+
# .python-version
94+
95+
# pipenv
96+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
97+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
98+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
99+
# install all needed dependencies.
100+
#Pipfile.lock
101+
102+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
103+
__pypackages__/
104+
105+
# Celery stuff
106+
celerybeat-schedule
107+
celerybeat.pid
108+
109+
# SageMath parsed files
110+
*.sage.py
111+
112+
# Environments
113+
.venv
114+
env/
115+
venv/
116+
ENV/
117+
env.bak/
118+
venv.bak/
119+
120+
# Spyder project settings
121+
.spyderproject
122+
.spyproject
123+
124+
# Rope project settings
125+
.ropeproject
126+
127+
# mkdocs documentation
128+
/site
129+
130+
# mypy
131+
.mypy_cache/
132+
.dmypy.json
133+
dmypy.json
134+
135+
# Pyre type checker
136+
.pyre/
137+
138+
# pytype static type analyzer
139+
.pytype/
140+
141+
# Cython debug symbols
142+
cython_debug/

.github/workflows/docker.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Release docker image
2+
3+
on:
4+
push:
5+
tags:
6+
- "*"
7+
8+
jobs:
9+
deploy:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v2
13+
- name: Login to DockerHub
14+
uses: docker/login-action@v1
15+
with:
16+
username: ${{ secrets.DOCKERHUB_USERNAME }}
17+
password: ${{ secrets.DOCKERHUB_TOKEN }}
18+
- name: Get current tag
19+
id: tag
20+
uses: dawidd6/action-get-tag@v1
21+
- name: Build and push
22+
uses: docker/build-push-action@v2
23+
with:
24+
context: .
25+
push: true
26+
cache-from: s3rius/fastapi_template:latest
27+
tags: |
28+
s3rius/fastapi_template:latest
29+
s3rius/fastapi_template:${{steps.tag.outputs.tag}}

.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
.idea
22
.vscode
33

4-
{%- if cookiecutter.db_info.name == "sqlite" %}
54
*.sqlite3
6-
{%- endif %}
75

86
# Byte-compiled / optimized / DLL files
97
__pycache__/

Dockerfile

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
FROM python:3.9.7-alpine3.13
2+
3+
RUN apk add --no-cache \
4+
curl \
5+
# For building dependencies. \
6+
gcc \
7+
musl-dev \
8+
git \
9+
g++ \
10+
libffi-dev \
11+
# For psycopg \
12+
postgresql-dev \
13+
# For mysql deps \
14+
mariadb-connector-c-dev
15+
16+
RUN adduser --disabled-password fastapi_template
17+
RUN mkdir /projects /src
18+
RUN chown -R fastapi_template:fastapi_template /projects /src
19+
USER fastapi_template
20+
21+
WORKDIR /src
22+
23+
ENV PATH ${PATH}:/home/fastapi_template/.local/bin
24+
25+
RUN pip install poetry==1.1.11
26+
27+
COPY . /src/
28+
RUN pip install .
29+
30+
USER root
31+
RUN rm -rfv /src
32+
RUN apk del curl
33+
USER fastapi_template
34+
35+
VOLUME /projects
36+
WORKDIR /projects
37+
38+
ENTRYPOINT ["/home/fastapi_template/.local/bin/fastapi_template"]
39+

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ python3 -m pip install .
2929
python3 -m fastapi_template
3030
```
3131

32+
Also you can use it with docker.
33+
```bash
34+
docker run --rm -it -v "$(pwd):/projects" s3rius/fastapi_template
35+
```
36+
3237
<div align="center">
3338
<img src="https://user-images.githubusercontent.com/18153319/137182689-ce714440-7576-46a0-8f96-862a8469a28c.gif"/>
3439
<p>Templator in action</p>

fastapi_template/template/hooks/post_gen_project.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import shutil
55
import subprocess
66

7-
from pygit2 import init_repository
87
from termcolor import cprint, colored
98
from pathlib import Path
109

@@ -58,19 +57,16 @@ def replace_resources():
5857

5958

6059
def init_repo():
61-
repo_path = os.getcwd()
62-
repo = init_repository(repo_path)
60+
subprocess.run(["git", "init"], stdout=subprocess.PIPE)
6361
cprint("Git repository initialized.", "green")
64-
repo.index.add_all()
65-
repo.index.write()
62+
subprocess.run(["git", "add", "."], stdout=subprocess.PIPE)
6663
cprint("Added files to index.", "green")
6764
subprocess.run(["poetry", "install", "-n"])
6865
subprocess.run(["poetry", "run", "pre-commit", "install"])
6966
cprint("pre-commit installed.", "green")
7067
subprocess.run(["poetry", "run", "pre-commit", "run", "-a"])
71-
repo.index.add_all()
72-
repo.index.write()
73-
68+
subprocess.run(["git", "add", "."], stdout=subprocess.PIPE)
69+
subprocess.run(["git", "commit", "-m", "Initial commit"], stdout=subprocess.PIPE)
7470

7571
if __name__ == "__main__":
7672
delete_resources_for_disabled_features()

0 commit comments

Comments
 (0)