From 4f4f4676678dac78cd3e89c15e00d507c9ef5642 Mon Sep 17 00:00:00 2001 From: Stingray <44787842+OutboundSpade@users.noreply.github.com> Date: Fri, 21 Jul 2023 12:18:54 -0400 Subject: [PATCH 1/7] Updated config.yml --- .circleci/config.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index c3d0f38..006434a 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -10,7 +10,8 @@ jobs: steps: - run: | echo "export REPO_NAME=$(printf '%s\n' \"${CIRCLE_PROJECT_REPONAME,,}\")" >> $BASH_ENV && \ - echo "export USER=$(printf '%s\n' \"${CIRCLE_PROJECT_USERNAME,,}\")" >> $BASH_ENV + echo "export USER=$(printf '%s\n' \"${CIRCLE_PROJECT_USERNAME,,}\")" >> $BASH_ENV && \ + echo "export VERSION=$CIRCLE_TAG" >> $BASH_ENV - checkout - docker/check: docker-username: CIRCLE_PROJECT_USERNAME From 7ccf8ea80219b73ee4d1352bdb13a88be718c9e7 Mon Sep 17 00:00:00 2001 From: Stingray <44787842+OutboundSpade@users.noreply.github.com> Date: Fri, 21 Jul 2023 12:49:51 -0400 Subject: [PATCH 2/7] Updated config.yml --- .circleci/config.yml | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 006434a..f520edb 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -8,17 +8,20 @@ jobs: docker_layer_caching: false resource_class: arm.medium steps: - - run: | - echo "export REPO_NAME=$(printf '%s\n' \"${CIRCLE_PROJECT_REPONAME,,}\")" >> $BASH_ENV && \ - echo "export USER=$(printf '%s\n' \"${CIRCLE_PROJECT_USERNAME,,}\")" >> $BASH_ENV && \ - echo "export VERSION=$CIRCLE_TAG" >> $BASH_ENV + - run: + name: Setup Custom Environment Variables + command: | + echo "export REPO_NAME=$(printf '%s\n' \"${CIRCLE_PROJECT_REPONAME,,}\")" >> $BASH_ENV && \ + echo "export USER=$(printf '%s\n' \"${CIRCLE_PROJECT_USERNAME,,}\")" >> $BASH_ENV && \ + echo "export VERSION=$CIRCLE_TAG" >> $BASH_ENV && \ + echo "export TIMESTAMP=$(date --rfc-3339=seconds | sed 's/[ :]/-/g')" >> $BASH_ENV - checkout - docker/check: docker-username: CIRCLE_PROJECT_USERNAME registry: ghcr.io - docker/build: image: $USER/$REPO_NAME - tag: ${VERSION:-latest} + tag: ${VERSION:-NIGHTLY.$TIMESTAMP} registry: ghcr.io - docker/push: digest-path: /tmp/digest.txt From 8073e7835c9b7f7faafaf0f9ef53f0cb9845fa9a Mon Sep 17 00:00:00 2001 From: Stingray <44787842+OutboundSpade@users.noreply.github.com> Date: Fri, 21 Jul 2023 12:52:23 -0400 Subject: [PATCH 3/7] Updated config.yml --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index f520edb..0e0c5f1 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -14,7 +14,7 @@ jobs: echo "export REPO_NAME=$(printf '%s\n' \"${CIRCLE_PROJECT_REPONAME,,}\")" >> $BASH_ENV && \ echo "export USER=$(printf '%s\n' \"${CIRCLE_PROJECT_USERNAME,,}\")" >> $BASH_ENV && \ echo "export VERSION=$CIRCLE_TAG" >> $BASH_ENV && \ - echo "export TIMESTAMP=$(date --rfc-3339=seconds | sed 's/[ :]/-/g')" >> $BASH_ENV + echo "export TIMESTAMP=$(date --rfc-3339=seconds | sed 's/[ :+]/-/g')" >> $BASH_ENV - checkout - docker/check: docker-username: CIRCLE_PROJECT_USERNAME From c9e90dbb9e33dc643dd0a5df197a5fdc77e59e62 Mon Sep 17 00:00:00 2001 From: Stingray <44787842+OutboundSpade@users.noreply.github.com> Date: Fri, 21 Jul 2023 12:55:48 -0400 Subject: [PATCH 4/7] Updated config.yml --- .circleci/config.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 0e0c5f1..c4c110c 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -26,7 +26,7 @@ jobs: - docker/push: digest-path: /tmp/digest.txt image: $USER/$REPO_NAME - tag: ${VERSION:-latest} + tag: ${VERSION:-NIGHTLY.$TIMESTAMP} registry: ghcr.io - run: command: | @@ -36,5 +36,7 @@ workflows: jobs: - build-and-push: filters: - tags: # see: https://circleci.com/blog/publishing-to-github-releases-via-circleci/ - only: /(?<=^[Vv]|^)(?:(?(?:0|[1-9](?:(?:0|[1-9])+)*))[.](?(?:0|[1-9](?:(?:0|[1-9])+)*))[.](?(?:0|[1-9](?:(?:0|[1-9])+)*))(?:-(?(?:(?:(?:[A-Za-z]|-)(?:(?:(?:0|[1-9])|(?:[A-Za-z]|-))+)?|(?:(?:(?:0|[1-9])|(?:[A-Za-z]|-))+)(?:[A-Za-z]|-)(?:(?:(?:0|[1-9])|(?:[A-Za-z]|-))+)?)|(?:0|[1-9](?:(?:0|[1-9])+)*))(?:[.](?:(?:(?:[A-Za-z]|-)(?:(?:(?:0|[1-9])|(?:[A-Za-z]|-))+)?|(?:(?:(?:0|[1-9])|(?:[A-Za-z]|-))+)(?:[A-Za-z]|-)(?:(?:(?:0|[1-9])|(?:[A-Za-z]|-))+)?)|(?:0|[1-9](?:(?:0|[1-9])+)*)))*))?(?:[+](?(?:(?:(?:[A-Za-z]|-)(?:(?:(?:0|[1-9])|(?:[A-Za-z]|-))+)?|(?:(?:(?:0|[1-9])|(?:[A-Za-z]|-))+)(?:[A-Za-z]|-)(?:(?:(?:0|[1-9])|(?:[A-Za-z]|-))+)?)|(?:(?:0|[1-9])+))(?:[.](?:(?:(?:[A-Za-z]|-)(?:(?:(?:0|[1-9])|(?:[A-Za-z]|-))+)?|(?:(?:(?:0|[1-9])|(?:[A-Za-z]|-))+)(?:[A-Za-z]|-)(?:(?:(?:0|[1-9])|(?:[A-Za-z]|-))+)?)|(?:(?:0|[1-9])+)))*))?)$/ \ No newline at end of file + branches: + only: main + # tags: # see: https://circleci.com/blog/publishing-to-github-releases-via-circleci/ + # only: /(?<=^[Vv]|^)(?:(?(?:0|[1-9](?:(?:0|[1-9])+)*))[.](?(?:0|[1-9](?:(?:0|[1-9])+)*))[.](?(?:0|[1-9](?:(?:0|[1-9])+)*))(?:-(?(?:(?:(?:[A-Za-z]|-)(?:(?:(?:0|[1-9])|(?:[A-Za-z]|-))+)?|(?:(?:(?:0|[1-9])|(?:[A-Za-z]|-))+)(?:[A-Za-z]|-)(?:(?:(?:0|[1-9])|(?:[A-Za-z]|-))+)?)|(?:0|[1-9](?:(?:0|[1-9])+)*))(?:[.](?:(?:(?:[A-Za-z]|-)(?:(?:(?:0|[1-9])|(?:[A-Za-z]|-))+)?|(?:(?:(?:0|[1-9])|(?:[A-Za-z]|-))+)(?:[A-Za-z]|-)(?:(?:(?:0|[1-9])|(?:[A-Za-z]|-))+)?)|(?:0|[1-9](?:(?:0|[1-9])+)*)))*))?(?:[+](?(?:(?:(?:[A-Za-z]|-)(?:(?:(?:0|[1-9])|(?:[A-Za-z]|-))+)?|(?:(?:(?:0|[1-9])|(?:[A-Za-z]|-))+)(?:[A-Za-z]|-)(?:(?:(?:0|[1-9])|(?:[A-Za-z]|-))+)?)|(?:(?:0|[1-9])+))(?:[.](?:(?:(?:[A-Za-z]|-)(?:(?:(?:0|[1-9])|(?:[A-Za-z]|-))+)?|(?:(?:(?:0|[1-9])|(?:[A-Za-z]|-))+)(?:[A-Za-z]|-)(?:(?:(?:0|[1-9])|(?:[A-Za-z]|-))+)?)|(?:(?:0|[1-9])+)))*))?)$/ \ No newline at end of file From 1ce4ba97f3ec5e3e7ef93baec1c94dfbc7cc6e80 Mon Sep 17 00:00:00 2001 From: Stingray <44787842+OutboundSpade@users.noreply.github.com> Date: Fri, 21 Jul 2023 15:22:33 -0400 Subject: [PATCH 5/7] Add Versioning to build process Version info will automatically appear in default route --- .circleci/config.yml | 13 +++++++------ Dockerfile | 2 ++ app.py | 12 +++++++++--- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index c4c110c..f2f5b99 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -8,25 +8,26 @@ jobs: docker_layer_caching: false resource_class: arm.medium steps: + - checkout - run: - name: Setup Custom Environment Variables + name: Setup Custom Environment Variables & Add Version command: | echo "export REPO_NAME=$(printf '%s\n' \"${CIRCLE_PROJECT_REPONAME,,}\")" >> $BASH_ENV && \ echo "export USER=$(printf '%s\n' \"${CIRCLE_PROJECT_USERNAME,,}\")" >> $BASH_ENV && \ - echo "export VERSION=$CIRCLE_TAG" >> $BASH_ENV && \ - echo "export TIMESTAMP=$(date --rfc-3339=seconds | sed 's/[ :+]/-/g')" >> $BASH_ENV - - checkout + export VERSION=${CIRCLE_TAG:-NIGHTLY.$(date --rfc-3339=seconds | sed 's/[ :+]/-/g')} && \ + echo "export VERSION=$VERSION" >> $BASH_ENV && \ + echo $VERSION > version.txt - docker/check: docker-username: CIRCLE_PROJECT_USERNAME registry: ghcr.io - docker/build: image: $USER/$REPO_NAME - tag: ${VERSION:-NIGHTLY.$TIMESTAMP} + tag: $VERSION registry: ghcr.io - docker/push: digest-path: /tmp/digest.txt image: $USER/$REPO_NAME - tag: ${VERSION:-NIGHTLY.$TIMESTAMP} + tag: $VERSION registry: ghcr.io - run: command: | diff --git a/Dockerfile b/Dockerfile index 17d7163..8617066 100644 --- a/Dockerfile +++ b/Dockerfile @@ -23,6 +23,8 @@ COPY --from=base /usr/local/bin/gunicorn /usr/local/bin/gunicorn COPY ./*.py /app/ +COPY ./*.txt /app/ + COPY ./scripts/download_hitran.py . CMD gunicorn --bind 0.0.0.0:5000 wsgi:app diff --git a/app.py b/app.py index 3d632df..6476552 100644 --- a/app.py +++ b/app.py @@ -16,12 +16,18 @@ app = Flask(__name__) CORS(app) - +try: + with open("version.txt","r") as f: + version = f.read() + app.config["VERSION"] = version +except: + print("no version file found") @app.route("/", methods=["GET"]) def ftir() -> str: - return "

