Coder Social home page Coder Social logo

books's Introduction

books

A sample CI/CD pipeline for a Django application (books), using Docker, Github Actions, ArgoCD and Helm.

Setup

Requirements

Local Configuration and Deployment

  • Create a k8s cluster
    • k3d cluster create dev-cluster -a 2
  • Install ArgoCD and configure it with the Github repository, create the argocd namespace first
    • kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml
  • Create a namespace for the application, and add a secret to hold the ghrc credentials
    • kubectl create -n books secret docker-registry ghcr-secret --docker-username hilyas --docker-password $CR_PAT --docker-server ghcr.io, where $CR_PAT is the Github Personal Access Token.
  • Configure the helm chart to pull the images from the ghrc, using the secret created above
  • Create the app in ArgoCD and sync it
    • argocd app create books --repo https://github.com/hilyas/books.git --path helm/books --values values.dev.yaml --dest-server https://kubernetes.default.svc --dest-namespace books --sync-policy automated --auto-prune --self-heal
  • Port forward the ArgoCD server to access the UI
    • kubectl port-forward svc/argocd-server -n argocd 8080:443
  • Port forward the books service to access the application
    • kubectl port-forward svc/books -n books 8000:8000

To obtain the admin password for the ArgoCD UI run:

  • kubectl -n argocd get secret argocd-initial-admin-secret -o jsonpath="{.data.password}" | base64 -d && echo

Local dev uses a k3s cluster, with ArgoCD (installed in the argocd namespace) for deployment. Github actions uses the GITHUB_TOKEN to authenticate with the Github container registry and push images to it. A Github Personal Access Token (PAT) is used to authenticate with ArgoCD to pull the images and deploy the application.

After every commit to the main branch, the application is automatically deployed to the dev cluster, using ArgoCD. ArgoCD deploys the application to the dev cluster, in the books namespace. Docker images can be built and run locally before committing to the main branch. Useful to quickly test changes to the application.

There are many improvements that can be made but this is a good starting point, for example:

  • Considering multiple environments (dev, staging, prod)
  • Using helmfile to manage the helm releases
  • Using a develop branch and a main branch
  • Use a different database system (PostgreSQL, MySQL, etc)

Note: the apps directory contains Django code only, without helm configuration. The helm directory contains the helm charts for the various Django apps in the repo. This can be changed to have a single helm chart for the whole application, or a helm chart for each Django app, or a helm chart for each Django app and a helm chart for the whole application.

books's People

Contributors

hilyas avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.