MLops for beginners

Day19: Getting started with S2I (Source to Image)

What is S2I? Why you need it? How can you use it to leverage the power of complete devops life-cycle?

flask-repo
|-- run.py
|-- sampleapp/
|-- __init__.py
|-- views.py
flask-repo
|-- run.py
|-- sampleapp/
|-- __init__.py
|-- views.py
|-- .s2i # new folder
|-- environment # new file

Steps

sudo dnf config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.reposudo dnf install docker-ce-3:18.09.1-3.el7 -ysudo systemctl start docker
sudo yum install unzip git wget -ywget https://github.com/openshift/source-to-image/releases/download/v1.3.0/source-to-image-v1.3.0-eed2850f-linux-amd64.tar.gztar xvf source-to-image-v1.3.0-eed2850f-linux-amd64.tar.gz
sudo cp s2i /usr/local/bin/    or (You can do both if you are not sure)sudo cp s2i /usr/bin
# This will download the source code from github and use 
# "centos/python-36-centos7" as the base image and will finally
# give you a "voiceaim-website" docker image.
sudo s2i build https://github.com/ayedaemon/VoiceAIM-website centos/python-36-centos7 voiceaim-website
# Here you run the image to create a new container and check it
sudo docker run -p 80:80 voiceaim-website
from centos:latestrun yum install wget -y# Installs jenkinsrun wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo
run rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key
run yum install java-11-openjdk jenkins -y
## Installs Docker
add docker.repo /etc/yum.repos.d/
run yum install docker-ce containerd.io git -y --nobest
run yum install unzip git wget -y
## download and install s2irun wget https://github.com/openshift/source-to-image/releases/download/v1.3.0/source-to-image-v1.3.0-eed2850f-linux-amd64.tar.gzrun tar xvf source-to-image-v1.3.0-eed2850f-linux-amd64.tar.gz
run cp s2i /usr/local/bin/
run cp s2i /usr/bin
# starts jenkins
expose 8080
entrypoint ["java"]
cmd ["-jar", "/usr/lib/jenkins/jenkins.war", "--httpPort=8080"]
docker pull ayedaemon/s2ijenkins:1
sudo docker run -d -p 8080:8080 ayedaemon/s2ijenkins:1

But why would I ever do this?? Why we need S2I with jenkins in a container?

sudo docker run -d -p 8080:8080 -v /var/run/docker.sock:/var/run/docker.sock — name s2ijenk ayedaemon/s2ijenkins:1
mkdir -p /dockerfiless2i build . centos/python-36-centos7 ayedaemon/voiceaim_website --as-dockerfile /dockerfiles/Dockerfile
add the path to the dockerfile too (check in advance section)

Connecting the dots and rest is magic. https://ayedaemon.github.io/