Skip to content

Commit

Permalink
feat: Update environment variable handling in workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Armadillidiid committed Mar 18, 2024
1 parent a1b657d commit d4c70f7
Showing 1 changed file with 16 additions and 22 deletions.
38 changes: 16 additions & 22 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,33 +57,27 @@ jobs:
REMOTE_USER: ${{ secrets.USERNAME }}
TARGET: ${{ secrets.TARGET_DIR }}
SOURCE: "docker-compose.yaml"
SCRIPT_BEFORE: |
if ! grep -q "source export-env" ~/.bash_profile; then
echo "source export-env" >> ~/.bash_profile
fi
touch export-env
SCRIPT_AFTER: |
aws ecr get-login-password --region "${{ secrets.AWS_REGION }}" | docker login --username AWS --password-stdin "${{ steps.login-ecr.outputs.registry }}"
cd "${{ secrets.TARGET_DIR }}"
echo 'export POSTGRES_HOST="${{ secrets.POSTGRES_HOST }}"' > export-env
echo 'export POSTGRES_USER="${{ secrets.POSTGRES_USER }}"' >> export-env
echo 'export POSTGRES_PASSWORD="${{ secrets.POSTGRES_PASSWORD }}"' >> export-env
echo 'export POSTGRES_DB="${{ secrets.POSTGRES_DB }}"' >> export-env
echo 'export POSTGRES_PORT="${{ secrets.POSTGRES_PORT }}"' >> export-env
echo 'export DJANGO_SECRET_KEY="${{ secrets.DJANGO_SECRET_KEY }}"' >> export-env
echo 'export GOOGLE_MAP_API_KEY="${{ secrets.GOOGLE_MAP_API_KEY }}"' >> export-env
echo 'export DJANGO_ALLOWED_HOSTS="${{ secrets.DJANGO_ALLOWED_HOSTS }}"' >> export-env
echo 'export DJANGO_CSRF_TRUSTED_ORIGINS="${{ secrets.DJANGO_CSRF_TRUSTED_ORIGINS }}"' >> export-env
echo 'export SERVER_NAME="${{ vars.SERVER_NAME }}"' >> export-env
echo 'export CERTBOT_EMAIL="${{ secrets.CERTBOT_EMAIL }}"' >> export-env
echo 'export ECR_REGISTRY="${{ steps.login-ecr.outputs.registry }}"' >> export-env
echo 'export ECR_REPOSITORY="${{ env.ECR_REPOSITORY }}"' >> export-env
echo 'export IMAGE_TAG="${{ env.IMAGE_TAG }}"' >> export-env
echo 'POSTGRES_HOST="${{ secrets.POSTGRES_HOST }}"' > .env
echo 'POSTGRES_USER="${{ secrets.POSTGRES_USER }}"' >> .env
echo 'POSTGRES_PASSWORD="${{ secrets.POSTGRES_PASSWORD }}"' >> .env
echo 'POSTGRES_DB="${{ secrets.POSTGRES_DB }}"' >> .env
echo 'POSTGRES_PORT="${{ secrets.POSTGRES_PORT }}"' >> .env
echo 'DJANGO_SECRET_KEY="${{ secrets.DJANGO_SECRET_KEY }}"' >> .env
echo 'GOOGLE_MAP_API_KEY="${{ secrets.GOOGLE_MAP_API_KEY }}"' >> .env
echo 'DJANGO_ALLOWED_HOSTS="${{ secrets.DJANGO_ALLOWED_HOSTS }}"' >> .env
echo 'DJANGO_CSRF_TRUSTED_ORIGINS="${{ secrets.DJANGO_CSRF_TRUSTED_ORIGINS }}"' >> .env
echo 'SERVER_NAME="${{ vars.SERVER_NAME }}"' >> .env
echo 'CERTBOT_EMAIL="${{ secrets.CERTBOT_EMAIL }}"' >> .env
echo 'ECR_REGISTRY="${{ steps.login-ecr.outputs.registry }}"' >> .env
echo 'ECR_REPOSITORY="${{ env.ECR_REPOSITORY }}"' >> .env
echo 'IMAGE_TAG="${{ env.IMAGE_TAG }}"' >> .env
source ~/.bash_profile
cd "${{ secrets.TARGET_DIR }}"
docker compose pull
docker compose down
docker compose up -d
docker compose up -d --env-file .env
# rm -f local_ssh_script-before-*.sh
docker system prune -af

0 comments on commit d4c70f7

Please sign in to comment.