Skip to content

Commit

Permalink
build: add docker support (#75)
Browse files Browse the repository at this point in the history
* feat: add Dockerfile to run application in container

Added Dockerfile with .dockerignore to streamline use of enex2notion.
User can now build an image with '$ docker build -t <image_name>:>tag> .'
Data volume is declared at /data, which client can map to the host
directory where the .enex files reside.
Entrypoint already specifies the launch script, all left to do is to add
CLI arguments.

* docs(readme): add info about building docker images

Added section with commands to build a docker image from the source
as well as run it.

* build: update Dockerfile

* ci(github): add container release workflow

* docs(readme): add info about docker

* docs(readme): move docker info higher

---------

Co-authored-by: vzhd1701 <vzhd1701@gmail.com>
  • Loading branch information
akmal2409 and vzhd1701 authored Oct 20, 2023
1 parent 7b14b6d commit 89615c9
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 0 deletions.
78 changes: 78 additions & 0 deletions .github/workflows/release_containers.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
name: release_containers

on:
workflow_dispatch:
push:
tags:
- "v[0-9]+.[0-9]+.[0-9]+"

jobs:
release_ghcr:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Checkout latest release tag
if: github.event_name == 'workflow_dispatch'
run: |
LATEST_TAG=$(git describe --tags `git rev-list --tags --max-count=1`)
git checkout $LATEST_TAG
echo "TAG_VERSION=$LATEST_TAG" >> $GITHUB_ENV
- name: Get push tag version
if: github.event_name == 'push'
run: echo "TAG_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Publish Docker image to GitHub Container Registry
uses: elgohr/Publish-Docker-Github-Action@v5
with:
name: ${{ github.repository }}
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
tags: "latest,${{ env.TAG_VERSION }}"
platforms: linux/amd64,linux/arm64

release_docker:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Checkout latest release tag
if: github.event_name == 'workflow_dispatch'
run: |
LATEST_TAG=$(git describe --tags `git rev-list --tags --max-count=1`)
git checkout $LATEST_TAG
echo "TAG_VERSION=$LATEST_TAG" >> $GITHUB_ENV
- name: Get push tag version
if: github.event_name == 'push'
run: echo "TAG_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Publish Docker image to Docker Container Registry
uses: elgohr/Publish-Docker-Github-Action@v5
with:
name: ${{ github.repository }}
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
tags: "latest,${{ env.TAG_VERSION }}"
platforms: linux/amd64,linux/arm64

- name: Update Docker Hub Description
uses: peter-evans/dockerhub-description@v3
with:
repository: ${{ github.repository }}
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
37 changes: 37 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
FROM debian:12-slim AS build

ENV BUILD_POETRY_VERSION=1.6.1

RUN apt-get update && \
apt-get install --no-install-suggests --no-install-recommends --yes python3-venv python3-pip && \
python3 -m venv /venv && \
/venv/bin/pip install --upgrade pip

RUN pip3 install --break-system-packages poetry==$BUILD_POETRY_VERSION

FROM build AS build-venv

COPY . /app
WORKDIR /app

RUN poetry build --no-interaction -f wheel
RUN /venv/bin/pip install --disable-pip-version-check dist/*.whl

FROM gcr.io/distroless/python3-debian12

ENV INSIDE_DOCKER_CONTAINER=1

LABEL maintainer="vzhd1701 <vzhd1701@gmail.com>" \
org.opencontainers.image.title="enex2notion" \
org.opencontainers.image.description="Import Evernote ENEX files to Notion " \
org.opencontainers.image.authors="vzhd1701 <vzhd1701@gmail.com>" \
org.opencontainers.image.licenses="MIT" \
org.opencontainers.image.documentation="https://github.com/vzhd1701/enex2notion" \
org.opencontainers.image.url="https://github.com/vzhd1701/enex2notion" \
org.opencontainers.image.source="https://github.com/vzhd1701/enex2notion.git"

COPY --from=build-venv /venv /venv

WORKDIR /input

ENTRYPOINT ["/venv/bin/enex2notion"]
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ $ brew install enex2notion
$ pipx install enex2notion
```

### With [**Docker**](https://docs.docker.com/)

This command maps current directory `$PWD` to the `/input` directory in the container. You can replace `$PWD` with a directory that contains your `*.enex` files. When running commands like `enex2notion /input` refer to your local mapped directory as `/input`.

```shell
$ docker run --rm -t -v "$PWD":/input vzhd1701/enex2notion:latest
```

### With PIP

```bash
Expand Down

0 comments on commit 89615c9

Please sign in to comment.