Skip to content

Commit

Permalink
newer version
Browse files Browse the repository at this point in the history
  • Loading branch information
leoBitto committed Mar 28, 2024
1 parent cc9e09c commit d3ae338
Show file tree
Hide file tree
Showing 5 changed files with 237 additions and 327 deletions.
118 changes: 0 additions & 118 deletions .github/workflows/build-and-deploy.yml

This file was deleted.

71 changes: 71 additions & 0 deletions .github/workflows/build-and-push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: BUILD & PUSH ON GHCR

on:
push:
branches: main
workflow_dispatch:


env:
REGISTRY: ghcr.io
IMAGE_NAME: webapp_django

jobs:
build_and_push:
runs-on: ubuntu-latest
steps:
- name: Checkout the repo
uses: actions/checkout@v2

- name: Create config directory and .env file
run: |
mkdir -p config
echo "DEBUG=False" >> config/.env
echo "SECRET_KEY=foo" >> config/.env
echo "DJANGO_ALLOWED_HOSTS=localhost 127.0.0.1 [::1] *" >> config/.env
echo "SQL_ENGINE=django.db.backends.postgresql" >> config/.env
echo "POSTGRES_DB=${{ secrets.POSTGRES_DB }}" >> config/.env
echo "POSTGRES_USER=${{ secrets.POSTGRES_USER }}" >> config/.env
echo "POSTGRES_PASSWORD=${{ secrets.POSTGRES_PASSWORD }}" >> config/.env
echo "SQL_HOST=db" >> config/.env
echo "SQL_PORT=5432" >> config/.env
echo "DATABASE=postgres" >> config/.env
echo "DOMAIN=localhost" >> config/.env
working-directory: .

- name: Display content of .env file
run: cat ./config/.env

- name: Build Docker image using Docker Compose
run: docker-compose -f docker-compose.yml build

- name: verify that all the container have been built
run: docker images

- name: LOG IN to container registry
run: echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u ${{ github.actor }} --password-stdin

- name: set lower case owner name
run: |
echo "OWNER_LC=${OWNER,,}" >>${GITHUB_ENV}
env:
OWNER: '${{ github.repository_owner }}'

- name: Tag image
run: |
echo ${REGISTRY}/${OWNER_LC}/${IMAGE_NAME}:${{ github.run_number }}
docker tag ${IMAGE_NAME} ${REGISTRY}/${OWNER_LC}/${IMAGE_NAME}:latest
docker tag nginx_django ${REGISTRY}/${OWNER_LC}/nginx_django:latest
- name: List Docker images
run: docker images


- name: Push image to GitHub Container Registry
run: |
echo ${REGISTRY}/${OWNER_LC}/${{ env.IMAGE_NAME }}:latest
docker push ${REGISTRY}/${OWNER_LC}/${{ env.IMAGE_NAME }}:latest
docker push ${REGISTRY}/${OWNER_LC}/nginx_django:latest
88 changes: 88 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
name: Deploy

on:
push:
branches: main
workflow_dispatch:


jobs:
deploy:
runs-on: ubuntu-latest

steps:

- name: Checkout del repository
uses: actions/checkout@v2

- name: Set ENV variables
run: |
echo "REPO_NAME=${GITHUB_REPOSITORY#$GITHUB_REPOSITORY_OWNER/}" >> $GITHUB_ENV
- name: Clone or update repository
id: clone_or_update_repo
uses: appleboy/[email protected]
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.DO_SSH_PRIVATE_KEY }}


script: |
if [ ! -d "/etc/docker/tester" ]; then
git clone --recursive https://leoBitto:${{ secrets.GITHUB_TOKEN }}@github.com/leoBitto/tester.git /etc/docker/tester
else
cd /etc/docker/tester
git pull --recurse-submodules origin main
fi

- name: Create config directory and .env file
uses: appleboy/[email protected]
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.DO_SSH_PRIVATE_KEY }}
script: |
mkdir -p config
echo "DEBUG=False" >> config/.env
echo "SECRET_KEY=foo" >> config/.env
echo "DJANGO_ALLOWED_HOSTS=localhost 127.0.0.1 [::1] *" >> config/.env
echo "SQL_ENGINE=django.db.backends.postgresql" >> config/.env
echo "POSTGRES_DB=${{ secrets.POSTGRES_DB }}" >> config/.env
echo "POSTGRES_USER=${{ secrets.POSTGRES_USER }}" >> config/.env
echo "POSTGRES_PASSWORD=${{ secrets.POSTGRES_PASSWORD }}" >> config/.env
echo "SQL_HOST=db" >> config/.env
echo "SQL_PORT=5432" >> config/.env
echo "DATABASE=postgres" >> config/.env
echo "DOMAIN=localhost" >> config/.env
pwd
ls -la
cat ./config/.env
- name: Upgrade server and install docker and stop old container
uses: appleboy/[email protected]
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.DO_SSH_PRIVATE_KEY }}
script: |
sudo apt update -y
sudo apt upgrade -y
sudo apt install docker-ce docker-ce-cli containerd.io -y
sudo apt install docker-compose -y
cd /etc/docker
docker-compose down || true
- name: Avvia i nuovi container
uses: appleboy/[email protected]
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.DO_SSH_PRIVATE_KEY }}
script: |
cd /etc/docker
docker-compose down || true
docker-compose up -d
5 changes: 2 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ services:
build:
context: ./src
dockerfile: Dockerfile
image: django
command: gunicorn base.wsgi:application --bind 0.0.0.0:8000 --workers 3 --timeout 90
volumes:
- static_volume:/home/app/web/static
Expand All @@ -16,16 +15,16 @@ services:
- ./config/.env
depends_on:
- db

db:
image: postgres:15
image: postgres
volumes:
- postgres_data:/var/lib/postgresql/data/
env_file:
- ./config/.env

nginx:
build: ./nginx
image: nginx:latest
volumes:
- static_volume:/home/app/web/static
- media_volume:/home/app/web/media
Expand Down
Loading

0 comments on commit d3ae338

Please sign in to comment.