forked from ArmanCreativeSolutions/django-challenge
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from osmanmakhtoom/feat/ci-cd
Feat/ci cd
- Loading branch information
Showing
3 changed files
with
209 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
name: Deployment | ||
|
||
on: | ||
push: | ||
branches: ["main"] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout the source code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Install SSH KEY | ||
uses: shimataro/ssh-key-action@v2 | ||
with: | ||
key: ${{ secrets.SSH_PRIVATE_KEY }} | ||
known_hosts: unneccesarry | ||
|
||
- name: Adding known_hosts | ||
run: ssh-keyscan -p ${{ secrets.SSH_PORT }} -H ${{ secrets.SSH_HOST }} >> ~/.ssh/known_hosts | ||
|
||
|
||
- name: Deploy with rsync | ||
run: rsync -avz -e "ssh -p ${{ secrets.SSH_PORT }}" . ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }}:/var/www/ | ||
|
||
- name: executing remote ssh commands using password | ||
uses: appleboy/[email protected] | ||
with: | ||
host: ${{ secrets.SSH_HOST }} | ||
username: ${{ secrets.SSH_USER }} | ||
key: ${{ secrets.SSH_PRIVATE_KEY }} | ||
port: ${{ secrets.SSH_PORT }} | ||
script: | | ||
cd /var/www/ | ||
make docker-restart |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
name: Testing CI | ||
|
||
on: | ||
push: | ||
branches: ["testing"] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout the source code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Make envfile | ||
uses: SpicyPizza/[email protected] | ||
with: | ||
envkey_DEBUG: true | ||
envkey_CELERY_BROKER: ${{ secrets.CELERY_BROKER }} | ||
envkey_CELERY_BACKEND: ${{ secrets.CELERY_BACKEND }} | ||
envkey_CORS_ALLOW_ALL_ORIGINS: true | ||
envkey_CORS_ALLOWED_ORIGIN: ${{ secrets.CORS_ALLOWED_ORIGIN }} | ||
envkey_DJANGO_SETTINGS_MODULE: "apps.core.settings" | ||
envkey_SECRET_KEY: ${{ secrets.SECRET_KEY }} | ||
envkey_DJANGO_ALLOWED_HOSTS: ${{ secrets.DJANGO_ALLOWED_HOSTS }} | ||
envkey_DATABASE_URL: ${{ secrets.DATABASE_URL }} | ||
envkey_CACHE_URL: ${{ secrets.CACHE_URL }} | ||
envkey_POSTGRES_DB: ${{ secrets.POSTGRES_DB }} | ||
envkey_POSTGRES_USER: ${{ secrets.POSTGRES_USER }} | ||
envkey_POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }} | ||
envkey_RABBITMQ_DEFAULT_USER: ${{ secrets.RABBITMQ_DEFAULT_USER }} | ||
envkey_RABBITMQ_DEFAULT_PASS: ${{ secrets.RABBITMQ_DEFAULT_PASS }} | ||
envkey_RABBITMQ_DEFAULT_VHOST: ${{ secrets.RABBITMQ_DEFAULT_VHOST }} | ||
envkey_SMS_PHONE_NUMBER: ${{ secrets.SMS_PHONE_NUMBER }} | ||
envkey_SMS_CLIENT_ID: ${{ secrets.SMS_CLIENT_ID }} | ||
envkey_ENV: ${{ secrets.ENV }} | ||
directory: . | ||
file_name: .env | ||
fail_on_empty: false | ||
sort_keys: false | ||
|
||
- name: Run Project and Tests | ||
run: | | ||
make docker-up | ||
make docker-lint | ||
make docker-test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
# Makefile | ||
|
||
# Variables | ||
PROJECT_NAME = arman | ||
PYTHON = python3 | ||
PIP = pip3 | ||
DJANGO_MANAGE = $(PYTHON) backend/manage.py | ||
DOCKER_COMPOSE = docker compose | ||
|
||
# Default environment file | ||
ENV_FILE = .env | ||
|
||
# Help command to display available tasks | ||
.PHONY: help | ||
help: | ||
@echo "Available commands:" | ||
@echo " make setup - Set up the project environment" | ||
@echo " make run - Run the Django development server" | ||
@echo " make migrate - Apply database migrations" | ||
@echo " make superuser - Create a Django superuser" | ||
@echo " make test - Run tests" | ||
@echo " make lint - Lint the codebase" | ||
@echo " make clean - Clean up project artifacts" | ||
@echo " make docker-up - Start Docker services" | ||
@echo " make docker-down - Stop Docker services" | ||
@echo " make docker-restart - Restart all Docker services" | ||
@echo " make docker-logs - View logs for all Docker services" | ||
@echo " make docker-migrate - Run Docker Django migrations" | ||
@echo " make docker-superuser - Create Docker Django superuser" | ||
@echo " make docker-lint - Run Docker Django linter" | ||
@echo " make docker-test - Run Docker Django tests" | ||
|
||
# Set up the project environment | ||
.PHONY: setup | ||
setup: | ||
@echo "Setting up the project environment..." | ||
$(PIP) install -r backend/requirements.txt | ||
$(DJANGO_MANAGE) migrate | ||
$(DJANGO_MANAGE) collectstatic --noinput | ||
|
||
# Run the Django development server | ||
.PHONY: run | ||
run: | ||
@echo "Starting the Django development server..." | ||
$(DJANGO_MANAGE) runserver 0.0.0.0:8000 | ||
|
||
# Apply migrations | ||
.PHONY: migrate | ||
migrate: | ||
@echo "Applying migrations..." | ||
$(DJANGO_MANAGE) migrate | ||
|
||
# Create a Django superuser | ||
.PHONY: superuser | ||
superuser: | ||
@echo "Creating a Django superuser..." | ||
$(DJANGO_MANAGE) createsuperuser | ||
|
||
# Run tests | ||
.PHONY: test | ||
test: | ||
@echo "Running tests..." | ||
$(DJANGO_MANAGE) test | ||
|
||
# Lint the codebase | ||
.PHONY: lint | ||
lint: | ||
@echo "Running linter..." | ||
ruff format | ||
ruff check --fix | ||
|
||
# Clean up the project directory | ||
.PHONY: clean | ||
clean: | ||
@echo "Cleaning up project artifacts..." | ||
find . -name '*.pyc' -delete | ||
find . -name '__pycache__' -delete | ||
|
||
# Run initial database setup (optional) | ||
.PHONY: initdb | ||
initdb: | ||
@echo "Initializing the database..." | ||
$(DJANGO_MANAGE) makemigrations | ||
$(DJANGO_MANAGE) migrate | ||
|
||
# ---- Docker commands ---- | ||
|
||
# Start Docker services | ||
.PHONY: docker-up | ||
docker-up: | ||
@echo "Starting Docker services..." | ||
$(DOCKER_COMPOSE) up --build -d | ||
|
||
# Stop Docker services | ||
.PHONY: docker-down | ||
docker-down: | ||
@echo "Stopping Docker services..." | ||
$(DOCKER_COMPOSE) down --remove-orphans | ||
|
||
# Restart all services | ||
.PHONY: docker-restart | ||
docker-restart: | ||
$(DOCKER_COMPOSE) down && $(DOCKER_COMPOSE) up -d | ||
|
||
# View logs | ||
.PHONY: docker-logs | ||
docker-logs: | ||
$(DOCKER_COMPOSE) logs -f | ||
|
||
# Apply migrations | ||
.PHONY: docker-migrate | ||
docker-migrate: | ||
$(DOCKER_COMPOSE) exec backend python manage.py migrate | ||
|
||
# Create superuser | ||
.PHONY: docker-superuser | ||
docker-superuser: | ||
$(DOCKER_COMPOSE) exec backend python manage.py createsuperuser | ||
|
||
# Run linter | ||
.PHONY: docker-lint | ||
docker-lint: | ||
$(DOCKER_COMPOSE) exec backend ruff format && $(DOCKER_COMPOSE) exec backend ruff check --fix | ||
|
||
# Run tests | ||
.PHONY: docker-test | ||
docker-test: | ||
$(DOCKER_COMPOSE) exec backend python manage.py test |