This repository deploy a Python application ,including python code contained in index.py . The application is a simple, “Present BTC in USD” app that uses Flask, a small HTTP server for Python apps.
In this module we:
- Present the Current Bitcoin Price in USD.
- Present the Average Price for the last 10 minutes.
We get the data from This Website
FROM python:alpine3.7
COPY . /app
WORKDIR /app
RUN pip install -r requirements.txt
EXPOSE 5000
CMD python ./index.py
telling Docker what base image to use for the container, and implicitly selecting the Python version to use, which in this case is 3.7.
moves the application into the container image.
sets the working directory
calling pip and pointing to the requirements.txt file.
exposes a port that is used by Flask.
tells the container what to execute to start the application. In this case, it is telling Python to run index.py.
This file contains a list of the dependencies that the application needs to run.
- Install Docker
sudo apt install docker.io -y
- Clone the Repository
- build the image by running Docker build from a command line or terminal that is in the root directory of the application.
- After it is built, you can run the image as a container.
Commands:
git clone 'https://github.com/assiakhateeb/btcApp.git'
cd btcApp
docker build --tag my-python-app .
docker run --name python-app -p 5000:5000 my-python-app
After it starts, you should be able to access the application with the url http://localhost:5000/
We create a Jenkinsfile for CI/CD that creates and pushes the generated Docker image to Docker Hub.
1. Go to Jenkins homepage, click on “New Item”, select “Pipeline” and enter the job name as “docker-python-app”.
In this pipeline, We have 2 environment variables to change the registry and the credential easily.
The third environment is to save docker image informations.
registry = "assiakhateeb/btc_app"
registryCredential = 'dockerhub'
dockerImage = ''
}
Docker build command:
docker.build registry + ":$BUILD_NUMBER"
Deploying the docker image to dockerhub:
docker.withRegistry( '', registryCredential ) {
dockerImage.push()
After build and deploy, delete the image to cleanup your server space.
sh "docker rmi $registry:$BUILD_NUMBER"