Skip to content

Commit

Permalink
modified scp of nginx
Browse files Browse the repository at this point in the history
  • Loading branch information
leoBitto committed Apr 13, 2024
1 parent 767c662 commit ff47c62
Showing 1 changed file with 21 additions and 23 deletions.
44 changes: 21 additions & 23 deletions .github/workflows/CI-CD.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ env:
jobs:
build_and_push:
runs-on: ubuntu-latest

steps:

- name: Checkout the repo
uses: actions/checkout@v3
with:
Expand Down Expand Up @@ -58,16 +56,14 @@ jobs:

- name: Tag image
run: |
echo ${REGISTRY}/${OWNER_LC}/${IMAGE_NAME}:latest
docker tag webapp_django ${REGISTRY}/${OWNER_LC}/${IMAGE_NAME}:latest
docker tag webapp_django ${{ env.REGISTRY }}/${OWNER_LC}/${{ env.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
docker push ${{ env.REGISTRY }}/${OWNER_LC}/${{ env.IMAGE_NAME }}:latest
deploy:
runs-on: ubuntu-latest
Expand All @@ -81,13 +77,11 @@ jobs:
submodules: recursive
token: ${{ secrets.GITHUB_TOKEN }}


- name: Set ENV variables
- name: Get repo name to give directory a name
run: |
echo "REPO_NAME=${GITHUB_REPOSITORY#$GITHUB_REPOSITORY_OWNER/}" >> $GITHUB_ENV
echo $GITHUB_ENV

- name: Create project directory and conf file
uses: appleboy/[email protected]
with:
Expand All @@ -112,7 +106,6 @@ jobs:
echo "DOMAIN=${{ secrets.DOMAIN }}" >> "/opt/${{ env.REPO_NAME }}/config/.env"
cat "/opt/${{ env.REPO_NAME }}/config/.env"
- name: SCP Docker Compose file
uses: appleboy/scp-action@master
with:
Expand All @@ -122,6 +115,24 @@ jobs:
source: "./docker-compose.prod.yml"
target: "/opt/${{ env.REPO_NAME }}/"

- name: SCP Nginx conf file
uses: appleboy/scp-action@master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.PRIVATE_KEY }}
source: "./nginx/nginx.conf"
target: "/etc/nginx/"
strip_components: 2

- name: Update Nginx configuration file
uses: appleboy/[email protected]
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.PRIVATE_KEY }}
script: |
sed -i "s/yourdomain.com/${{ secrets.DOMAIN }}/g" /opt/${{ env.REPO_NAME }}/nginx/nginx.prod.conf
- name: Upgrade server and install Docker
uses: appleboy/[email protected]
Expand All @@ -147,16 +158,13 @@ jobs:
sudo apt-get update -y
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose docker-compose-plugin -y
sudo apt upgrade -y
- name: set lower case owner name
run: |
echo "OWNER_LC=${OWNER,,}" >>${GITHUB_ENV}
env:
OWNER: '${{ github.repository_owner }}'


- name: Stop And Start containers
uses: appleboy/[email protected]
with:
Expand All @@ -177,14 +185,4 @@ jobs:
docker exec web python manage.py migrate
docker exec web python manage.py collectstatic --noinput --clear
- name: Restart Nginx Service
uses: appleboy/[email protected]
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.PRIVATE_KEY }}
script: |
sudo systemctl restart nginx

0 comments on commit ff47c62

Please sign in to comment.