128 lines
2.8 KiB
YAML
128 lines
2.8 KiB
YAML
################
|
|
# Build & Test #
|
|
################
|
|
|
|
kind: pipeline
|
|
name: run_tests
|
|
|
|
steps:
|
|
# Run tests against React client app (with Jest)
|
|
- name: client_test
|
|
image: node:18-alpine
|
|
commands:
|
|
- cd services/client
|
|
# Install dependencies
|
|
- yarn install --frozen-lockfile
|
|
# Run tests in CI mode
|
|
- CI=true yarn test --coverage
|
|
volumes:
|
|
- name: node_cache
|
|
path: /drone/src/services/client/node_modules
|
|
|
|
# Run tests against Python/Flask engine backend (with pytest)
|
|
- name: engine_test
|
|
image: python:3.9-alpine
|
|
commands:
|
|
- cd services/game
|
|
# Install dependencies
|
|
- pip install -r requirements.txt
|
|
# Start with a fresh database
|
|
- python manage.py recreate_db
|
|
# Run tests
|
|
- pytest --cov=project --cov-report=term-missing
|
|
environment:
|
|
FLASK_ENV: production
|
|
APP_SETTINGS: project.config.TestingConfig
|
|
DATABASE_TEST_URL: postgres://postgres:postgres@gamedb:5432/game_test
|
|
volumes:
|
|
- name: pip_cache
|
|
path: /root/.cache/pip
|
|
|
|
# Run tests against full stack (with Cypress)
|
|
- name: e2e_test
|
|
image: cypress/included:10.10.0
|
|
environment:
|
|
CYPRESS_baseUrl: http://localhost:8000
|
|
commands:
|
|
# Build the stack
|
|
- docker-compose -f docker-compose.yml up -d
|
|
# Run Cypress tests
|
|
- yarn cypress run
|
|
- docker-compose -f docker-compose.yml down
|
|
volumes:
|
|
- name: docker
|
|
path: /var/run/docker.sock
|
|
|
|
# Notify Telegram that tests are passed
|
|
- name: telegram_notify
|
|
image: appleboy/drone-telegram
|
|
settings:
|
|
token:
|
|
from_secret: telegram_token
|
|
to:
|
|
from_secret: telegram_chat_id
|
|
message: >
|
|
Build {{build.number}} {{build.status}}:
|
|
{{build.link}}
|
|
when:
|
|
status:
|
|
- success
|
|
- failure
|
|
|
|
volumes:
|
|
- name: docker
|
|
host:
|
|
path: /var/run/docker.sock
|
|
- name: pip_cache
|
|
host:
|
|
path: /tmp/cache/drone/pip
|
|
- name: node_cache
|
|
host:
|
|
path: /tmp/cache/drone/node_modules
|
|
|
|
services:
|
|
- name: gamedb
|
|
image: postgres:15-alpine
|
|
ports:
|
|
- 5432
|
|
environment:
|
|
POSTGRES_USER: postgres
|
|
POSTGRES_PASSWORD: postgres
|
|
POSTGRES_DB: game_test
|
|
|
|
---
|
|
########################
|
|
# Deploy to Production #
|
|
########################
|
|
|
|
kind: pipeline
|
|
name: deploy
|
|
|
|
depends_on:
|
|
- run_tests
|
|
|
|
trigger:
|
|
status:
|
|
- success
|
|
|
|
steps:
|
|
- name: deploy
|
|
image: python:3.9-alpine
|
|
commands:
|
|
- pip install fabric
|
|
- fab -H production.server deploy
|
|
environment:
|
|
DEPLOY_HOST: production.server
|
|
DEPLOY_USER: deploy_user
|
|
DEPLOY_PATH: /var/www/app
|
|
DEPLOY_KEY: /root/.ssh/id_rsa
|
|
when:
|
|
branch: master
|
|
event:
|
|
- push
|
|
|
|
volumes:
|
|
- name: ssh
|
|
host:
|
|
path: /home/drone_user/.ssh
|