Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
9bfbaa7
modified
baylon-obinna Aug 8, 2024
40f1ed9
DOCKERFILES
baylon-obinna Aug 13, 2024
cf5bd32
modified dockerfile
baylon-obinna Aug 15, 2024
2e95ff2
containerized
baylon-obinna Aug 19, 2024
61211b4
k8s manifests update
baylon-obinna Aug 19, 2024
3c7695e
modified: k8s/manifests/redis/deployment.yml
baylon-obinna Aug 20, 2024
5be8fa5
modified
baylon-obinna Aug 21, 2024
ec920aa
modifications of some files
baylon-obinna Sep 2, 2024
cc0e174
added a logging to catch errors when populating data
baylon-obinna Sep 3, 2024
2ec67cd
changes
baylon-obinna Sep 5, 2024
16fb350
changes
baylon-obinna Sep 5, 2024
8dbe0d7
modified
baylon-obinna Sep 6, 2024
98d41cf
modified
baylon-obinna Sep 7, 2024
aa2ef36
updated readme, compose and app.py files
baylon-obinna Sep 7, 2024
437fa93
modified and renamed
baylon-obinna Sep 10, 2024
c2a066c
redis_host modifications
baylon-obinna Sep 11, 2024
004ce32
helm charts setup
baylon-obinna Sep 12, 2024
e1c7ac5
integratd github workflows
baylon-obinna Sep 16, 2024
ece48cf
fixing greenlet issues
baylon-obinna Sep 16, 2024
8d86ae1
fixing greenlet installation
baylon-obinna Sep 16, 2024
60f87d1
upgraded from autopep8==1.5.4 to 1.5.7
baylon-obinna Sep 16, 2024
c3ab680
dependencies issues
baylon-obinna Sep 16, 2024
80d989a
dependencies :wrapt == 1.14.7 to 1.16.0
baylon-obinna Sep 16, 2024
f33e63e
dependcy pycodestyle==2.6.0 t0 2.7.0
baylon-obinna Sep 16, 2024
40e9ffd
dependency autopep8==1.5.4 to 1.5.6
baylon-obinna Sep 16, 2024
ad7c057
setup a redis server for pipeline
baylon-obinna Sep 16, 2024
935a333
fixed AUTH issues with redis connection
baylon-obinna Sep 16, 2024
634093b
redis modification
baylon-obinna Sep 16, 2024
43ad13c
removed --test in python app start up
baylon-obinna Sep 16, 2024
f38cbf1
added a tests directory
baylon-obinna Sep 17, 2024
4221e9d
edited pipeline to build packages not run them
baylon-obinna Sep 17, 2024
3e56b53
added a lint script for frontend code analysis
baylon-obinna Sep 17, 2024
8b1c4e0
fixed eslint errors
baylon-obinna Sep 17, 2024
a178300
fixed .flake8 issues
baylon-obinna Sep 17, 2024
ad9ee0e
fixed docker errors
baylon-obinna Sep 17, 2024
06b6a4a
buildx formatting
baylon-obinna Sep 17, 2024
28727d5
fixing buildx errors
baylon-obinna Sep 17, 2024
6478f7d
fixed dockerfile error for backend
baylon-obinna Sep 17, 2024
fcbfc6e
upgraded pip
baylon-obinna Sep 18, 2024
a666926
upgraded to python 3.8 slim
baylon-obinna Sep 18, 2024
070641c
updated formatting for ENV and synthax error in pipeline
baylon-obinna Sep 18, 2024
94a3b72
added a stage to update helm charts on github
baylon-obinna Sep 19, 2024
b8cb18a
updated path to helms values.yaml
baylon-obinna Sep 19, 2024
845b9cd
path error fixed
baylon-obinna Sep 19, 2024
844d825
added username and user email
baylon-obinna Sep 19, 2024
e021319
Update image tag to 10936501657
baylon-obinna Sep 19, 2024
4dd687d
Update values.yaml
baylon-obinna Sep 19, 2024
a8cd4fa
updated workflows to run only on prod branch
baylon-obinna Sep 26, 2024
3f54a03
added a readme-DevOps.md
baylon-obinna Oct 7, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ ignore =
F401,
F403,
F405,
E402,
max-line-length = 120
162 changes: 162 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
name: CI/CD Pipeline