Raston Lab FTIR API

" - + if "VERSION" not in app.config: + app.config["VERSION"] = "0.0.0" + return "

Raston Lab FTIR API%s

" % (" - Version "+app.config["VERSION"]) @app.route("/spectrum", methods=["POST"]) def spectrum() -> dict[bool, list[float], list[float]]: From 0b53f2e30b2b48657de44a15198db3856cca0862 Mon Sep 17 00:00:00 2001 From: Stingray <44787842+OutboundSpade@users.noreply.github.com> Date: Fri, 21 Jul 2023 15:30:32 -0400 Subject: [PATCH 6/7] Add runtime deps to Dockerfile --- Dockerfile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 8617066..74f9b9c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ FROM python:3.10-slim-bullseye as base -RUN apt update && apt install wget tar git libpcrecpp0v5 -y +RUN apt update && apt install wget tar git -y WORKDIR /app @@ -14,6 +14,8 @@ RUN pip3 install --no-index --find-links=/app/packages -r /app/scripts/requireme FROM python:3.10-slim-bullseye +RUN apt update && apt install libpcrecpp0v5 -y + WORKDIR /app # copy pip packages from base From 07b3d62ba7d1cb025a3090eff60e6dc30f033c91 Mon Sep 17 00:00:00 2001 From: Stingray <44787842+OutboundSpade@users.noreply.github.com> Date: Fri, 21 Jul 2023 15:55:10 -0400 Subject: [PATCH 7/7] Updated config.yml --- .circleci/config.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index f2f5b99..edc0177 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -39,5 +39,5 @@ workflows: filters: branches: only: main - # tags: # see: https://circleci.com/blog/publishing-to-github-releases-via-circleci/ - # only: /(?<=^[Vv]|^)(?:(?(?:0|[1-9](?:(?:0|[1-9])+)*))[.](?(?:0|[1-9](?:(?:0|[1-9])+)*))[.](?(?:0|[1-9](?:(?:0|[1-9])+)*))(?:-(?(?:(?:(?:[A-Za-z]|-)(?:(?:(?:0|[1-9])|(?:[A-Za-z]|-))+)?|(?:(?:(?:0|[1-9])|(?:[A-Za-z]|-))+)(?:[A-Za-z]|-)(?:(?:(?:0|[1-9])|(?:[A-Za-z]|-))+)?)|(?:0|[1-9](?:(?:0|[1-9])+)*))(?:[.](?:(?:(?:[A-Za-z]|-)(?:(?:(?:0|[1-9])|(?:[A-Za-z]|-))+)?|(?:(?:(?:0|[1-9])|(?:[A-Za-z]|-))+)(?:[A-Za-z]|-)(?:(?:(?:0|[1-9])|(?:[A-Za-z]|-))+)?)|(?:0|[1-9](?:(?:0|[1-9])+)*)))*))?(?:[+](?(?:(?:(?:[A-Za-z]|-)(?:(?:(?:0|[1-9])|(?:[A-Za-z]|-))+)?|(?:(?:(?:0|[1-9])|(?:[A-Za-z]|-))+)(?:[A-Za-z]|-)(?:(?:(?:0|[1-9])|(?:[A-Za-z]|-))+)?)|(?:(?:0|[1-9])+))(?:[.](?:(?:(?:[A-Za-z]|-)(?:(?:(?:0|[1-9])|(?:[A-Za-z]|-))+)?|(?:(?:(?:0|[1-9])|(?:[A-Za-z]|-))+)(?:[A-Za-z]|-)(?:(?:(?:0|[1-9])|(?:[A-Za-z]|-))+)?)|(?:(?:0|[1-9])+)))*))?)$/ \ No newline at end of file + tags: # see: https://circleci.com/blog/publishing-to-github-releases-via-circleci/ + only: /(?<=^[Vv]|^)(?:(?(?:0|[1-9](?:(?:0|[1-9])+)*))[.](?(?:0|[1-9](?:(?:0|[1-9])+)*))[.](?(?:0|[1-9](?:(?:0|[1-9])+)*))(?:-(?(?:(?:(?:[A-Za-z]|-)(?:(?:(?:0|[1-9])|(?:[A-Za-z]|-))+)?|(?:(?:(?:0|[1-9])|(?:[A-Za-z]|-))+)(?:[A-Za-z]|-)(?:(?:(?:0|[1-9])|(?:[A-Za-z]|-))+)?)|(?:0|[1-9](?:(?:0|[1-9])+)*))(?:[.](?:(?:(?:[A-Za-z]|-)(?:(?:(?:0|[1-9])|(?:[A-Za-z]|-))+)?|(?:(?:(?:0|[1-9])|(?:[A-Za-z]|-))+)(?:[A-Za-z]|-)(?:(?:(?:0|[1-9])|(?:[A-Za-z]|-))+)?)|(?:0|[1-9](?:(?:0|[1-9])+)*)))*))?(?:[+](?(?:(?:(?:[A-Za-z]|-)(?:(?:(?:0|[1-9])|(?:[A-Za-z]|-))+)?|(?:(?:(?:0|[1-9])|(?:[A-Za-z]|-))+)(?:[A-Za-z]|-)(?:(?:(?:0|[1-9])|(?:[A-Za-z]|-))+)?)|(?:(?:0|[1-9])+))(?:[.](?:(?:(?:[A-Za-z]|-)(?:(?:(?:0|[1-9])|(?:[A-Za-z]|-))+)?|(?:(?:(?:0|[1-9])|(?:[A-Za-z]|-))+)(?:[A-Za-z]|-)(?:(?:(?:0|[1-9])|(?:[A-Za-z]|-))+)?)|(?:(?:0|[1-9])+)))*))?)$/ \ No newline at end of file