Commit d6df3edb authored by Sergio Gonzalez Diaz's avatar Sergio Gonzalez Diaz
Browse files

Add global .gitlab-ci.yml and monitoring .gitlab-ci.yml

parent 29231f0d
Loading
Loading
Loading
Loading

.gitlab-ci.yml

0 → 100644
+11 −0
Original line number Diff line number Diff line
# stages of the cicd pipeline
stages:
  - build
  - test
#  - deploy

# include the individual .gitlab-ci.yml of each micro-service
include: 
  - local: '/src/monitoring/.gitlab-ci.yml'
#  - local: '/src/context/.gitlab-ci.yml'
+72 −0
Original line number Diff line number Diff line
variables:
  IMAGE_NAME: 'monitoring' # name of the microservice
  IMAGE_TAG: 'latest' # tag of the container image (production, development, etc)

# build the Docker image
build monitoring:
  stage: build
  script:
    - docker build -t "$IMAGE_NAME:$IMAGE_TAG" -f ./src/$IMAGE_NAME/Dockerfile ./src/
  rules:
    - changes:
      - src/$IMAGE_NAME/**
      - .gitlab-ci.yml

# tags the Docker image
tag monitoring:
  stage: build
  script:
    - docker tag "$IMAGE_NAME:$IMAGE_TAG" "$CI_REGISTRY_IMAGE/$IMAGE_NAME:$IMAGE_TAG"
  rules:
    - changes:
      - src/$IMAGE_NAME/**
      - .gitlab-ci.yml

# push the Docker image to the gitlab Docker registry
push monitoring:
  stage: build
  before_script:
    - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
  script:
    - docker push "$CI_REGISTRY_IMAGE/$IMAGE_NAME:$IMAGE_TAG"
  rules:
    - changes:
      - src/$IMAGE_NAME/**
      - .gitlab-ci.yml

# test if the Docker image can be pulled from the gitlab registry
test monitoring pull:
  stage: test
  needs:
    - push monitoring
  before_script:
    - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
  script:
    - docker pull "$CI_REGISTRY_IMAGE/$IMAGE_NAME:$IMAGE_TAG"
  rules:
    - changes:
      - src/$IMAGE_NAME/**
      - .gitlab-ci.yml

# test if the Docker image can be executed
test monitoring run:
  stage: test
  needs:
    - build monitoring
  script:
    - docker network create -d bridge teraflowbridge
    - docker run -d -p 7070:7070 --name monitoring --network=teraflowbridge --rm "$IMAGE_NAME:$IMAGE_TAG"
    - sleep 5
    - docker ps | grep monitoring > deploy_test_report.txt
  after_script:
    - docker stop monitoring
    - docker network rm teraflowbridge
  rules:
    - changes:
      - src/$IMAGE_NAME/**
      - .gitlab-ci.yml
  artifacts:
    when: always
    paths:
      - deploy_test_report.txt
    expire_in: 1 day
 No newline at end of file