CodeX
Published in

CodeX

A Boilerplate to Self-Hosted Continuous Delivery Django Apps (Part-2)

Django, Docker, GitHub Actions, Workflow, Self-Hosting, Custom Runner

Photo by Yancy Min on Unsplash

GitHub Actions

Self-hosted CD Workflow

cd.yml

name: Baysan Continuous Deliveryon:
push:
branches: [ "main" ]
jobs:
deploy:
runs-on: self-hosted
steps:
- uses: actions/checkout@v3

- name: Build Updated Docker Compose Environment
run: docker-compose build
- name: Stop Old Docker Compose Environment
run: docker-compose down
- name: Run Updated Docker Compose Environment
run: docker-compose up -d
- name: Remove Unused Docker Compose Environment
run: |
docker container prune -f
docker image prune -f
  • Execute this workflow when something is pushed on main branch.
  • Define a job as deploy
  • The job will run on self-hosted server
  • Get the last version of the code by using actions/checkout@v3
  • On the server, execute docker-compose build
  • On the server, execute docker-compose down
  • On the server, execute docker-compose up -d
  • On the server, execute docker container prune -f && docker image prune -f

Creating Runner

export RUNNER_ALLOW_RUNASROOT=1
./svc.sh install
./svc.sh start
./svc.sh status
./svc.sh uninstall
We see all of them failed because I didn’t set up a runner for this boilerplate repo

Finally

--

--

Everything connected with Tech & Code. Follow to join our 1M+ monthly readers

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Baysan

Lifelong learner & Freelancer. I use technology that helps me. I’m currently working as a Business Intelligence & Backend Developer. mebaysan.com