diff --git a/.github/workflows/dev.yml b/.github/workflows/dev.yml index 7d86c7e..0a4b097 100644 --- a/.github/workflows/dev.yml +++ b/.github/workflows/dev.yml @@ -47,7 +47,7 @@ jobs: IMAGE_NAME: ghcr.io/manimatter/decluttarr IMAGE_TAG: dev run: | - docker build -f docker/Dockerfile -t $IMAGE_NAME:$IMAGE_TAG --label com.decluttarr.version=$IMAGE_TAG . + docker build -f docker/Dockerfile -t $IMAGE_NAME:$IMAGE_TAG --label com.decluttarr.version=$IMAGE_TAG --build-arg IMAGE_TAG=$IMAGE_TAG . docker push $IMAGE_NAME:$IMAGE_TAG - name: "Delete untagged versions" diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e787074..24d8929 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -47,6 +47,6 @@ jobs: IMAGE_NAME: ghcr.io/manimatter/decluttarr IMAGE_TAG: ${{ steps.setversion.outputs.new_tag }} run: | - docker buildx build --platform linux/amd64,linux/arm64 -t $IMAGE_NAME:$IMAGE_TAG -t $IMAGE_NAME:latest --label com.decluttarr.version=$IMAGE_TAG -f docker/Dockerfile --push . + docker buildx build --platform linux/amd64,linux/arm64 -t $IMAGE_NAME:$IMAGE_TAG -t $IMAGE_NAME:latest --label com.decluttarr.version=$IMAGE_TAG --build-arg IMAGE_TAG=$IMAGE_TAG -f docker/Dockerfile --push . diff --git a/config/config.py b/config/config.py index d9b016a..c6331a3 100644 --- a/config/config.py +++ b/config/config.py @@ -6,6 +6,7 @@ import configparser ######################################################################################################################## # Check if in Docker IS_IN_DOCKER = os.environ.get('IS_IN_DOCKER') +IMAGE_TAG = os.environ.get('IMAGE_TAG', 'Local') ######################################################################################################################## def config_section_map(section): diff --git a/docker/Dockerfile b/docker/Dockerfile index c68e2fa..a053d89 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -3,6 +3,14 @@ # sudo docker run --rm -it --entrypoint sh ghcr.io/manimatter/decluttarr:dev FROM python:3.10.13-slim + +# Define a build-time argument for IMAGE_TAG +ARG IMAGE_TAG + +# Set an environment variable using the build-time argument +ENV IMAGE_TAG_ENV=$IMAGE_TAG + + LABEL org.opencontainers.image.source="https://github.com/ManiMatter/decluttarr" ENV IS_IN_DOCKER 1 diff --git a/main.py b/main.py index feeb765..bc4cd81 100644 --- a/main.py +++ b/main.py @@ -12,19 +12,6 @@ import requests import platform from packaging import version -import docker -def get_image_tag(): - # Retrieves the github version tag of the docker image - client = docker.from_env() - try: - container_info = client.containers.get('decluttarr') - image_tag = container_info.labels.get('decluttarr.version', 'No image tag provided') - return image_tag - except docker.errors.NotFound: - return 'Container not found' - except Exception as e: - return f'Error retrieving image tag: {e}' - ########### Enabling Logging # Set up logging log_level_num=logging.getLevelName(settings_dict['LOG_LEVEL']) @@ -73,10 +60,9 @@ async def main(): fmt = '{0.days} days {0.hours} hours {0.minutes} minutes' logger.info('#' * 50) logger.info('Decluttarr - Application Started!') - if settings_dict['IS_IN_DOCKER']: - logger.info('Version: %s', get_image_tag()) logger.info('') logger.info('*** Current Settings ***') + logger.info('Version: %s', settings_dict['IMAGE_TAG']) logger.info('%s | Removing failed downloads', str(settings_dict['REMOVE_FAILED'])) logger.info('%s | Removing downloads missing metadata', str(settings_dict['REMOVE_METADATA_MISSING'])) logger.info('%s | Removing downloads missing files', str(settings_dict['REMOVE_MISSING_FILES']))