Skip to content

Commit

Permalink
ci/cd: add docker commands to Makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
oedokumaci committed Apr 25, 2024
1 parent f8ccf7a commit 6b2955a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 10 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
.github/
.venv/
.vscode/
config/config.yml
logs/logs.log
30 changes: 29 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: help vscode-settings setup update-dev update-user run project-help test pre-commit purge-logs clean
.PHONY: help setup update-dev update-user vscode-settings run docker-build docker-run docker docker-logs docker-stop docker-kill docker-show docker-prune project-help test pre-commit purge-logs clean

help: ## Show this help message for each Makefile recipe
ifeq ($(OS),Windows_NT)
Expand Down Expand Up @@ -43,6 +43,34 @@ endif
run: ## Run project
pdm run python -m template_python

docker-build: ## Build Docker image for the project
sudo docker build -t template-python .

docker-run: ## Run Docker container from the image in detached mode
sudo docker run --rm -it \
-v $(PWD)/data:/usr/src/app/data \
-v $(PWD)/logs:/usr/src/app/logs \
-v $(PWD)/outputs:/usr/src/app/outputs \
--name template-python-app \
template-python

docker: clean docker-build docker-run ## Clean, build and run Docker container

docker-logs: ## Show Docker container logs
sudo docker logs -f template-python-app

docker-stop: ## Stop Docker container
sudo docker stop template-python-app

docker-kill: ## Kill Docker container
sudo docker kill template-python-app

docker-show: ## Show Docker containers
sudo docker ps -a

docker-prune: ## Prune Docker system
sudo docker system prune -a

project-help: ## Show project help
pdm run python -m template_python --help

Expand Down
11 changes: 2 additions & 9 deletions README_main.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,9 @@ There are three easy ways to install the package.

The easiest way to run the project is to use Docker. First, install [Docker](https://docs.docker.com/get-docker/). Then, run the following command in the project directory.
```bash
docker build -t template-python .
make docker
```
This will build the Docker image. After the image is built, the following are some examples of how to run the project.

```bash
docker run --rm -it -v "PATH_TO_YOUR_CONFIG.yaml:/usr/src/app/config/config.yaml" -e environment_variable=ENVIRONMENT_VARIABLE template-python
```

These commands will run the project with the specified config file and cli arguments. The output can be seen in the terminal. The `-v` option mounts the specified config file to the container. The `-e` option sets the environment variable to the specified value. The `--rm` option removes the container after it exits. You can also not use the `--rm` option to keep the container after it exits and see the logs. The `-it` option is for interactive mode.

If you do not have `make` installed, you can run the commands in the `Makefile` manually.

### Download Zip File

Expand Down

0 comments on commit 6b2955a

Please sign in to comment.