diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..329af37 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,11 @@ +# Use an official Python runtime as a parent image +FROM python:3.9-slim + +# Set the working directory in the container +WORKDIR /usr/src/app + +# Copy the current directory contents into the container at /usr/src/app +COPY . . + +# Install any needed packages specified in requirements.txt +RUN pip install --no-cache-dir -r requirements.txt diff --git a/README.md b/README.md index 4a53b6d..4b9a0dc 100644 --- a/README.md +++ b/README.md @@ -3,4 +3,13 @@ Tools for gopro or other action cams for preparing upload to mapillary, kartaview, panoramx or other street image sites. - remove_stopping.py - Move images without GPS position in file and nearby photos (duplicated position) -- copy_from_gopro.py - Copy or move images from action cam to a folder with subfolder each date \ No newline at end of file +- copy_from_gopro.py - Copy or move images from action cam to a folder with subfolder each date + +## Standalone + +To run the Python script inside docker from the command line, you can [use Bun](https://bun.sh/docs/installation) like this: + +```sh +chmod +x remove_stopping_executable.ts +./remove_stopping_executable.ts PATH/TO/YOUR/FILES +``` diff --git a/remove_stopping_executable.ts b/remove_stopping_executable.ts new file mode 100755 index 0000000..69231a4 --- /dev/null +++ b/remove_stopping_executable.ts @@ -0,0 +1,46 @@ +#!/usr/bin/env bun + +const args = process.argv.slice(2); + +if (args.length !== 1) { + console.error("Usage: Call with `./remove_stopping_executable.ts PATH/TO/YOUR/FILES`."); + process.exit(1); +} + +const folderPath = args[0]; + +// Function to check if the Docker image exists +async function imageExists(image: string): Promise<boolean> { + const { stdout } = await Bun.spawn(["docker", "images", "-q", image]); + const output = await new Response(stdout).text(); + return output.trim().length > 0; +} + +// Function to build the Docker image if it doesn't exist +async function buildImageIfNeeded(image: string): Promise<void> { + const exists = await imageExists(image); + if (!exists) { + console.log(`Building Docker image: ${image}`); + const buildProcess = Bun.spawn(["docker", "build", "-t", image, "."]); + const status = await buildProcess.exited; + if (status !== 0) { + console.error("Failed to build Docker image."); + process.exit(status); + } + } +} + +async function run() { + await buildImageIfNeeded("remove_stopping_image"); + + const dockerCommand = `docker run --rm -v "${folderPath}:/data" remove_stopping_image python ./remove_stopping.py -p /data -d 3`; + const runProcess = Bun.spawn(["sh", "-c", dockerCommand], { + stdout: "inherit", + stderr: "inherit", + }); + + const status = await runProcess.exited; + process.exit(status); +} + +run();