Skip to content

Commit

Permalink
Add docker and all dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
YaroslavBordovoy committed Oct 1, 2022
1 parent 5c28b42 commit 03db433
Show file tree
Hide file tree
Showing 11 changed files with 201 additions and 1 deletion.
7 changes: 7 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Ignore all
**

# with the exception of
!main.py
!requirements.txt
!Makefile
4 changes: 4 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[flake8]
exclude =
venv
max-line-length = 120
26 changes: 26 additions & 0 deletions .github/workflows/main-workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Main workflow

on: [ pull_request ]

jobs:
main:
runs-on: ubuntu-22.04

steps:
# Need this for any work with repository.
- name: Checkout
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.10"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install --requirement requirements.txt
- name: Make autoformatting
run: |
black ./
- name: Check codestyle
run: |
flake8 ./
18 changes: 18 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
repos:
- repo: https://github.com/asottile/pyupgrade
rev: v2.38.0
hooks:
- id: pyupgrade
args: [
"--py310-plus"
]

- repo: https://github.com/psf/black
rev: 22.8.0
hooks:
- id: black
# It is recommended to specify the latest version of Python
# supported by your project here, or alternatively use
# pre-commit's default_language_version, see
# https://pre-commit.com/#top_level-default_language_version
language_version: python3.10
23 changes: 23 additions & 0 deletions .run/Run main.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Run main" type="PythonConfigurationType" factoryName="Python">
<module name="homework__docker__bordovoy_yaroslav" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
<envs>
<env name="PYTHONUNBUFFERED" value="1" />
</envs>
<option name="SDK_HOME" value="" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
<option name="IS_MODULE_SDK" value="true" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/main.py" />
<option name="PARAMETERS" value="" />
<option name="SHOW_COMMAND_LINE" value="false" />
<option name="EMULATE_TERMINAL" value="false" />
<option name="MODULE_MODE" value="false" />
<option name="REDIRECT_INPUT" value="false" />
<option name="INPUT_FILE" value="" />
<method v="2" />
</configuration>
</component>
25 changes: 25 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
FROM python:3.10

ENV PYTHONUNBUFFERED=1

ARG WORKDIR=/wd
ARG USER=user

WORKDIR ${WORKDIR}

RUN useradd --system ${USER} && \
chown --recursive ${USER} ${WORKDIR}

RUN apt update && apt upgrade -y

COPY --chown=${USER} requirements.txt requirements.txt

RUN pip install --upgrade pip && \
pip install --requirement requirements.txt

COPY --chown=${USER} ./main.py main.py
COPY --chown=${USER} ./Makefile Makefile

USER ${USER}

ENTRYPOINT ["python", "main.py"]
49 changes: 49 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
.PHONY: homework-i-run
# Run homework.
homework-i-run:
@python main.py

.PHONY: homework-i-purge
homework-i-purge:
@echo The end

.PHONY: init-dev
# Init environment for development
init-dev:
@pip install --upgrade pip && \
pip install --requirement requirements.txt && \
pre-commit install

.PHONY: pre-commit-run
# Run tools for files from commit.
pre-commit-run:
@pre-commit run

.PHONY: pre-commit-run-all
# Run tools for all files.
pre-commit-run-all:
@pre-commit run --all-files

.PHONY: d-homework-i-run
# Make all actions needed for run homework (docker).
d-homework-i-run:
@make d-run

.PHONY: d-homework-i-purge
# Make all actions needed for purge homework related data.
d-homework-i-purge:
@make d-purge

.PHONY: d-run
# Run docker
d-run:
@COMPOSE_DOCKER_CLI_BUILD=1 DOCKER_BUILDKIT=1 \
docker-compose \
up --build

.PHONY: d-purge
# Purge all data related with services
d-purge:
@COMPOSE_DOCKER_CLI_BUILD=1 DOCKER_BUILDKIT=1 \
docker-compose \
down --volumes --remove-orphans --rmi local --timeout 0
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# DOCKER HOMEWORK

---

![main workflows](https://github.com/hillel-i-python-pro-i-2022-08-26/homework__docker__bordovoy_yaroslav/actions/workflows/main-workflow.yml/badge.svg)

### Important Commands


#### ⚡️ Run script

- make homework-i-run

#### ❌ Purge script

- make homework-i-purge

#### ⚡️ Run docker

Creating an image.

- make d-homework-i-run

#### ❌ Purge docker

Deleted docker-related data.

- make d-homework-i-purge
6 changes: 6 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: '3.8'


services:
app:
build: .
2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
fake = Faker()

def main():
return f"Hello, {fake.first_name()}"
return f"Hello, {fake.first_name()}!"

if __name__ == '__main__':
print(main())
14 changes: 14 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Generate fake-names
faker==15.0.0

# Autoformatter
black==22.8.0

# Check codestyle
flake8==5.0.4

# Upgrade syntax
pyupgrade==2.38.2

# Pre-commit hook
pre-commit==2.20.0

0 comments on commit 03db433

Please sign in to comment.