Skip to content

Commit

Permalink
Merge branch 'milestone6' into main for final submission
Browse files Browse the repository at this point in the history
  • Loading branch information
bfulroth committed Dec 13, 2023
2 parents 19d3e1c + 664b83b commit a275e4b
Show file tree
Hide file tree
Showing 67 changed files with 6,444 additions and 238 deletions.
33 changes: 19 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,17 @@
- Russell Brown, [[email protected]]([email protected])

### Presentation Video
* \<Link Here>
* [Youtube Presentation](https://youtu.be/7q6euZdu2UE)

### Blog Post Link
* \<Link Here>
* [Medium Draft Post](https://medium.com/institute-for-applied-computational-science/snapnutrition-bridging-the-gap-between-technology-and-dietary-well-being-dbd6fc5ffc1c)
---

### Project Organization


![](reports/final_project_directory_structure.png)

# AC215 - Final Project

**Group Name:** SnapNutrition
Expand All @@ -24,7 +29,7 @@ In this project we aim to develop an application that can estimate calories and

## Data Description

PLACE_HOLDER: Need to fill out...
We conducted a thorough review of literature, open-source projects, and datasets. The dataset that we decided as team to use for this project was published by a Google Research Group and called [Nutrition 5K](https://github.com/google-research-datasets/Nutrition5k). The paper accompanying the dataset describes a their systematic approach to capturing and curating images, depth images, and video of entire plates of food from two cafeterias for the purpose of model training. In addition, the original dataset was composed of 180 GB, most of which was video. As video and depth images introduce additional challenges with regard to model training, we decided to scope our project to just overhead images which reduced our training dataset to 2.2 GB! This was extremely important as it allowed to to explore a more diverse set of models as well as implement hyperparameter sweeps. Each image that we used included quantified macronutrient labels for calories, fat, carbohydrates, protein, and total mass.

## Proposed Solution

Expand Down Expand Up @@ -84,7 +89,11 @@ To run the container locally:

**Deployment**

We used Ansible to create, provision, and deploy our frontend and backend to GCP in an automated fashion. Ansible helps us manage infrastructure as code and this is very useful to keep track of our app infrastructure as code in GitHub. It helps use setup deployments in a very automated way.
We used Ansible to create, provision, and deploy our frontend and backend to GCP in an automated fashion. Ansible helps us manage infrastructure as code and this is very useful to keep track of our app infrastructure as code in GitHub. It also helps us set up deployments in a very automated way. In addition to Ansible, we use a kubernetes cluster to take care of load balancing and failover.

Here is an example of 2 nodes from our k8 cluster running:

<img src="reports/k8cluster_nodes.png" width="800"><br>

To run the container locally:
- Open a terminal and go to the location where `app/src/deployment`
Expand All @@ -99,15 +108,17 @@ ansible-playbook deploy-docker-images.yml -i inventory.yml
ansible-playbook deploy-k8s-cluster.yml -i inventory.yml --extra-vars cluster_state=present
```

[For more details on running this container click here.](app/src/deployment/README.md)
- View the App
* Copy the `nginx_ingress_ip` from the terminal from the create cluster command
* Go to `http://<YOUR INGRESS IP>.sslip.io`

PLACE_HOLDER: How do we view the app???
[For more details on running this container click here.](app/src/deployment/README.md)

### Deploy using GitHub Actions

Finally we added CI/CD using GitHub Actions, such that we can trigger deployment or any other pipeline using GitHub Events. Our yaml files can be found under `.github/workflows`

`cicdworkflow.yml` - Brief description here
`k8s_deploy.yml` - Brief description here

We implemented a CI/CD workflow to use the deployment container to
* Invoke docker image building and pushing to GCR on code changes
Expand Down Expand Up @@ -219,10 +230,4 @@ We built the following containers for our project:
- Uses Ansible and Kubernetes to manage:
- Frontend and API Service registration on Google Container Registry (GCR)
- Creating and Provisioning nodes (Virtual Machines) with our frontend and backend API service.
- [Full Details Here](app/src/deployment/README.md)

## NOTE

**DO NOT KEEP YOUR GCP INSTANCES RUNNING**

Once you are done with taking screenshots for the milestone bring them down.
- [Full Details Here](app/src/deployment/README.md)
187 changes: 0 additions & 187 deletions README_Template.md

This file was deleted.

35 changes: 0 additions & 35 deletions app/src/deployment/deploy-k8s-tic-tac-toe.yml

This file was deleted.

1 change: 0 additions & 1 deletion app/src/model-deployment
Submodule model-deployment deleted from ccd658
6 changes: 6 additions & 0 deletions app/src/model-deployment/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# misc
.DS_Store
/docker-volumes
trainer.tar.gz
/artifacts
/wandb
54 changes: 54 additions & 0 deletions app/src/model-deployment/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Use the official Debian-hosted Python image
FROM python:3.9-slim-buster

ARG DEBIAN_PACKAGES="build-essential git curl wget unzip gzip"

# Prevent apt from showing prompts
ENV DEBIAN_FRONTEND=noninteractive

# Python wants UTF-8 locale
ENV LANG=C.UTF-8

# Tell pipenv where the shell is. This allows us to use "pipenv shell" as a
# container entry point.
ENV PYENV_SHELL=/bin/bash

# Tell Python to disable buffering so we don't lose any logs.
ENV PYTHONUNBUFFERED=1

# Ensure we have an up to date baseline, install dependencies and
# create a user so we don't run the app as root
RUN set -ex; \
for i in $(seq 1 8); do mkdir -p "/usr/share/man/man${i}"; done && \
apt-get update && \
apt-get upgrade -y && \
apt-get install -y --no-install-recommends $DEBIAN_PACKAGES && \
apt-get install -y --no-install-recommends software-properties-common apt-transport-https ca-certificates gnupg2 gnupg-agent curl openssh-client && \
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add - && \
echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] https://packages.cloud.google.com/apt cloud-sdk main" | tee -a /etc/apt/sources.list.d/google-cloud-sdk.list && \
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key --keyring /usr/share/keyrings/cloud.google.gpg add - && \
apt-get update && \
apt-get install -y --no-install-recommends google-cloud-sdk && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* && \
pip install --no-cache-dir --upgrade pip && \
pip install pipenv && \
useradd -ms /bin/bash app -d /home/app -u 1000 -p "$(openssl passwd -1 Passw0rd)" && \
mkdir -p /app && \
chown app:app /app

# Switch to the new user
USER app
WORKDIR /app

# Install python packages
ADD --chown=app:app Pipfile Pipfile.lock /app/

RUN pipenv sync

# Add the rest of the source code. This is done last so we don't invalidate all
# layers when we change a line of code.
ADD --chown=app:app . /app

# Entry point
ENTRYPOINT ["/bin/bash","./docker-entrypoint.sh"]
21 changes: 21 additions & 0 deletions app/src/model-deployment/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 DLOps

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Loading

0 comments on commit a275e4b

Please sign in to comment.