stages:
  - test
  - deploy
  
before_script:
  - apk update
  - apk add pkgconfig
  - apk add mariadb-connector-c-dev build-base


test:
  stage: test
  image: python:3.9-alpine  
  script:
    - pip install --upgrade pip
    - pip install django
    - pip install -r requirements.txt
    - pip install python-dotenv
    - python manage.py test

deploy:
  stage: deploy
  image: python:3.9-alpine  
  before_script:
  - apk add --no-cache openssh-client
  - eval $(ssh-agent -s)
  - echo "$SSH_PRIVATE_KEY" | ssh-add -
  - ssh -o StrictHostKeyChecking=no $SSH_USER@$SERVER_IP echo "SSH-connection successful."
  script:
    - mkdir deploy
    - cp -r core deploy/
    - cp -r server deploy/
    - cp manage.py requirements.txt test.rest docker-compose.yml Dockerfile deploy/
    - ls deploy/
    - scp -r deploy $SSH_USER@$SERVER_IP:$DEPLOY_PATH/
    - ssh $SSH_USER@$SERVER_IP "cd $DEPLOY_PATH/deploy && docker compose down"
    - ssh $SSH_USER@$SERVER_IP "cd $DEPLOY_PATH/deploy && docker compose up -d"
  only:
    - main