Skip to content

Commit

Permalink
merged in only one workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
leoBitto committed Apr 1, 2024
1 parent 15af790 commit 0480a0f
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 90 deletions.
92 changes: 75 additions & 17 deletions .github/workflows/deploy.yml → .github/workflows/CI-CD.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,73 @@
name: Deploy
name: CI/CD

on:
push:
branches: main
workflow_dispatch:
workflow_dispatch:


env:
REGISTRY: ghcr.io
IMAGE_NAME: tester
IMAGE_NAME: djangoforge

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=${{ secrets.DOMAIN }}" >> config/.env
working-directory: .

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

- name: Update Nginx configuration file
run: |
sed -i "s/server_name localhost/server_name ${{ secrets.DOMAIN }}/g" ./nginx/nginx.conf
working-directory: .

- name: Build Docker image using Docker Compose
run: docker-compose -f docker-compose.dev.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}:latest
docker tag webapp_django ${REGISTRY}/${OWNER_LC}/${IMAGE_NAME}: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
jobs:
deploy:
Expand All @@ -32,7 +92,7 @@ jobs:
script: |
mkdir -p "/opt/${{ env.REPO_NAME }}"
mkdir -p "/opt/${{ env.REPO_NAME }}/config"
rm /opt/${{ env.REPO_NAME }}/confing/.env
rm /opt/${{ env.REPO_NAME }}/config/.env
echo "DEBUG=False" >> "/opt/${{ env.REPO_NAME }}/config/.env"
echo "SECRET_KEY=foo" >> "/opt/${{ env.REPO_NAME }}/config/.env"
echo "DJANGO_ALLOWED_HOSTS=localhost 127.0.0.1 [::1] *" >> "/opt/${{ env.REPO_NAME }}/config/.env"
Expand Down Expand Up @@ -103,16 +163,16 @@ jobs:
env:
OWNER: '${{ github.repository_owner }}'

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

# - name: Pull image from GitHub Container Registry
# run: |
# echo ${REGISTRY}/${OWNER_LC}/${{ env.IMAGE_NAME }}:latest
# docker pull ${REGISTRY}/${OWNER_LC}/${{ env.IMAGE_NAME }}:latest
# docker tag ${REGISTRY}/${OWNER_LC}/${{ env.IMAGE_NAME }}:latest ${{ env.IMAGE_NAME }}
# docker images
# - name: LOG IN to container registry
# run: |
# echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u ${{ github.actor }} --password-stdin
# - name: Pull image from GitHub Container Registry
# run: |
# echo ${REGISTRY}/${OWNER_LC}/${{ env.IMAGE_NAME }}:latest
# docker pull ${REGISTRY}/${OWNER_LC}/${{ env.IMAGE_NAME }}:latest
# docker tag ${REGISTRY}/${OWNER_LC}/${{ env.IMAGE_NAME }}:latest ${{ env.IMAGE_NAME }}
# docker images

- name: Stop And Start containers
uses: appleboy/ssh-action@v0.1.3
Expand All @@ -134,6 +194,4 @@ jobs:
# docker-compose -f /opt/${{ env.REPO_NAME }}/docker-compose-prod.yml exec -T web python manage.py migrate --noinput
# docker-compose -f /opt/${{ env.REPO_NAME }}/docker-compose-prod.yml exec -T web python manage.py collectstatic --noinput --clear





73 changes: 0 additions & 73 deletions .github/workflows/build-and-push.yml

This file was deleted.

0 comments on commit 0480a0f

Please sign in to comment.