on:
push:
branches:
- prod
paths-ignore:
- 'README.md'
- 'K8s/**'
- 'helm/**'

jobs:
# Build frontend and backend
build:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

# Build frontend
- name: Setup Node.js for frontend
uses: actions/setup-node@v2
with:
node-version: 16

- name: Cache node modules
uses: actions/cache@v2
env:
cache-name: cache-node-modules
with:
path: '**/node_modules'
key: ${{ runner.os }}-modules-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-modules-

- name: Install frontend dependencies
run: |
npm update
npm install --prefix ./client

- name: Build frontend
run: npm run build --prefix ./client

# Build backend
- name: Setup Python for backend
uses: actions/setup-python@v2
with:
python-version: '3.8'

- name: Cache pip packages
uses: actions/cache@v2
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-

# Install system dependencies
- name: Install system dependencies for Python
run: |
sudo apt-get update
sudo apt-get install -y python3-dev libffi-dev build-essential

# Install Python dependencies with only-binary option
- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
pip install --only-binary :all: -r requirements.txt

- name: Check for dependency issues
run: pip check

# Static Code Analysis
static_analysis:
runs-on: ubuntu-latest
needs: build # This will only run after the build stage is successful

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: 16

- name: Install ESLint
run: |
npm install --prefix ./client
npm install eslint --prefix ./client

# Static analysis for frontend
- name: Run ESLint for frontend
run: npm run lint --prefix ./client

# Static analysis for backend
- name: Run Flake8 for backend
run: |
pip install flake8
flake8 ./app.py

# Docker image build and push with GitHub run ID tag
docker_build_push:
runs-on: ubuntu-latest
needs: static_analysis # This will only run after the static analysis is successful

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

# Build and tag frontend image with GitHub run ID
- name: Build frontend Docker image
run: |
docker buildx build -t baylon44/redis-chat-frontend:${{ github.run_id }} -f ./client/dockerfile ./client --load
docker push baylon44/redis-chat-frontend:${{ github.run_id }}

# Build and tag backend image with GitHub run ID
- name: Build backend Docker image
run: |
docker buildx build -t baylon44/redis-chat-backend:${{ github.run_id }} -f Dockerfile . --load
docker push baylon44/redis-chat-backend:${{ github.run_id }}


# update helms charts values with updated image tags and push to github
helm_update:
runs-on: ubuntu-latest
needs: docker_build_push # This will only run after the Docker image build and push is successful

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Update Helm values.yaml for frontend
run: |
sed -i '/chatfrontend:/,/tag:/s/tag:.*/tag: ${{ github.run_id }}/' ./helm/redis-chat-app/values.yaml

- name: Update Helm values.yaml for backend
run: |
sed -i '/chatbackend:/,/tag:/s/tag:.*/tag: ${{ github.run_id }}/' ./helm/redis-chat-app/values.yaml

- name: Commit and push updated values.yaml
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git config --global user.email "nwaoshop@gmail.com"
git config --global user.name "baylon-obinna"
git add ./helm/redis-chat-app/values.yaml
git commit -m "Update image tag to ${{ github.run_id }}"
git push origin master
47 changes: 35 additions & 12 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,36 @@
# Use Python37
FROM python:3.7
# Copy requirements.txt to the docker image and install packages
COPY requirements.txt /
RUN pip install -r requirements.txt
# Set the WORKDIR to be the folder
COPY . /app
# Expose port 8080
EXPOSE 8080
ENV PORT 8080
# Use Python 3.7
FROM python:3.8-slim

# Set the working directory
WORKDIR /app
# Use gunicorn as the entrypoint
CMD exec gunicorn --bind :$PORT --worker-class eventlet -w 1 app:app

# Copy requirements.txt and install packages
COPY requirements.txt .
RUN pip install --upgrade pip && pip install --no-cache-dir -r requirements.txt

