Gitlab CI commands for TF serving

Gitlab CI commands for TF serving

This is an example .gitlab-ci.yml file which can be used to containerize and deploy a tensorflow model

stages:
  - containerize
  - deploy

variables:
  SERVING_CONTAINER: serving_base
  DOCKER_IMAGE: 192.168.1.2:5000/redblack
  AI_MODEL: redblack
  DEPLOYMENT: redblack

containerization:
  stage: containerize
  script:
    # Run an empty tensorflow serving container
    - docker run -d --name ${SERVING_CONTAINER} tensorflow/serving
    # Copy the model into the serving container and save it as a new image
    - docker cp ./${AI_MODEL} ${SERVING_CONTAINER}:/models/${AI_MODEL}
    - docker commit --change "ENV MODEL_NAME ${AI_MODEL}" serving_base ${DOCKER_IMAGE}
    # Push the container to the registry
    - docker push ${DOCKER_IMAGE}
    # Cleanup
    - docker stop ${SERVING_CONTAINER}
    - docker container rm ${SERVING_CONTAINER}
    - docker image rm ${DOCKER_IMAGE}

deployment:
  stage: deploy
  script:
    - kubectl apply -f deployment.yml
    - kubectl rollout restart deployment/${DEPLOYMENT}
  environment:
    name: staging