Merge pull request #229 from ZUS666/develop #49
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
name: api_spot | |
on: | |
push: | |
branches: [ "main" ] | |
jobs: | |
send_docker_compose: | |
name: Send docker-compose | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: copy file via ssh password | |
uses: appleboy/scp-action@v0.1.4 | |
with: | |
host: ${{ secrets.HOST }} | |
password: ${{ secrets.PASSWORD }} | |
username: ${{ secrets.USER }} | |
key: ${{ secrets.SSH_KEY }} | |
source: "infra/docker-compose.yml" | |
target: ${{ secrets.DEPLOY_PATH }} | |
overwrite: true | |
send_nginx: | |
name: Send nginx | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: copy file via ssh password | |
uses: appleboy/scp-action@v0.1.4 | |
with: | |
host: ${{ secrets.HOST }} | |
password: ${{ secrets.PASSWORD }} | |
username: ${{ secrets.USER }} | |
key: ${{ secrets.SSH_KEY }} | |
source: "infra/nginx/default.conf" | |
target: ${{ secrets.DEPLOY_PATH }} | |
overwrite: true | |
build_and_push_to_docker_hub: | |
name: Push Docker image to Docker Hub | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out the repo | |
uses: actions/checkout@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Login to Docker | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Push to Docker Hub | |
uses: docker/build-push-action@v4 | |
with: | |
context: ./api_spot/ | |
push: true | |
tags: ${{ secrets.DOCKER_USERNAME }}/${{ secrets.IMAGE_NAME }}:latest | |
deploy: | |
runs-on: ubuntu-latest | |
needs: [send_docker_compose, send_nginx, build_and_push_to_docker_hub] | |
steps: | |
- name: executing remote ssh commands to deploy | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.HOST }} | |
username: ${{ secrets.USER }} | |
password: ${{ secrets.PASSWORD }} | |
key: ${{ secrets.SSH_KEY }} | |
script: | | |
cd ${{ secrets.DEPLOY_PATH }} | |
sudo docker pull ${{ secrets.DOCKER_USERNAME }}/${{ secrets.IMAGE_NAME }}:latest | |
sudo docker rmi $(sudo docker images -f dangling=true) | |
rm .env | |
touch .env | |
echo ALLOWED_HOSTS=${{ secrets.ALLOWED_HOSTS }} >> .env | |
echo HOST=${{ secrets.HOST }} >> .env | |
echo SECRET_KEY=${{ secrets.SECRET_KEY }} >> .env | |
echo DB_ENGINE=${{ secrets.DB_ENGINE }} >> .env | |
echo DB_NAME=${{ secrets.DB_NAME }} >> .env | |
echo POSTGRES_USER=${{ secrets.POSTGRES_USER }} >> .env | |
echo POSTGRES_PASSWORD=${{ secrets.POSTGRES_PASSWORD }} >> .env | |
echo DB_HOST=${{ secrets.DB_HOST }} >> .env | |
echo DB_PORT=${{ secrets.DB_PORT }} >> .env | |
echo CELERY_BROKER=${{ secrets.CELERY_BROKER }} >> .env | |
echo CELERY_BACKEND=${{ secrets.CELERY_BACKEND }} >> .env | |
echo REDIS_ADDRESS=${{ secrets.REDIS_ADDRESS }} >> .env | |
echo CELERY_BROKER_URL=${{ secrets.CELERY_BROKER_URL }} >> .env | |
echo FLOWER_PORT=${{ secrets.FLOWER_PORT }} >> .env | |
echo FLOWER_URL_PREFIX=${{ secrets.FLOWER_URL_PREFIX }} >> .env | |
echo FLOWER_BASIC_AUTH=${{ secrets.FLOWER_BASIC_AUTH }} >> .env | |
echo GMAIL_API_CLIENT_ID=${{ secrets.GMAIL_API_CLIENT_ID }} >> .env | |
echo GMAIL_API_CLIENT_SECRET=${{ secrets.GMAIL_API_CLIENT_SECRET }} >> .env | |
echo GMAIL_API_REFRESH_TOKEN=${{ secrets.GMAIL_API_REFRESH_TOKEN }} >> .env | |
echo COMPANY_NAME=${{ secrets.COMPANY_NAME }} >> .env | |
echo AWS_ACCESS_KEY_ID=${{ secrets.AWS_ACCESS_KEY_ID }} >> .env | |
echo AWS_SECRET_ACCESS_KEY=${{ secrets.AWS_SECRET_ACCESS_KEY }} >> .env | |
echo AWS_S3_ENDPOINT_URL=${{ secrets.AWS_S3_ENDPOINT_URL }} >> .env | |
echo AWS_S3_REGION_NAME=${{ secrets.AWS_S3_REGION_NAME }} >> .env | |
cd infra | |
sudo docker-compose stop | |
sudo docker-compose rm backend | |
sudo docker-compose rm celery | |
sudo docker-compose rm celery_beat | |
sudo docker-compose up -d | |
sudo docker-compose exec -d backend python manage.py migrate |