Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ci #20

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
90 changes: 0 additions & 90 deletions .github/main.yml

This file was deleted.

89 changes: 89 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
name: Continuous Integration and Delivery

on: [push]

env:
WEB_IMAGE: ghcr.io/$(echo $GITHUB_REPOSITORY | tr '[:upper:]' '[:lower:]')/web
NGINX_IMAGE: ghcr.io/$(echo $GITHUB_REPOSITORY | tr '[:upper:]' '[:lower:]')/nginx

jobs:
build:
name: Build Docker Images
runs-on: ubuntu-latest
steps:
- name: Checkout master
uses: actions/checkout@v1
- name: Add environment variables to .env
run: |
echo DEBUG=0 >> .env
echo SQL_ENGINE=django.db.backends.postgresql >> .env
echo DATABASE=postgres >> .env
echo SECRET_KEY=${{ secrets.SECRET_KEY }} >> .env
echo SQL_DATABASE=${{ secrets.SQL_DATABASE }} >> .env
echo SQL_USER=${{ secrets.SQL_USER }} >> .env
echo SQL_PASSWORD=${{ secrets.SQL_PASSWORD }} >> .env
echo SQL_HOST=${{ secrets.SQL_HOST }} >> .env
echo SQL_PORT=${{ secrets.SQL_PORT }} >> .env
- name: Set environment variables
run: |
echo "WEB_IMAGE=$(echo ${{env.WEB_IMAGE}} )" >> $GITHUB_ENV
echo "NGINX_IMAGE=$(echo ${{env.NGINX_IMAGE}} )" >> $GITHUB_ENV
- name: Log in to GitHub Packages
run: echo ${PERSONAL_ACCESS_TOKEN} | docker login ghcr.io -u ${{ secrets.NAMESPACE }} --password-stdin
env:
PERSONAL_ACCESS_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
- name: Pull images
run: |
docker pull ${{ env.WEB_IMAGE }} || true
docker pull ${{ env.NGINX_IMAGE }} || true
- name: Build images
run: |
docker-compose -f docker-compose.ci.yml build
- name: Push images
run: |
docker push ${{ env.WEB_IMAGE }}
docker push ${{ env.NGINX_IMAGE }}

deploy:
name: Deploy to DigitalOcean
runs-on: ubuntu-latest
needs: build
steps:
- name: Checkout master
uses: actions/checkout@v1
- name: Add environment variables to .env
run: |
echo DEBUG=0 >> .env
echo SQL_ENGINE=django.db.backends.postgresql >> .env
echo DATABASE=postgres >> .env
echo SECRET_KEY=${{ secrets.SECRET_KEY }} >> .env
echo SQL_DATABASE=${{ secrets.SQL_DATABASE }} >> .env
echo SQL_USER=${{ secrets.SQL_USER }} >> .env
echo SQL_PASSWORD=${{ secrets.SQL_PASSWORD }} >> .env
echo SQL_HOST=${{ secrets.SQL_HOST }} >> .env
echo SQL_PORT=${{ secrets.SQL_PORT }} >> .env
echo WEB_IMAGE=${{ env.WEB_IMAGE }} >> .env
echo NGINX_IMAGE=${{ env.NGINX_IMAGE }} >> .env
echo NAMESPACE=${{ secrets.NAMESPACE }} >> .env
echo PERSONAL_ACCESS_TOKEN=${{ secrets.PERSONAL_ACCESS_TOKEN }} >> .env
- name: Add the private SSH key to the ssh-agent
env:
SSH_AUTH_SOCK: /tmp/ssh_agent.sock
run: |
mkdir -p ~/.ssh
ssh-agent -a $SSH_AUTH_SOCK > /dev/null
ssh-keyscan github.com >> ~/.ssh/known_hosts
ssh-add - <<< "${{ secrets.PRIVATE_KEY }}"
- name: Build and deploy images on DigitalOcean
env:
SSH_AUTH_SOCK: /tmp/ssh_agent.sock
run: |
scp -o StrictHostKeyChecking=no -r ./.env ./docker-compose.prod.yml root@${{ secrets.DIGITAL_OCEAN_IP_ADDRESS }}:/app
ssh -o StrictHostKeyChecking=no root@${{ secrets.DIGITAL_OCEAN_IP_ADDRESS }} << 'ENDSSH'
cd /app
source .env
docker login ghcr.io -u $NAMESPACE -p $PERSONAL_ACCESS_TOKEN
docker pull $WEB_IMAGE
docker pull $NGINX_IMAGE
docker-compose -f docker-compose.prod.yml up -d
ENDSSH
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,23 @@ Here are the steps to install and run the project:
3. Install dependencies ...
4. Run the project ...


