-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
21 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,9 +13,7 @@ env: | |
jobs: | ||
build_and_push: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
|
||
- name: Checkout the repo | ||
uses: actions/checkout@v3 | ||
with: | ||
|
@@ -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 | ||
|
@@ -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: | ||
|
@@ -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: | ||
|
@@ -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] | ||
|
@@ -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: | ||
|
@@ -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 | ||