# Copy the rest of the application
COPY . .

# Python startup script instead of a bash script
RUN echo 'import eventlet\n\
eventlet.monkey_patch()\n\
from chat.app import app, run_app\n\
from chat import utils\n\
import os\n\
\n\
utils.init_redis()\n\
\n\
if os.environ.get("CREATE_DEMO_DATA", "True").lower() == "true":\n\
from chat.demo_data import create\n\
create()\n\
\n\
run_app()' > /app/start.py

# Expose port 8000
EXPOSE 8000

# Set environment variable
ENV PORT=8000

# Use the Python script as the entrypoint
CMD ["python", "/app/start.py"]
53 changes: 53 additions & 0 deletions README-DevOps.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Implementing DevOps practices on the Redis chat application

The main goal of this project is to implement DevOps practices in the Redis chat application.
DevOps practices include the following:

- Creating Docker files
- Containerization
- Continuous Integration (CI)
- Continuous Deployment (CD)

Summary Diagram

![alt text](<Screenshot (199).png>)

Creating Dockerfiles
The Dockerfile is used to build a Docker image. The Docker images contains the redis chat application services frontend and backend packaged with there dependencies. The Docker images is then used to create Docker containers.

Containerization
Containerization is the process of packaging an application and its dependencies into a container. The container is then run on a container platform such as Docker. Containerization allows you to run the application in a consistent environment, regardless of the underlying infrastructure.

Docker compose is used to spin up Docker containers from the Docker file created above, with necessary configuration for each services including the Redis database

Commands to build the Docker container:

docker compose build

Command to run the Docker container:

docker compose up

Continuous Integration (CI)

Continuous Integration (CI) is the practice of automating the integration of code changes into a shared repository. CI helps to catch bugs early in the development process and ensures that the code is always in a deployable state.

We will use GitHub Actions to implement CI for the Go web application. GitHub Actions is a feature of GitHub that allows you to automate workflows, such as building, testing, and deploying code.

The GitHub Actions workflow will run the following steps:

- Checkout the code from the repository
- Build the Docker image
- Run tests
- Push the images to a docker hub repository
- Update the values of the helm charts with new image tags

Continuous Deployment (CD)

Continuous Deployment (CD) is the practice of automatically deploying code changes to a production environment. CD helps to reduce the time between code changes and deployment, allowing you to deliver new features and fixes to users faster.

We will use Argo CD to implement CD for the Redis chat application. Argo CD is a declarative, GitOps continuous delivery tool for Kubernetes. It allows you to deploy applications to Kubernetes clusters using Git as the source of truth.

The Argo CD application will deploy the Go web application to a Kubernetes cluster. The application will be automatically synced with the Git repository, ensuring that the application is always up to date.

https://medium.com/@nwaoshop/implementing-ci-cd-on-a-redis-opensource-project-358d9a19cb9f
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -260,12 +260,19 @@ sess.init_app(app)

- REDIS_ENDPOINT_URI: Redis server URI
- REDIS_PASSWORD: Password to the server
- REDIS_USER: User to connect #redisuser

#### Run frontend

```sh
cd client
yarn install
nvm install 16
nvm use 16
npm update
npm install
npm run start
--
yarn install #production
yarn start
```

Expand All @@ -274,6 +281,7 @@ yarn start
Run with venv:

```sh
install requirements.txt {pip install -r requirements.txt} # for some you have to these packages after {pip install flask flask_cors flask_session flask_socketio bcrypt redis eventlent}
python app.py
```

Expand Down
Binary file added Screenshot (199).png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 13 additions & 5 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
from chat.app import app, run_app # noqa
import eventlet
import logging
import os

eventlet.monkey_patch()

# Set up logging
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')

from chat.app import app, run_app # noqa
from chat import utils

if __name__ == "__main__":
# monkey patch is "required to force the message queue package to use coroutine friendly functions and classes"
# check flask-socketio docs https://flask-socketio.readthedocs.io/en/latest/
import eventlet
logging.info("Starting application in local development mode")

utils.init_redis()

eventlet.monkey_patch()
run_app()
Loading