From 905722c16bfd9d129da63a3a75954e6b7ad865e8 Mon Sep 17 00:00:00 2001 From: Akmal Alikhujaev Date: Fri, 3 Feb 2023 12:09:01 +0100 Subject: [PATCH 1/6] 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 :>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. --- .dockerignore | 9 +++++++++ Dockerfile | 25 +++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..125f146 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,9 @@ +.github/ +.git +.gitignore +tests/ +.pre-commit-config.yaml +.versionrc.js +CHANGELOG.md +LICENSE +README.md \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..0ee1090 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,25 @@ +FROM python:3.10.6-slim + +# Map host volume here from where you can read the *.enex files +VOLUME data + +# Lock version +ENV POETRY_VERSION=1.3.2 + +# Install poetry build and dependency management system for python +RUN pip3 install "poetry==$POETRY_VERSION" + +# Cache the dependencies, they are less volatile. +COPY poetry.lock pyproject.toml /code/ + +WORKDIR /code + +# Disabling creation of virtual environment since docker container is isolated by design. +RUN poetry config virtualenvs.create false +RUN poetry install --no-dev --no-interaction --no-ansi + +# Copy rest of the files (code) which are more likely to change. +COPY . ./ + +# Setting entry point that cannot be overriden, we will just need to prepend the CLI args when using docker run +ENTRYPOINT [ "poetry", "run", "enex2notion" ] From f119e65e55d45c1b0aef50246bdec3cb2e9b3490 Mon Sep 17 00:00:00 2001 From: Akmal Alikhujaev Date: Fri, 3 Feb 2023 12:35:16 +0100 Subject: [PATCH 2/6] 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. --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index 45bf3ed..d771e8d 100644 --- a/README.md +++ b/README.md @@ -73,6 +73,14 @@ $ poetry install --no-dev $ poetry run enex2notion ``` +### With [**Docker**](https://docs.docker.com/) +Last command (docker run) maps current directory ($PWD) to the data directory in the container. You can replace $PWD with a directory that contains your *.enex files. When running commands like "enex2notion /data" refer to your local mapped directory as /data. + +```shell +$ git clone https://github.com/vzhd1701/enex2notion.git +$ docker build -t enex2notion:latest . +$ docker run --rm -t -v "$PWD":/data enex2notion +``` ## Usage ```shell From 98f0898bb4e718a9b5c79e5a5a365596866cd108 Mon Sep 17 00:00:00 2001 From: vzhd1701 Date: Fri, 20 Oct 2023 11:29:23 +0500 Subject: [PATCH 3/6] build: update Dockerfile --- .dockerignore | 9 --------- Dockerfile | 46 +++++++++++++++++++++++++++++----------------- 2 files changed, 29 insertions(+), 26 deletions(-) delete mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore deleted file mode 100644 index 125f146..0000000 --- a/.dockerignore +++ /dev/null @@ -1,9 +0,0 @@ -.github/ -.git -.gitignore -tests/ -.pre-commit-config.yaml -.versionrc.js -CHANGELOG.md -LICENSE -README.md \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 0ee1090..bfed6b8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,25 +1,37 @@ -FROM python:3.10.6-slim +FROM debian:12-slim AS build -# Map host volume here from where you can read the *.enex files -VOLUME data +ENV BUILD_POETRY_VERSION=1.6.1 -# Lock version -ENV POETRY_VERSION=1.3.2 +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 -# Install poetry build and dependency management system for python -RUN pip3 install "poetry==$POETRY_VERSION" +RUN pip3 install --break-system-packages poetry==$BUILD_POETRY_VERSION -# Cache the dependencies, they are less volatile. -COPY poetry.lock pyproject.toml /code/ +FROM build AS build-venv -WORKDIR /code +COPY . /app +WORKDIR /app -# Disabling creation of virtual environment since docker container is isolated by design. -RUN poetry config virtualenvs.create false -RUN poetry install --no-dev --no-interaction --no-ansi +RUN poetry build --no-interaction -f wheel +RUN /venv/bin/pip install --disable-pip-version-check dist/*.whl -# Copy rest of the files (code) which are more likely to change. -COPY . ./ +FROM gcr.io/distroless/python3-debian12 -# Setting entry point that cannot be overriden, we will just need to prepend the CLI args when using docker run -ENTRYPOINT [ "poetry", "run", "enex2notion" ] +ENV INSIDE_DOCKER_CONTAINER=1 + +LABEL maintainer="vzhd1701 " \ + org.opencontainers.image.title="enex2notion" \ + org.opencontainers.image.description="Import Evernote ENEX files to Notion " \ + org.opencontainers.image.authors="vzhd1701 " \ + 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"] From 256e755a10bfcbac3fe59669d9eafd3783f0a969 Mon Sep 17 00:00:00 2001 From: vzhd1701 Date: Fri, 20 Oct 2023 12:08:35 +0500 Subject: [PATCH 4/6] ci(github): add container release workflow --- .github/workflows/release_containers.yml | 78 ++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 .github/workflows/release_containers.yml diff --git a/.github/workflows/release_containers.yml b/.github/workflows/release_containers.yml new file mode 100644 index 0000000..cbf73af --- /dev/null +++ b/.github/workflows/release_containers.yml @@ -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 }} From 156f8b540d7fb781979c919f8b233684e4adc823 Mon Sep 17 00:00:00 2001 From: vzhd1701 Date: Fri, 20 Oct 2023 12:11:43 +0500 Subject: [PATCH 5/6] docs(readme): add info about docker --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index a41a497..c4e084a 100644 --- a/README.md +++ b/README.md @@ -73,14 +73,14 @@ $ poetry install --no-dev $ poetry run enex2notion ``` -### With [**Docker**](https://docs.docker.com/) -Last command (docker run) maps current directory ($PWD) to the data directory in the container. You can replace $PWD with a directory that contains your *.enex files. When running commands like "enex2notion /data" refer to your local mapped directory as /data. +### 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 -$ git clone https://github.com/vzhd1701/enex2notion.git -$ docker build -t enex2notion:latest . -$ docker run --rm -t -v "$PWD":/data enex2notion +$ docker run --rm -t -v "$PWD":/input vzhd1701/enex2notion:latest ``` + ## Usage ```shell From 374fdceb44591dfae280ad25637873523cb25439 Mon Sep 17 00:00:00 2001 From: vzhd1701 Date: Fri, 20 Oct 2023 12:15:14 +0500 Subject: [PATCH 6/6] docs(readme): move docker info higher --- README.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index c4e084a..014c094 100644 --- a/README.md +++ b/README.md @@ -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 @@ -73,14 +81,6 @@ $ poetry install --no-dev $ poetry run 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 -``` - ## Usage ```shell