Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker #8

Merged
merged 1 commit into from
Feb 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,53 @@ jobs:
poetry version "${VERSION}"
poetry build
poetry publish

test_docker:
runs-on: ubuntu-latest
needs: lint_and_test
if: github.event_name != 'release'
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
permissions:
contents: read
packages: write
steps:
- name: Check out repository code
uses: actions/checkout@v4
- name: Build docker
run: |
make docker

publish_docker:
runs-on: ubuntu-latest
needs: publish_pypi
if: github.event_name == 'release' && github.event.action == 'created'
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
permissions:
contents: read
packages: write
steps:
- name: Check out repository code
uses: actions/checkout@v4
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: docker
push: true
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
labels: ${{ steps.meta.outputs.labels }}

4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ clean: ## Clean generated files
rm -Rf .*_cache build
find . -type d -name __pycache__ -exec rm -Rf {} \; 2>/dev/null || true

.PHONY: docker
docker: ## Build docker image
cd docker && $(MAKE) build

.PHONY: publish
publish: ## Publish to PyPI
@if test "${VERSION}" = "0.0.0"; then echo "ERROR: Cannot publish a dev version"; exit 1; fi
Expand Down
43 changes: 42 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,13 @@ See [this directory](jinja_tree/app/embedded_extensions/) for others

`pip install jinja-tree`

> [!TIP]
> If you want to get a better readability of `jinja-tree` output (colors...), you can also use `pip install rich` to install
> this **optional** dependency.

> [!NOTE]
> A docker image will also be available soon 🕒
> A docker image is also available. You can use it to avoid any specific installation.
> See at the end of the "Usage" section for more details.

## Usage

Expand Down Expand Up @@ -254,4 +259,40 @@ Options:

```

</details>

### Docker image

A docker image is also available. You can use it this way:

```bash
docker run -t -v $(pwd):/workdir --user=$(id -u) ghcr.io/fabien-marty/jinja-tree:latest /workdir
```

*(we mount the current directory in the `/workdir` directory in the container and execute `jinja-tree` in this `/workdir` directory)*

> [!WARNING]
> If you plan to use environment variables with the docker image, you will have to use (possibly multiple times) the `-e VAR=VALUE` option to pass them to the container.
> With docker, it's more practical to use a `.env` (dotenv) file as it will be automatically mounted in the container.

If you want to add some CLI options, you can add them like in this example:

```bash
docker run -t -v $(pwd):/workdir --user=$(id -u) ghcr.io/fabien-marty/jinja-tree:latest --verbose /workdir
```

*(we added `--verbose` just before the `/workdir` argument)*

<details>

<summary>If you want to use the `jinja-stdin` CLI with docker?</summary>


```bash
echo "FOO {{ BAR }}" |docker run -i -v $(pwd):/workdir -e BAR=BAZ --user=$(id -u) --entrypoint jinja-stdin ghcr.io/fabien-marty/jinja-tree:latest
```


*(it will output `FOO BAZ`)*

</details>
43 changes: 42 additions & 1 deletion README.md.template
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,13 @@ See [this directory]({{BASEURL}}jinja_tree/app/embedded_extensions/) for others

`pip install jinja-tree`

> [!TIP]
> If you want to get a better readability of `jinja-tree` output (colors...), you can also use `pip install rich` to install
> this **optional** dependency.

> [!NOTE]
> A docker image will also be available soon 🕒
> A docker image is also available. You can use it to avoid any specific installation.
> See at the end of the "Usage" section for more details.

## Usage

Expand Down Expand Up @@ -190,3 +195,39 @@ Hello bar
```

</details>

### Docker image

A docker image is also available. You can use it this way:

```bash
docker run -t -v $(pwd):/workdir --user=$(id -u) ghcr.io/fabien-marty/jinja-tree:latest /workdir
```

*(we mount the current directory in the `/workdir` directory in the container and execute `jinja-tree` in this `/workdir` directory)*

> [!WARNING]
> If you plan to use environment variables with the docker image, you will have to use (possibly multiple times) the `-e VAR=VALUE` option to pass them to the container.
> With docker, it's more practical to use a `.env` (dotenv) file as it will be automatically mounted in the container.

If you want to add some CLI options, you can add them like in this example:

```bash
docker run -t -v $(pwd):/workdir --user=$(id -u) ghcr.io/fabien-marty/jinja-tree:latest --verbose /workdir
```

*(we added `--verbose` just before the `/workdir` argument)*

<details>

<summary>If you want to use the `jinja-stdin` CLI with docker?</summary>

{% raw %}
```bash
echo "FOO {{ BAR }}" |docker run -i -v $(pwd):/workdir -e BAR=BAZ --user=$(id -u) --entrypoint jinja-stdin ghcr.io/fabien-marty/jinja-tree:latest
```
{% endraw %}

*(it will output `FOO BAZ`)*

</details>
8 changes: 5 additions & 3 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from python:3.12-slim-bookworm

COPY jinja-tree.toml /etc/jinja-tree.toml
RUN pip install jinja-tree
RUN pip install jinja-tree rich

ENTRYPOINT ["jinja-tree"]
RUN mkdir /workdir
WORKDIR /workdir

ENTRYPOINT ["jinja-tree"]
10 changes: 10 additions & 0 deletions docker/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.PHONY: build
build:: ## Build the Docker image
docker build -t myapp .

.PHONY: help
help::
@# See https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
@cat $(MAKEFILE_LIST) >"$(TMPDIR)/makefile_help.txt"
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' "$(TMPDIR)/makefile_help.txt" | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
@rm -f "$(TMPDIR)/makefile_help.txt"
Loading