fastapi-dls/.gitlab-ci.yml

103 lines
3.5 KiB
YAML
Raw Normal View History

2022-12-16 15:55:17 +03:00
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
2022-12-27 12:04:26 +03:00
# create conf file
2022-12-27 12:05:52 +03:00
- mkdir -p build/etc/fastapi-dls
2022-12-27 12:04:26 +03:00
- touch build/etc/fastapi-dls/env
2022-12-27 12:16:04 +03:00
# cd into "build/"
- cd build/
script:
2022-12-27 12:16:04 +03:00
- dpkg -b . build.deb
artifacts:
expire_in: 1 week
paths:
2022-12-27 12:19:35 +03:00
- build/build.deb
build:docker:
2022-12-16 15:55:17 +03:00
image: docker:dind
interruptible: true
stage: build
rules:
- if: $CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH
2022-12-16 15:55:17 +03:00
tags: [ docker ]
before_script:
2022-12-21 13:06:09 +03:00
- echo "COMMIT=${CI_COMMIT_SHA}" >> version.env # COMMIT=`git rev-parse HEAD`
2022-12-16 15:55:17 +03:00
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}
2022-12-23 15:48:48 +03:00
test:
image: python:3.10-slim-bullseye
stage: test
2022-12-23 13:24:40 +03:00
variables:
DATABASE: sqlite:///../app/db.sqlite
2022-12-23 15:48:48 +03:00
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
2022-12-16 15:55:17 +03:00
stage: test
needs:
- job: build:debian
artifacts: true
before_script:
- apt-get update -qq && apt-get install -qq -y jq # systemd
2022-12-16 15:55:17 +03:00
script:
2022-12-27 12:23:51 +03:00
- ls -alh build/
# test installation
2022-12-27 12:23:51 +03:00
- apt-get install -q -y ./build/build.deb --fix-missing
# 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
2022-12-16 15:55:17 +03:00
deploy:
stage: deploy
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
before_script:
2022-12-21 13:06:09 +03:00
- echo "COMMIT=${CI_COMMIT_SHA}" >> version.env
- source version.env
2022-12-21 13:11:55 +03:00
- echo "Building docker image for commit ${COMMIT} with version ${VERSION}"
2022-12-16 15:55:17 +03:00
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}
2022-12-20 11:08:45 +03:00
- docker build . --tag $PUBLIC_REGISTRY_USER/${CI_PROJECT_NAME}:latest
- docker push $PUBLIC_REGISTRY_USER/${CI_PROJECT_NAME}:${VERSION}
2022-12-20 11:08:45 +03:00
- docker push $PUBLIC_REGISTRY_USER/${CI_PROJECT_NAME}:latest