Last active
December 11, 2019 11:57
-
-
Save heckad/01f0ed0c8a3a282b8992e7758079d9a6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
image: docker:stable | |
services: | |
- docker:dind | |
stages: | |
- build_base_image | |
- build_test_image | |
- test | |
- deploy | |
variables: | |
SERVISE_NAME: example | |
PROJECT_FOLDER: example | |
PROJECT_HOST: example.com | |
PROJECT_HTTP_PROTOCOL: http | |
BASE_IMAGE_NAME: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG-$CI_COMMIT_SHORT_SHA | |
TEST_IMAGE_NAME: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG-$CI_COMMIT_SHORT_SHA-test | |
GIT_STRATEGY: none | |
default: | |
before_script: | |
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY | |
build-base: | |
stage: build_base_image | |
variables: | |
GIT_STRATEGY: fetch | |
script: | |
- docker build -t $BASE_IMAGE_NAME -f Dockerfile . | |
- docker push $BASE_IMAGE_NAME | |
build-test: | |
stage: build_test_image | |
script: | |
- docker run --entrypoint "" --name tmp $BASE_IMAGE_NAME pipenv install --system --dev --ignore-pipfile | |
- docker commit tmp $TEST_IMAGE_NAME | |
- docker push $TEST_IMAGE_NAME | |
only: | |
changes: | |
- Docerfile | |
- .pre-commit-config.yaml | |
- tests/**/* | |
- $PROJECT_FOLDER/**/* | |
check_stile: | |
stage: test | |
script: | |
- docker run $TEST_IMAGE_NAME pre-commit run -a | |
only: | |
changes: | |
- Docerfile | |
- .pre-commit-config.yaml | |
- tests/**/* | |
- $PROJECT_FOLDER/**/* | |
tests: | |
stage: test | |
script: | |
- docker run $TEST_IMAGE_NAME pytest --cov | |
coverage: '/^TOTAL.+?(\d+%)$/' | |
only: | |
changes: | |
- Docerfile | |
- tests/**/* | |
- $PROJECT_FOLDER/**/* | |
deploy to staging: | |
stage: deploy | |
image: | |
name: bitnami/kubectl:latest | |
entrypoint: [""] | |
variables: | |
GIT_STRATEGY: fetch | |
NAMESPACE: default | |
services: [] | |
before_script: [] | |
script: | |
- kubectl set image -n $NAMESPACE deployment/$SERVISE_NAME *="$BASE_IMAGE_NAME" | |
environment: | |
name: staging | |
url: $PROJECT_HOST://develop.$PROJECT_HOST | |
when: manual | |
only: | |
- master | |
- develop | |
deploy to production: | |
stage: deploy | |
image: | |
name: bitnami/kubectl:latest | |
entrypoint: [""] | |
variables: | |
GIT_STRATEGY: fetch | |
NAMESPACE: production | |
services: [] | |
before_script: [] | |
script: | |
- kubectl set image -n $NAMESPACE deployment/$SERVISE_NAME *="$BASE_IMAGE_NAME" | |
environment: | |
name: prod | |
url: $PROJECT_HTTP_PROTOCOL://$PROJECT_HOST | |
when: manual | |
only: | |
- master |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment