mirror of
https://gitea.publichub.eu/oscar.krause/fastapi-dls.git
synced 2024-11-10 00:18:47 +00:00
112 lines
3.9 KiB
YAML
112 lines
3.9 KiB
YAML
cache:
|
|
key: one-key-to-rule-them-all
|
|
|
|
build:debian:
|
|
# debian:bullseye-slim
|
|
image: debian:bookworm-slim # just to get "python3-jose" working
|
|
stage: build
|
|
before_script:
|
|
- apt-get update -qq && apt-get install -qq -y build-essential
|
|
- chmod 0755 -R .
|
|
# create build directory for .deb sources
|
|
- mkdir build
|
|
# copy install instructions
|
|
- cp -r DEBIAN build/
|
|
# copy app
|
|
- mkdir -p build/usr/share/
|
|
- cp -r app build/usr/share/fastapi-dls
|
|
# create conf file
|
|
- mkdir -p build/etc/fastapi-dls
|
|
- touch build/etc/fastapi-dls/env
|
|
# cd into "build/"
|
|
- cd build/
|
|
script:
|
|
- dpkg -b . build.deb
|
|
artifacts:
|
|
expire_in: 1 week
|
|
paths:
|
|
- build/build.deb
|
|
|
|
build:docker:
|
|
image: docker:dind
|
|
interruptible: true
|
|
stage: build
|
|
rules:
|
|
- if: $CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH
|
|
tags: [ docker ]
|
|
before_script:
|
|
- 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}
|
|
- docker push ${CI_REGISTRY}/${CI_PROJECT_PATH}/${CI_BUILD_REF_NAME}:${CI_BUILD_REF}
|
|
|
|
test:
|
|
image: python:3.10-slim-bullseye
|
|
stage: test
|
|
variables:
|
|
DATABASE: sqlite:///../app/db.sqlite
|
|
before_script:
|
|
- pip install -r requirements.txt
|
|
- pip install pytest httpx
|
|
- mkdir -p app/cert
|
|
- openssl genrsa -out app/cert/instance.private.pem 2048
|
|
- openssl rsa -in app/cert/instance.private.pem -outform PEM -pubout -out app/cert/instance.public.pem
|
|
- cd test
|
|
script:
|
|
- pytest main.py
|
|
|
|
test:debian:
|
|
image: debian:bookworm-slim
|
|
stage: test
|
|
variables:
|
|
DEBIAN_FRONTEND: noninteractive
|
|
needs:
|
|
- job: build:debian
|
|
artifacts: true
|
|
before_script:
|
|
- apt-get update -qq && apt-get install -qq -y jq # systemd
|
|
script:
|
|
# test installation
|
|
- apt-get install -q -y ./build/build.deb --fix-missing
|
|
- uvicorn --host 127.0.0.1 --port 443
|
|
--app-dir /usr/share/fastapi-dls/app
|
|
--ssl-keyfile /etc/fastapi-dls/webserver.key
|
|
--ssl-certfile /opt/fastapi-dls/webserver.crt
|
|
--proxy-headers &
|
|
- FASTAPI_DLS_PID=$!
|
|
- echo "Started service with pid $FASTAPI_DLS_PID"
|
|
- kill $FASTAPI_DLS_PID
|
|
# copy example config from GitLab-CI-Variables
|
|
#- cat ${EXAMPLE_CONFIG} > /etc/fastapi-dls/env
|
|
#- systemctl daemon-reload
|
|
#- systemctl enable fastapi-dls.service
|
|
#- systemctl start fastapi-dls.service
|
|
#- if [ "`curl --insecure -s https://localhost:8000/status | jq .status`" != "up" ]; then exit 2; fi
|
|
#- systemctl stop fastapi-dls.service
|
|
#- systemctl disable fastapi-dls.service
|
|
- apt-get purge -qq -y fastapi-dls
|
|
- apt-get autoremove -qq -y && apt-get clean -qq
|
|
|
|
deploy:
|
|
stage: deploy
|
|
rules:
|
|
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
|
|
before_script:
|
|
- echo "COMMIT=${CI_COMMIT_SHA}" >> version.env
|
|
- source version.env
|
|
- echo "Building docker image for commit ${COMMIT} with version ${VERSION}"
|
|
script:
|
|
- echo "GitLab-Registry"
|
|
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
|
|
- docker build . --tag ${CI_REGISTRY}/${CI_PROJECT_PATH}/${CI_BUILD_REF_NAME}:${VERSION}
|
|
- docker build . --tag ${CI_REGISTRY}/${CI_PROJECT_PATH}/${CI_BUILD_REF_NAME}:latest
|
|
- docker push ${CI_REGISTRY}/${CI_PROJECT_PATH}/${CI_BUILD_REF_NAME}:${VERSION}
|
|
- docker push ${CI_REGISTRY}/${CI_PROJECT_PATH}/${CI_BUILD_REF_NAME}:latest
|
|
- echo "Docker-Hub"
|
|
- docker login -u $PUBLIC_REGISTRY_USER -p $PUBLIC_REGISTRY_TOKEN
|
|
- 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}:${VERSION}
|
|
- docker push $PUBLIC_REGISTRY_USER/${CI_PROJECT_NAME}:latest
|