## Installation with Docker

Here are the steps to install and run the project:

1. Clone the repository ...
2. Checkout to "feature" branch
3. Install dependencies ...
4. Install [docker](https://docs.docker.com/engine/install/) on your machine
5. Open terminal in your project and run ...
6. `docker-compose -f docker-compose.yml up -d --build`
7. Open another terminal window and run ...
8. docker-compose -f docker-compose.yml logs -f
9. PLease find more instructions and commands in this [documentaion 1](https://testdriven.io/blog/deploying-django-to-digitalocean-with-docker-and-github-actions/)and [documentation 2](https://testdriven.io/blog/dockerizing-django-with-postgres-gunicorn-and-nginx/)

## API URL = http://137.184.113.226/

## Usage

Here's how to use the project functionalities:
Expand Down
3 changes: 2 additions & 1 deletion app/clearpath_home/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@

# 'DJANGO_ALLOWED_HOSTS' should be a single string of hosts with a space between each.
# For example: 'DJANGO_ALLOWED_HOSTS=localhost 127.0.0.1 [::1]'
ALLOWED_HOSTS = os.environ.get("DJANGO_ALLOWED_HOSTS").split(" ")
# ALLOWED_HOSTS = os.environ.get("DJANGO_ALLOWED_HOSTS").split(" ")
ALLOWED_HOSTS = ['localhost', '127.0.0.1', '137.184.113.226']


# Application definition
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,22 @@ RUN apt-get update \
# install dependencies
RUN pip install --upgrade pip

COPY ./app/requirements.txt /requirements.txt
COPY ./requirements.txt /requirements.txt
RUN pip install -r /requirements.txt

COPY ./app/compose/local/django/entrypoint /entrypoint
COPY ./compose/production/django/entrypoint /entrypoint
RUN sed -i 's/\r$//g' /entrypoint
RUN chmod +x /entrypoint
# RUN chown django /entrypoint

COPY ./app/compose/local/django/start /start
COPY ./compose/production/django/start /start
RUN sed -i 's/\r$//g' /start
RUN chmod +x /start
# RUN chown django /start


# copy project
COPY . .

# run entrypoint.sh
ENTRYPOINT ["/usr/src/app/entrypoint.prod.sh"]
ENTRYPOINT ["/entrypoint"]
3 changes: 2 additions & 1 deletion app/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ django-cors-headers
python-dotenv
django-filter
django-nextjs
markdown
markdown
gunicorn==21.2.0
11 changes: 6 additions & 5 deletions docker-compose.ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: "3.9"
version: "3.8"

services:
web:
Expand All @@ -8,7 +8,7 @@ services:
cache_from:
- "${WEB_IMAGE}"
image: "${WEB_IMAGE}"
command: gunicorn hello_django.wsgi:application --bind 0.0.0.0:8000
command: gunicorn clearpath_home.wsgi:application --bind 0.0.0.0:8000
volumes:
- static_volume:/app/staticfiles
- media_volume:/app/mediafiles
Expand Down Expand Up @@ -37,10 +37,11 @@ services:
volumes:
- postgres_data:/var/lib/postgresql/data/
environment:
POSTGRES_USER: clearpath
POSTGRES_PASSWORD: clearpath
POSTGRES_DB: clearpath_dev
POSTGRES_USER: clearpath_home
POSTGRES_PASSWORD: clearpath_home
POSTGRES_DB: clearpath_home

volumes:
postgres_data:
static_volume:
media_volume: