2022-12-16 12:55:17 +00:00
|
|
|
cache:
|
|
|
|
key: one-key-to-rule-them-all
|
|
|
|
|
|
|
|
build:
|
|
|
|
image: docker:dind
|
|
|
|
interruptible: true
|
|
|
|
stage: build
|
|
|
|
rules:
|
2022-12-22 09:31:40 +00:00
|
|
|
- if: $CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH
|
2022-12-16 12:55:17 +00:00
|
|
|
tags: [ docker ]
|
2022-12-21 09:40:05 +00:00
|
|
|
before_script:
|
2022-12-21 10:06:09 +00:00
|
|
|
- echo "COMMIT=${CI_COMMIT_SHA}" >> version.env # COMMIT=`git rev-parse HEAD`
|
2022-12-16 12:55:17 +00: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}
|
|
|
|
|
|
|
|
test:
|
2022-12-23 06:40:27 +00:00
|
|
|
image: python:3.10-slim-bullseye
|
2022-12-16 12:55:17 +00:00
|
|
|
stage: test
|
2022-12-23 10:24:40 +00:00
|
|
|
variables:
|
|
|
|
DATABASE: sqlite:///../app/db.sqlite
|
2022-12-23 06:35:37 +00:00
|
|
|
before_script:
|
2022-12-23 06:36:33 +00:00
|
|
|
- pip install -r requirements.txt
|
2022-12-23 06:35:37 +00:00
|
|
|
- pip install pytest httpx
|
2022-12-23 06:43:02 +00:00
|
|
|
- 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
|
2022-12-23 06:41:18 +00:00
|
|
|
- cd test
|
2022-12-16 12:55:17 +00:00
|
|
|
script:
|
2022-12-23 06:35:37 +00:00
|
|
|
- pytest main.py
|
2022-12-16 12:55:17 +00:00
|
|
|
|
|
|
|
deploy:
|
|
|
|
stage: deploy
|
|
|
|
rules:
|
|
|
|
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
|
2022-12-21 09:48:36 +00:00
|
|
|
before_script:
|
2022-12-21 10:06:09 +00:00
|
|
|
- echo "COMMIT=${CI_COMMIT_SHA}" >> version.env
|
2022-12-21 09:48:36 +00:00
|
|
|
- source version.env
|
2022-12-21 10:11:55 +00:00
|
|
|
- echo "Building docker image for commit ${COMMIT} with version ${VERSION}"
|
2022-12-16 12:55:17 +00:00
|
|
|
script:
|
2022-12-22 09:31:40 +00:00
|
|
|
- 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"
|
2022-12-20 08:01:31 +00:00
|
|
|
- docker login -u $PUBLIC_REGISTRY_USER -p $PUBLIC_REGISTRY_TOKEN
|
2022-12-21 09:48:36 +00:00
|
|
|
- docker build . --tag $PUBLIC_REGISTRY_USER/${CI_PROJECT_NAME}:${VERSION}
|
2022-12-20 08:08:45 +00:00
|
|
|
- docker build . --tag $PUBLIC_REGISTRY_USER/${CI_PROJECT_NAME}:latest
|
2022-12-21 09:48:36 +00:00
|
|
|
- docker push $PUBLIC_REGISTRY_USER/${CI_PROJECT_NAME}:${VERSION}
|
2022-12-20 08:08:45 +00:00
|
|
|
- docker push $PUBLIC_REGISTRY_USER/${CI_PROJECT_NAME}:latest
|