Skip to content

aditi-agarwal-tw/ci-workshop-app

 
 

Repository files navigation

Continuous Intelligence Workshop

A demo on how to apply continuous delivery principles to train, test and deploy ML models.

Workshop pre-requisites

Before the workshop, please ensure you have done the following:

Setup

  1. Fork repository: https://github.com/davified/ci-workshop-app
  2. Clone repository: git clone https://github.com/YOUR_USERNAME/ci-workshop-app
  3. For mac users: run bin/setup.sh
  4. Start Docker on your desktop
  5. Edit the Dockerfile and replace <your username> and <your email> with your github username and email
  6. Build docker image:
  • Mac / Linux users: docker build . -t ai-sg-workshop
  • Windows users: docker build . -f Dockerfile.windows -t ai-sg-workshop
  1. Now you're ready to run some commands!
  • Start interactive shell in container: docker run -it -v $(pwd):/home/ci-workshop-app -p 8080:8080 ai-sg-workshop bash
  • Run any of the following commands in the docker container:
    • Run tests: python -m unittest discover -s src/
    • Train model: python src/train.py
    • Start application: bin/start_server.sh

Note: Windows users have to add: --platform linux after docker run (e.g. docker run --platform linux -it -v $(pwd):/home/ci-workshop-app -p 8080:8080 ai-sg-workshop bash)

  1. Some other docker commands that you may find useful
  • Start a bash shell in a running container when it’s running: docker exec -it <container-id> /bin/bash (you can find the container id by running docker ps)
  1. We'll be doing most of our coding in the interactive shell. Anything that you used to do in your bash shell, you can also do in the interactive shell of the container. For example:
# hello world
$ echo "hello world!"

# train model: 
$ python src/train.py

# start flask app
$ python src/app.py

To deploy your changes, just git commit and git push! The CI pipeline (specified in .circleci/config.yml) will do everything (train, test, deploy) for you.

RUN git config --global user.name ''
&& git config --global user.email ''
&& git config --global credential.helper cache

One-time steps for deployment

CircleCI

Heroku

  • Login to heroku by running: heroku login
  • Create a heroku project for app (staging): heroku create ci-workshop-app-<YOUR_NAME>-staging
  • Create a heroku project for app (prod): heroku create ci-workshop-app-<YOUR_NAME>-prod
  • In .circleci/config.yml, replace ci-workshop-app-bob-staging and ci-workshop-app-bob-prod with the names of your staging and prod apps
  • Generate a heroku auth token and copy the 'Token' value : heroku authorizations:create
  • On CircleCI webpage, go to your project settings (click on the gear icon on your project) and click on 'Environment Variables' on the left panel. Add the following variable:
    • Name: HEROKU_AUTH_TOKEN
    • Value: (paste value created from previous step)

GCP App Engine

Note: Deploying to GCP App Engine takes much longer because (i) gcloud app deploy just takes that long (5+ minutes), (ii) we need to build a docker image of our application and that takes time (5+ minutes). If you don't want to run the following example, you can still checkout the CircleCI config and sample build log

Steps for deploying to GCP App Engine:

  • Get secret key from GCP console (follow steps 1-3 of instructions)
  • Define environment variable in CircleCI
    • GCLOUD_SERVICE_KEY: (copy and paste contents of secret key)
  • If deploying to app engine for the first time, enable App Engine Admin API on GCP

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 64.2%
  • Shell 24.8%
  • Dockerfile 11.0%