mirror of
https://github.com/Dannecron/netology-devops-gitlab.git
synced 2025-12-25 15:22:35 +03:00
add test and gitlab-ci
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/.idea/
|
||||
71
.gitlab-ci.yml
Normal file
71
.gitlab-ci.yml
Normal file
@@ -0,0 +1,71 @@
|
||||
---
|
||||
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
|
||||
11
test/validate_api.sh
Executable file
11
test/validate_api.sh
Executable file
@@ -0,0 +1,11 @@
|
||||
#!/bin/sh
|
||||
|
||||
statusCode=$(curl -s -o /dev/null -w "%{http_code}" http://$PYTHON_API_HOSTNAME:5290/get_info)
|
||||
|
||||
if [ $statusCode == "200" ]; then
|
||||
echo "service available"
|
||||
exit 0
|
||||
else
|
||||
echo "service unavailable"
|
||||
exit 1
|
||||
fi
|
||||
Reference in New Issue
Block a user