Files
netology-devops-gitlab/.gitlab-ci.yml
2022-09-16 10:45:00 +07:00

72 lines
1.7 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
stages:
- build
- test
- deploy
pre-build:
image: busybox:latest
stage: build
script:
- |
if [[ "$CI_COMMIT_BRANCH" == "$CI_DEFAULT_BRANCH" ]]; then
tag="latest"
echo "Running on default branch '$CI_DEFAULT_BRANCH': tag = 'latest'"
else
tag="$CI_COMMIT_REF_SLUG"
echo "Running on branch '$CI_COMMIT_BRANCH': tag = $tag"
fi
- echo "DOCKER_IMAGE=$CI_REGISTRY_IMAGE:${tag}"" > docker.env
artifacts:
reports:
dotenv:
docker.env
# todo взять скрипт с yandex
docker-build:
# Use the official docker image.
image: docker:latest
stage: build
services:
- docker:dind
needs:
- pre-build
before_script:
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
# All other branches are tagged with the escaped branch name (commit ref slug)
script:
- docker build --pull -t "$DOCKER_IMAGE" -f docker/Dockerfile .
- docker push "$DOCKER_IMAGE"
# Run this job in a branch where a Dockerfile exists
rules:
- if: $CI_COMMIT_BRANCH
exists:
- docker/Dockerfile
test-api:
image: alpine/curl:latest
stage: test
variables:
PYTHON_API_HOSTNAME: python-api
services:
- name: $DOCKER_IMAGE
alias: python-api
needs:
- pre-build
- docker-build
before_script:
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
script:
- ./test/validate_api.sh
# todo взять скрипт с yandex
deploy-main:
image: docker:latest
stage: deploy
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
before_script:
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
script:
- echo 1