From 7eddb1786255e20e50fb95511531f382a167d34f Mon Sep 17 00:00:00 2001 From: Oscar Krause Date: Wed, 21 Dec 2022 10:48:36 +0100 Subject: [PATCH 1/5] Dockerfile - include version.env to image --- .gitlab-ci.yml | 7 +++++-- Dockerfile | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index ffa1295..076485b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -24,9 +24,12 @@ deploy: stage: deploy rules: - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH + before_script: + - source version.env + - Building docker image for commit "${COMMIT}" with version "${VERSION}" script: - docker login -u $PUBLIC_REGISTRY_USER -p $PUBLIC_REGISTRY_TOKEN - - docker build . --tag $PUBLIC_REGISTRY_USER/${CI_PROJECT_NAME}:${CI_BUILD_REF} + - docker build . --tag $PUBLIC_REGISTRY_USER/${CI_PROJECT_NAME}:${VERSION} - docker build . --tag $PUBLIC_REGISTRY_USER/${CI_PROJECT_NAME}:latest - - docker push $PUBLIC_REGISTRY_USER/${CI_PROJECT_NAME}:${CI_BUILD_REF} + - docker push $PUBLIC_REGISTRY_USER/${CI_PROJECT_NAME}:${VERSION} - docker push $PUBLIC_REGISTRY_USER/${CI_PROJECT_NAME}:latest diff --git a/Dockerfile b/Dockerfile index c3aa040..9b5a9f3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,6 +11,7 @@ RUN apk update \ && apk del build-deps COPY app /app +COPY version.env /app/version.env COPY README.md /README.md HEALTHCHECK --start-period=30s --interval=10s --timeout=5s --retries=3 CMD curl --insecure --fail https://localhost/status || exit 1 From 418473157147ec84eaa4d82d4c974d7f38826907 Mon Sep 17 00:00:00 2001 From: Oscar Krause Date: Wed, 21 Dec 2022 10:53:51 +0100 Subject: [PATCH 2/5] dotenv fixes --- app/main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/main.py b/app/main.py index 2af3bc9..b48ffab 100644 --- a/app/main.py +++ b/app/main.py @@ -5,7 +5,7 @@ from uuid import uuid4 from os.path import join, dirname from os import getenv -from dotenv import dotenv_values +from dotenv import load_dotenv from fastapi import FastAPI, HTTPException from fastapi.requests import Request from fastapi.encoders import jsonable_encoder @@ -22,7 +22,7 @@ from Crypto.PublicKey import RSA from Crypto.PublicKey.RSA import RsaKey logger = logging.getLogger() -dotenv_values('version.env') +load_dotenv('version.env') VERSION, COMMIT, DEBUG = getenv('VERSION', 'unknown'), getenv('COMMIT', 'unknown'), bool(getenv('DEBUG', False)) From c5b6c79d1c8ec317590baf9ce86ce8678fca05ce Mon Sep 17 00:00:00 2001 From: Oscar Krause Date: Wed, 21 Dec 2022 11:06:09 +0100 Subject: [PATCH 3/5] fixes --- .gitlab-ci.yml | 3 ++- Dockerfile | 2 +- app/main.py | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 076485b..52fa10f 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -9,7 +9,7 @@ build: - if: $CI_COMMIT_BRANCH tags: [ docker ] before_script: - - echo "COMMIT=`git rev-parse HEAD`" >> version.env + - echo "COMMIT=${CI_COMMIT_SHA}" >> version.env # COMMIT=`git rev-parse HEAD` script: - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY - docker build . --tag ${CI_REGISTRY}/${CI_PROJECT_PATH}/${CI_BUILD_REF_NAME}:${CI_BUILD_REF} @@ -25,6 +25,7 @@ deploy: rules: - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH before_script: + - echo "COMMIT=${CI_COMMIT_SHA}" >> version.env - source version.env - Building docker image for commit "${COMMIT}" with version "${VERSION}" script: diff --git a/Dockerfile b/Dockerfile index 9b5a9f3..5819ef5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,7 +11,7 @@ RUN apk update \ && apk del build-deps COPY app /app -COPY version.env /app/version.env +COPY version.env /version.env COPY README.md /README.md HEALTHCHECK --start-period=30s --interval=10s --timeout=5s --retries=3 CMD curl --insecure --fail https://localhost/status || exit 1 diff --git a/app/main.py b/app/main.py index b48ffab..f35d3fc 100644 --- a/app/main.py +++ b/app/main.py @@ -22,7 +22,7 @@ from Crypto.PublicKey import RSA from Crypto.PublicKey.RSA import RsaKey logger = logging.getLogger() -load_dotenv('version.env') +load_dotenv('../version.env') VERSION, COMMIT, DEBUG = getenv('VERSION', 'unknown'), getenv('COMMIT', 'unknown'), bool(getenv('DEBUG', False)) From 6afb121533973f5cfeea759cf1eb56694838d0dd Mon Sep 17 00:00:00 2001 From: Oscar Krause Date: Wed, 21 Dec 2022 11:06:25 +0100 Subject: [PATCH 4/5] README.md - added docs section --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 7005045..25a7547 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,10 @@ HTML rendered README.md. Status endpoint, used for *healthcheck*. Shows also current version and commit hash. +### `GET /docs` + +OpenAPI specifications rendered from `GET /openapi.json`. + ### `GET /-/origins` List registered origins. From 00f6590a9f9dce751cbf75bf7bca98d4cddd6e5b Mon Sep 17 00:00:00 2001 From: Oscar Krause Date: Wed, 21 Dec 2022 11:11:55 +0100 Subject: [PATCH 5/5] .gitlab-ci.yml fixes --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 52fa10f..effbf3c 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -27,7 +27,7 @@ deploy: before_script: - echo "COMMIT=${CI_COMMIT_SHA}" >> version.env - source version.env - - Building docker image for commit "${COMMIT}" with version "${VERSION}" + - echo "Building docker image for commit ${COMMIT} with version ${VERSION}" script: - docker login -u $PUBLIC_REGISTRY_USER -p $PUBLIC_REGISTRY_TOKEN - docker build . --tag $PUBLIC_REGISTRY_USER/${CI_PROJECT_NAME}:${VERSION}