Skip to content

Instantly share code, notes, and snippets.

@michaelachrisco
Created November 12, 2019 19:56
Show Gist options
  • Save michaelachrisco/acdd7963887d0cd51e6e7801c4dc0940 to your computer and use it in GitHub Desktop.
Save michaelachrisco/acdd7963887d0cd51e6e7801c4dc0940 to your computer and use it in GitHub Desktop.
Working Django Circleci Setup with Selenium
version: 2.1
jobs:
build:
working_directory: ~/DjangoProjectName
docker:
- image: circleci/python:3.7.3-browsers
environment:
DATABASE_URL: postgresql://root@localhost/circle_test?sslmode=disable
- image: circleci/postgres:9.6.7
environment:
POSTGRES_USER: root
POSTGRES_DB: circle_test
steps:
- checkout
- add_ssh_keys:
fingerprints:
- "yourdeploykeyhere"
- run: sudo apt-get update
- run: sudo chown -R circleci:circleci /usr/local/bin
- run: sudo chown -R circleci:circleci /usr/local/lib/python3.7/site-packages
- run: sudo apt install postgresql-client memcached
- restore_cache:
key: deps9-{{ .Branch }}-{{ checksum "requirements.txt" }}
- run:
name: Install Python dependencies
command: |
pip install -r requirements.txt --user
- save_cache:
key: deps9-{{ .Branch }}-{{ checksum "requirements.txt" }}
paths:
- ".venv"
- "/usr/local/bin"
- "/usr/local/lib/python3.7/site-packages"
- run:
name: Install geckodriver
command: |
wget https://github.com/mozilla/geckodriver/releases/download/v0.21.0/geckodriver-v0.21.0-linux64.tar.gz
tar -xvzf geckodriver*
chmod 755 geckodriver
sudo mv geckodriver /usr/local/bin
- run:
name: Install the latest firefox
command: |
sudo sh -c "echo 'deb http://ftp.hr.debian.org/debian sid main' >> /etc/apt/sources.list" &&
sudo apt-get update &&
sudo apt-get install -t sid firefox &&
firefox --version
- run:
command: |
cp DjangoProjectName/test_settings.py DjangoProjectName/settings.py
python manage.py migrate --settings=DjangoProjectName.settings
python manage.py sync_pgviews --force
python manage.py testserver core_auth/fixtures/test.json --noinput
background: true
- run:
command: |
sleep 10
python manage.py test --verbosity 2 --nomigrations --noinput --testrunner=DjangoProjectName.settings.NoDbTestRunner --keepdb
- store_test_results:
path: test-results
- store_artifacts:
path: test-results
destination: tr1
build-frontend:
working_directory: ~/DjangoProjectName
docker:
- image: "circleci/node:10.16.3"
steps:
- checkout
- run: sudo apt-get update
- run:
name: Install and setup frontend
command: |
cd frontend
yarn install
yarn audit-ci --moderate
yarn ng build --prod --no-progress --output-path ../core/templates/ang/ --output-hashing none
cd ..
- persist_to_workspace:
root: /home/circleci
paths:
- DjangoProjectName
deploy:
working_directory: ~/DjangoProjectName
machine:
enabled: true
steps:
- attach_workspace:
at: /home/circleci
- add_ssh_keys:
fingerprints:
- "yourdeploykeyhere"
- run: sudo apt install rsync
- run:
name: Deploy Over SSH
command: |
rsync -a --delete-before -e "ssh -A -p $SSH_PORT" ~/DjangoProjectName $SSH_USER@$SSH_HOST:/home/$SSH_USER/
cat .circleci/deploy.sh | ssh -A -p $SSH_PORT -l $SSH_USER $SSH_HOST bash
workflows:
version: 2
build_and_test:
jobs:
- build-frontend
- build
build-and-deploy:
jobs:
- hold: # <<< A job that will require manual approval in the CircleCI web application.
type: approval # <<< This key-value pair will set your workflow to a status of "On Hold"
requires: # We only run the "hold" job when test has succeeded
- build
- build-frontend
- build:
filters:
branches:
only: master
- build-frontend:
filters:
branches:
only: master
- deploy:
requires:
- build
- build-frontend
- hold
filters:
branches:
only: master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment