Last active
June 25, 2020 07:24
-
-
Save xb4dc0d3/3ae8e73150b5d879fcaf14b268f31ac6 to your computer and use it in GitHub Desktop.
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
image: python:latest | |
stages: | |
- test | |
- flake8 | |
- build | |
- sonarqube | |
- deploy | |
variables: | |
DOCKER_HOST: tcp://docker:2375 | |
DOCKER_TLS_CERTDIR: "" | |
PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip" | |
DOCKER_DRIVER: overlay2 | |
cache: | |
paths: | |
- .cache/pip | |
- venv/ | |
before_script: | |
- python -V | |
- pip install virtualenv | |
- virtualenv venv | |
- source venv/bin/activate | |
- pip install -r requirements.txt | |
dev-test: | |
stage: test | |
script: | |
- echo "SECRET_KEY=$SECRET_KEY_DJANGO" > .env.dev | |
- apt-get update -qq | |
- python manage.py collectstatic --settings=sip.settings.dev --no-input | |
- python manage.py runserver 8000 --settings=sip.settings.dev & | |
when: on_success | |
script: | |
- python manage.py test --settings=sip.settings.dev | |
only: | |
- development | |
- /^.*PBI-.*$/ | |
staging-test: | |
stage: test | |
script: | |
- echo "SECRET_KEY=$SECRET_KEY_DJANGO" > .env.staging | |
- apt-get update -qq | |
- python manage.py collectstatic --settings=sip.settings.staging --no-input | |
- python manage.py runserver 8000 --settings=sip.settings.staging & | |
when: on_success | |
script: | |
- python manage.py test --settings=sip.settings.staging | |
only: | |
- staging | |
lint: | |
stage: flake8 | |
script: | |
- flake8 | |
allow_failure: true | |
except: | |
- CI-CD | |
sonarqube: | |
image: nuga99/sonar-scanner-python | |
stage: sonarqube | |
before_script: | |
- python3 -V | |
- pip3 install -r requirements.txt | |
script: | |
- if [[ $CI_COMMIT_REF_NAME == staging ]]; then ENVIRON="sip.settings.staging"; else ENVIRON="sip.settings.dev"; fi | |
- coverage run --omit='manage.py,*/venv/*,**/python3*/**,authentication/cas_wrapper.py,/usr/**' manage.py test --settings=${ENVIRON} | |
- coverage report -m | |
- coverage xml -i | |
- sonar-scanner | |
-Dsonar.host.url=https://pmpl.cs.ui.ac.id/sonarqube | |
-Dsonar.projectKey=$SONARQUBE_PROJECT_KEY | |
-Dsonar.login=$SONARQUBE_TOKEN | |
-Dsonar.branch.name=$CI_COMMIT_REF_NAME | |
only: | |
- master | |
- staging | |
- development | |
- /^.*PBI-.*$/ | |
backend-deploy: | |
image: ruby:2.4 | |
stage: deploy | |
only: | |
- staging | |
before_script: | |
- gem install dpl | |
- wget -qO- https://cli-assets.heroku.com/install-ubuntu.sh | sh | |
script: | |
- dpl --provider=heroku --app=$HEROKU_APPNAME --api-key=$HEROKU_APIKEY | |
- export HEROKU_API_KEY=$HEROKU_APIKEY | |
- echo "SECRET_KEY=$SECRET_KEY_DJANGO" > .env.staging | |
- heroku run --app $HEROKU_APPNAME migrate | |
environment: | |
name: production | |
url: $HEROKU_APP_HOST | |
deploy_vm: | |
image: ubuntu | |
stage: deploy | |
only: | |
- staging | |
- CI-CD | |
before_script: | |
- 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client git -y )' | |
- eval $(ssh-agent -s) | |
- ssh-add <(echo "$SSH_1_KEY") | |
- mkdir -p ~/.ssh | |
- chmod 700 ~/.ssh | |
- ssh-keyscan kawung.cs.ui.ac.id >> ~/.ssh/known_hosts | |
- chmod 644 ~/.ssh/known_hosts | |
- '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config' | |
- echo "SECRET_KEY=$SECRET_KEY_DJANGO" > .env | |
- echo "DB_NAME=$DB_NAME" > .env | |
- echo "DB_USER=$DB_USER" > .env | |
- echo "DB_PASS=$DB_PASS" > .env | |
- echo "DB_HOST=$DB_HOST" > .env | |
- echo "DB_PORT=$DB_PORT" > .env | |
script: | |
- scp .env username@proxy_ip:/home/username | |
- ssh -T username@proxy_ip 'scp /home/.env username@server:~/Documents/mkppl-si-penilaian-dan-evaluasi-praktikum && ssh user@redacted_ip_address "cd ~/Documents/mkppl-si-penilaian-dan-evaluasi-praktikum && git pull origin staging && docker-compose down && docker-compose build && docker-compose up -d"' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment