-
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
5 changed files
with
237 additions
and
327 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -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 | ||
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 |
---|---|---|
@@ -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 |
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
Oops, something went wrong.