From dd211d166c38aa27558339b97fdf6fe8486931c9 Mon Sep 17 00:00:00 2001 From: dgtlmoon Date: Fri, 28 May 2021 10:20:23 +1000 Subject: [PATCH] Include release metadata during github build --- .github/workflows/image.yml | 8 +++++++- Dockerfile | 8 +------- backend/store.py | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/.github/workflows/image.yml b/.github/workflows/image.yml index 221fafc8..8cbd8acb 100644 --- a/.github/workflows/image.yml +++ b/.github/workflows/image.yml @@ -28,6 +28,12 @@ jobs: # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + - name: Create release metadata + run: | + # COPY'ed by Dockerfile into backend/ of the image, then read by the server in store.py + echo ${{ steps.vars.outputs.sha_short }} > backend/source.txt + echo ${{ steps.vars.outputs.tag }} > backend/tag.txt + - name: Test with pytest run: | # Each test is totally isolated and performs its own cleanup/reset @@ -68,7 +74,7 @@ jobs: cache-to: type=local,dest=/tmp/.buildx-cache - name: Image digest - run: echo ${{ steps.docker_build.outputs.digest }} + run: echo step SHA ${{ steps.vars.outputs.sha_short }} tag ${{steps.vars.outputs.tag}} branch ${{steps.vars.outputs.branch}} digest ${{ steps.docker_build.outputs.digest }} # failed: Cache service responded with 503 # - name: Cache Docker layers diff --git a/Dockerfile b/Dockerfile index c8744308..c75478d7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,12 +4,11 @@ FROM python:3.8-slim ARG CRYPTOGRAPHY_DONT_BUILD_RUST=1 COPY requirements.txt /tmp/requirements.txt -RUN apt-get update && apt-get install -y libssl-dev libffi-dev gcc libc-dev libxslt-dev zlib1g-dev rustc g++ --no-install-recommends && rm -rf /var/lib/apt/lists/* /var/cache/apt/* +RUN apt-get update && apt-get install -y libssl-dev libffi-dev gcc libc-dev libxslt-dev zlib1g-dev rustc g++ --no-install-recommends && rm -rf /var/lib/apt/lists/* /var/cache/apt/* # Update pip, install requirements, remove rust and dev packages that are no longer needed. RUN pip3 install --upgrade pip && pip3 install --no-cache-dir -r /tmp/requirements.txt && apt-get remove rustc *-dev --purge -y - RUN [ ! -d "/app" ] && mkdir /app RUN [ ! -d "/datastore" ] && mkdir /datastore @@ -24,11 +23,6 @@ WORKDIR /app # https://stackoverflow.com/questions/58701233/docker-logs-erroneously-appears-empty-until-container-stops ENV PYTHONUNBUFFERED=1 -# Attempt to store the triggered commit -ARG SOURCE_COMMIT -ARG SOURCE_BRANCH -RUN echo "commit: $SOURCE_COMMIT branch: $SOURCE_BRANCH" >/source.txt - CMD [ "python", "./changedetection.py" , "-d", "/datastore"] diff --git a/backend/store.py b/backend/store.py index 34e4938b..755db80d 100644 --- a/backend/store.py +++ b/backend/store.py @@ -63,8 +63,8 @@ class ChangeDetectionStore: 'notification_urls': [] # List of URLs to add to the notification Queue (Usually AppRise) } - if path.isfile('/source.txt'): - with open('/source.txt') as f: + if path.isfile('backend/source.txt'): + with open('backend/source.txt') as f: # Should be set in Dockerfile to look for /source.txt , this will give us the git commit # # So when someone gives us a backup file to examine, we know exactly what code they were running. self.__data['build_sha'] = f.read()