From b167599ef3d76f9366605b7b4e4f15613900491e Mon Sep 17 00:00:00 2001 From: leoBitto Date: Sat, 12 Oct 2024 18:10:50 +0200 Subject: [PATCH] third test for deploy --- ...reatesuperuser.yml => createsuperuser.yml} | 2 +- .github/workflows/deploy.yml | 15 ++++- .github/workflows/old_cicd_orchestrator.yml | 36 ---------- .github/workflows/old_deploy.yml | 67 ------------------- 4 files changed, 13 insertions(+), 107 deletions(-) rename .github/workflows/{old_createsuperuser.yml => createsuperuser.yml} (97%) delete mode 100644 .github/workflows/old_cicd_orchestrator.yml delete mode 100644 .github/workflows/old_deploy.yml diff --git a/.github/workflows/old_createsuperuser.yml b/.github/workflows/createsuperuser.yml similarity index 97% rename from .github/workflows/old_createsuperuser.yml rename to .github/workflows/createsuperuser.yml index b0efcc3d..eddf9a0b 100644 --- a/.github/workflows/old_createsuperuser.yml +++ b/.github/workflows/createsuperuser.yml @@ -1,4 +1,4 @@ -name: Create Django Superuser +name: 04.Create Django Superuser on: workflow_dispatch: # Trigger manual workflow run diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 08055c53..8a3e16ff 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -22,6 +22,15 @@ jobs: submodules: recursive token: ${{ secrets.GITHUB_TOKEN }} + - name: Remove old config directory + uses: appleboy/ssh-action@v0.1.3 + with: + host: ${{ secrets.HOST }} + username: ${{ secrets.USERNAME }} + key: ${{ secrets.PRIVATE_KEY }} + script: | + rm -r /opt/config/ + # Step 2: Creazione dei file di configurazione - name: Create config directory uses: appleboy/ssh-action@v0.1.3 @@ -91,7 +100,7 @@ jobs: username: ${{ secrets.USERNAME }} key: ${{ secrets.PRIVATE_KEY }} source: "./docker-compose.prod.yml" - target: "/opt/${{ github.repository }}/" + target: "/opt/" # Step 4: Pull dei container da GHCR - name: Pull containers from GHCR @@ -102,8 +111,8 @@ jobs: key: ${{ secrets.PRIVATE_KEY }} script: | echo ${{ secrets.GHCR_TOKEN }} | docker login ghcr.io -u ${{ github.actor }} --password-stdin - docker-compose -f /opt/${{ github.repository }}/docker-compose.prod.yml pull - docker-compose -f /opt/${{ github.repository }}/docker-compose.prod.yml up -d --force-recreate + docker compose -f /opt/docker-compose.prod.yml pull + docker compose -f /opt/docker-compose.prod.yml up -d --force-recreate # Step 5: Configurazione di Nginx - name: SCP Nginx configuration diff --git a/.github/workflows/old_cicd_orchestrator.yml b/.github/workflows/old_cicd_orchestrator.yml deleted file mode 100644 index 089046e9..00000000 --- a/.github/workflows/old_cicd_orchestrator.yml +++ /dev/null @@ -1,36 +0,0 @@ -name: CI/CD Orchestrator - -on: - push: - branches: - - main # Trigger on push to the main branch - -jobs: - deploy: - runs-on: ubuntu-latest - - steps: - # Step 1: Checkout repository - - name: Checkout Repository - uses: ./.github/workflows/checkout-repo.yml - - # Step 2: Create configuration files for Django and PostgreSQL - - name: Create Config Files - uses: ./.github/workflows/create-config-files.yml - with: - repo_name: "myrepo" - host: ${{ secrets.HOST }} - username: ${{ secrets.USERNAME }} - private_key: ${{ secrets.PRIVATE_KEY }} - - # Step 3: Build and Push Docker image to the GitHub registry - - name: Build and Push Docker Image - uses: ./.github/workflows/build-and-push-docker.yml - - # Step 4: Deploy containers (stop old, start new) - - name: Deploy Containers - uses: ./.github/workflows/deploy-containers.yml - with: - host: ${{ secrets.HOST }} - username: ${{ secrets.USERNAME }} - private_key: ${{ secrets.PRIVATE_KEY }} diff --git a/.github/workflows/old_deploy.yml b/.github/workflows/old_deploy.yml deleted file mode 100644 index 966c4f0e..00000000 --- a/.github/workflows/old_deploy.yml +++ /dev/null @@ -1,67 +0,0 @@ -name: Deploy Docker Compose - -on: - workflow_call: - inputs: - host: - description: "Host IP Address" - required: true - username: - description: "Username for SSH" - required: true - private_key: - description: "Private Key for SSH" - required: true - repo_name: - description: "Name of the repo" - required: true - ghcr_token: - description: "Token to access repo" - required: true - image_name: - description: "Name of the image" - required: true - -jobs: - deploy-containers: - runs-on: ubuntu-latest - - steps: - - name: Checkout Repository - uses: actions/checkout@v3 - with: - submodules: recursive - token: ${{ inputs.ghcr_token }} - - - name: SCP Docker Compose file - uses: appleboy/scp-action@master - with: - host: ${{ inputs.host }} - username: ${{ inputs.username }} - key: ${{ inputs.private_key }} - source: "./docker-compose.prod.yml" - target: "/opt/${{ inputs.repo_name }}/" - - - name: Start containers - uses: appleboy/ssh-action@v0.1.3 - with: - host: ${{ inputs.host }} - username: ${{ inputs.username }} - key: ${{ inputs.private_key }} - script: | - echo ${{ inputs.ghcr_token }} | docker login ghcr.io -u ${{ github.actor }} --password-stdin - - docker pull ghcr.io/leobitto/${{ inputs.image_name }}:latest - - docker tag ghcr.io/leobitto/${{ inputs.image_name }}:latest ${{ inputs.image_name }} - - mkdir -p /opt/web/static - mkdir -p /opt/web/media - - - docker compose -f /opt/${{ inputs.repo_name }}/docker-compose.prod.yml up -d - echo "wait 5 sec for POSTGRES service to fully start" - sleep 5 - echo "5 seconds has passed" - docker exec web python manage.py migrate - docker exec web python manage.py collectstatic --noinput --clear