Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
itsamenathan committed Dec 3, 2023
1 parent d35130a commit 28b3d10
Show file tree
Hide file tree
Showing 7 changed files with 249 additions and 1 deletion.
41 changes: 41 additions & 0 deletions .github/workflows/latest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Build latest image

on:
push:
branches:
- main

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build-and-push-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Log in to the Container registry
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Build and push Docker image
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
data
8 changes: 8 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM python:latest

RUN git clone https://github.com/daniel-widrick/zap2it-GuideScraping.git /zap2it

ADD entry.sh /entry.sh
RUN chmod 755 /entry.sh /zap2it/zap2it-GuideScrape.py

CMD ["/entry.sh"]
92 changes: 91 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,91 @@
# zap2it
# zap2it

This is a docker image for running [daniel-widrick/zap2it-GuideScraping](https://github.com/daniel-widrick/zap2it-GuideScraping) in an automated way.

## Features
* Running of zap2it-GuideScrape.py
* Docker Compose examples
* Removal of historical xmlguide files
* Healthcheck.io integration
* Run once, or forever based on sleep time

## Environment Variables Options
* CONFIGFILE: [string]
* Location of your config file.
* default: `/data/zap2itconfig.ini`
* OUTPUTFILE: [string]
* Location where you want the output file to be placed.
* default: `/data/xmlguide.xmltv`
* HEALTHCHECK_URL: [string]
* URL to ping when starting and ending the run.
* default: `undefined`
* SLEEPTIME: [int]
* Number of seconds to sleep before running again.
* default: `undefined`

## Running

### Only Once

#### docker cli
``` bash
docker run
-v $(PWD)/data:/data
-e CONFIGFILE=/data/zap2itconfig.ini
-e OUTPUTFILE=/data/xmlguide.xmltv
-e HEALTHCHECK_URL=https://hc-ping.com/UUID
--user 1000:1000
ghcr.io/itsamenathan/zap2it:main
```
#### docker-compose.yml

``` yml
version: '3'
services:
zap2it:
image: ghcr.io/itsamenathan/zap2it:main
volumes:
- ./data:/data
environment:
CONFIGFILE: "/data/zap2itconfig.ini"
OUTPUTFILE: "/data/xmlguide.xmltv"
HEALTHCHECK_URL: "https://hc-ping.com/UUID"
user: "1000:1000"
```
### Running Continually
The only difference is adding the `SLEEPTIME` variable.

#### docker cli
``` bash
docker run
-v $(PWD)/data:/data
-e CONFIGFILE=/data/zap2itconfig.ini
-e OUTPUTFILE=/data/xmlguide.xmltv
-e HEALTHCHECK_URL=https://hc-ping.com/UUID
-e SLEEPTIME=43200
--user 1000:1000
ghcr.io/itsamenathan/zap2it:main
```
#### docker-compose.yml

``` yml
version: '3'
services:
zap2it:
image: ghcr.io/itsamenathan/zap2it:main
volumes:
- ./data:/data
environment:
CONFIGFILE: "/data/zap2itconfig.ini"
OUTPUTFILE: "/data/xmlguide.xmltv"
HEALTHCHECK_URL: "https://hc-ping.com/UUID"
SLEEPTIME: 43200
user: "1000:1000"
```

### Running with [ofelia](https://github.com/mcuadros/ofelia)

Ofelia can run a docker container on a schedule for you.
Check out the [docker-compose.ofelia.yml](docker-compose.ofelia.yml) for reference.
26 changes: 26 additions & 0 deletions docker-compose.ofelia.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
version: '3'

services:
zap2it:
container_name: ghcr.io/itsamenathan/zap2it:main
image: zap2it
volumes:
- ./data:/data
environment:
CONFIGFILE: "/data/zap2itconfig.ini"
OUTPUTFILE: "/data/xmlguide.xmltv"
HEALTHCHECK_URL: "https://hc-ping.com/UUID" # CHANGE ME
user: "1000:1000"

ofelia:
image: mcuadros/ofelia:latest
restart: always
depends_on:
- zap2it
command: daemon --docker
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
labels:
ofelia.enabled: "true"
ofelia.job-run.zap2it.schedule: "@every 12h"
ofelia.job-run.zap2it.Container: "zap2it"
13 changes: 13 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version: '3'

services:
zap2it:
container_name: zap2it
image: ghcr.io/itsamenathan/zap2it:main
volumes:
- ./data:/data
environment:
CONFIGFILE: "/data/zap2itconfig.ini"
OUTPUTFILE: "/data/xmlguide.xmltv"
HEALTHCHECK_URL: "https://hc-ping.com/UUID" # CHANGE ME
user: "1000:1000"
69 changes: 69 additions & 0 deletions entry.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/bin/bash

config_file="${CONFIGFILE:-/data/zap2itconfig.ini}"
output_file="${OUTPUTFILE:-/data/xmlguide.xmltv}"
output_dir="$(dirname "$output_file")"
date_format="%Y-%m-%d %H:%M:%S %Z"

# Ping a healthcheck.io endpoint
healthcheck_io() {
[ "$1" ] && local url_path="/${1}" || local url_path=""
if [ "$HEALTHCHECK_URL" ]; then
curl -fsS -m 10 --retry 5 -o /dev/null "$HEALTHCHECK_URL$url_path"
fi
}

# Validate some checks before running main
validate() {
# Check output dir
if [ ! -d "$output_dir" ] || [ ! -w "$output_dir" ]; then
echo "Directory does not exist or is not writable...exiting"
exit 1
fi

# Check for config file
if [ ! -f "$config_file" ]; then
echo "Can't find $config_file...exiting"
exit 1
fi
}

zap2it() {
echo "Started: $(date +"$date_format")"

# Run script
python /zap2it/zap2it-GuideScrape.py \
--configfile "$config_file" \
--outputfile "$output_file" \
--language "${LANGUAGE:-en}"

echo "Finished: $(date +"$date_format")"

# remove historical files
rm "$output_dir"/xmlguide.2*.xmltv
}

main() {
# Loop if sleeptime is defined
if [ "$SLEEPTIME" ]; then
while true; do
echo "Running zap2it"
zap2it

echo "Next: $(date +"$date_format" -d "+$SLEEPTIME seconds")"

# sleep until next run
sleep "$SLEEPTIME"
done
else
echo "Running zap2it"
zap2it
fi

}

# Run the scripts functions
healthcheck_io "start"
validate
main
healthcheck_io

0 comments on commit 28b3d10

Please sign in to comment.