Commit 225176fc authored by Javier Moreno's avatar Javier Moreno
Browse files

Merge branch 'feat/gitlab-ci' into 'develop'

Merge Request Feat/gitlab ci into develop

See merge request teraflow-h2020/controller!2
parents da7f7f87 efc96d99
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'
+71 −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
  before_script:
    - if docker network list | grep teraflowbridge; then echo "teraflowbridge is already created"; else docker network create -d bridge teraflowbridge; fi  
  script:
    - docker run -d -p 7070:7070 --name monitoring --network=teraflowbridge --rm "$IMAGE_NAME:$IMAGE_TAG"
    - docker ps > deploy_test_report.txt
  after_script:
    - docker stop monitoring
  rules:
    - changes:
      - src/$IMAGE_NAME/**
      - .gitlab-ci.yml
  artifacts:
    when: always
    paths:
      - deploy_test_report.txt
    expire_in: 1 day