Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# Build, tag, and push the Docker images to the GitLab Docker registry
build compute:
variables:
IMAGE_NAME: 'compute' # name of the microservice
IMAGE_NAME_TEST: 'compute-test' # name of the microservice
IMAGE_TAG: 'latest' # tag of the container image (production, development, etc)
stage: build
before_script:
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
script:
- docker build -t "$IMAGE_NAME:$IMAGE_TAG" -f ./src/$IMAGE_NAME/Dockerfile ./src/
- docker tag "$IMAGE_NAME:$IMAGE_TAG" "$CI_REGISTRY_IMAGE/$IMAGE_NAME:$IMAGE_TAG"
- docker push "$CI_REGISTRY_IMAGE/$IMAGE_NAME:$IMAGE_TAG"
rules:
- changes:
- src/$IMAGE_NAME/**
- .gitlab-ci.yml
# Pull, execute, and run unitary tests for the Docker image from the GitLab registry
unit_test compute:
variables:
IMAGE_NAME: 'compute' # name of the microservice
IMAGE_NAME_TEST: 'compute-test' # name of the microservice
IMAGE_TAG: 'latest' # tag of the container image (production, development, etc)
stage: unit_test
needs:
- build compute
before_script:
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
- if docker network list | grep teraflowbridge; then echo "teraflowbridge is already created"; else docker network create -d bridge teraflowbridge; fi
script:
- docker pull "$CI_REGISTRY_IMAGE/$IMAGE_NAME:$IMAGE_TAG"
- docker run -d -p 9090:9090 --name $IMAGE_NAME --network=teraflowbridge "$IMAGE_NAME:$IMAGE_TAG"
- docker ps -a
- sleep 5
- docker ps -a
- docker logs $IMAGE_NAME
- docker exec -i $IMAGE_NAME bash -c "pytest --log-level=DEBUG --verbose $IMAGE_NAME/tests/test_unitary.py"
after_script:
- docker stop $IMAGE_NAME
- docker rm $IMAGE_NAME
rules:
- changes:
- src/$IMAGE_NAME/**
- .gitlab-ci.yml
# Deployment of the service in Kubernetes Cluster
deploy compute:
stage: deploy
needs:
- build compute
- unit_test compute
- dependencies all
- integ_test execute
script:
- kubectl version
- kubectl get all
- kubectl apply -f "manifests/computeservice.yaml"
- kubectl delete pods --selector app=computeservice
- kubectl get all