Created
May 3, 2017 10:35
-
-
Save toanalien/509672efc52e263d6cce381f5c6899e0 to your computer and use it in GitHub Desktop.
split gitlab-ci to multi phase
This file contains hidden or 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
| stages: | |
| - test | |
| - cleanup_test | |
| - staging | |
| - production | |
| - cleanup | |
| - compile_then_push | |
| - restart_ci | |
| before_script: | |
| - sudo apt-get install libpq-dev build-essential autoconf libtool pkg-config python-opengl python-imaging python-pyrex python-pyside.qtopengl idle-python2.7 qt4-dev-tools qt4-designer libqtgui4 libqtcore4 libqt4-xml libqt4-test libqt4-script libqt4-network libqt4-dbus python-qt4 python-qt4-gl libgle3 python-dev libffi-dev g++ libssl-dev libsasl2-dev libldap2-dev xvfb python-pip firefox=45.0.2+build1-0ubuntu1 -y --allow-downgrades | |
| - source /home/gitlab-runner/venv/bin/activate | |
| - docker-compose up --no-recreate -d | |
| test_job: | |
| stage: test | |
| script: | |
| # this configures django application to use attached postgres database that is run on `postgres` host | |
| # export DATABASE_URL=postgres://postgres:@postgres:5432/python-test-app | |
| # - apt-get update -qy | |
| # - apt-get install -y python-dev autoconf g++ build-essential redis-server | |
| # - redis-server | |
| # - redis-server --daemonize yes | |
| # - redis-cli -h redis PING | |
| - echo $USER | |
| - pwd | |
| # - redis-cli -h localhost PING | |
| # - wget https://bootstrap.pypa.io/get-pip.py | |
| # - python get-pip.py | |
| # - apt-get install postgresql-9.4 | |
| # - sudo /etc/init.d/postgresql restart | |
| # - pip install boto | |
| - pip install -r requirements.txt | |
| - xvfb-run py.test . --tb=auto --cov=. | |
| # - docker-compose stop | |
| # - docker-compose rm -f | |
| # - sudo service postgresql restart | |
| cleanup_test_job: | |
| stage: cleanup_test | |
| script: | |
| - sudo pkill -f Firefox | |
| - docker-compose stop | |
| - rm -rf pgdata | |
| - rm -rf rddata | |
| - rm -rf rdconfig | |
| - rm -rf mgdata | |
| when: always | |
| staging_job: | |
| stage: staging | |
| script: | |
| # - apt-get update -qy | |
| # - apt-get install -y ruby-dev | |
| # - gem install dpl | |
| - cp -f ~/settings/dev/local_settings.py ./elms/ | |
| - python manage.py migrate --noinput | |
| - rm ./elms/local_settings.py | |
| - dpl --provider=heroku --app=cloudjet-dev --api-key=$HEROKU_STAGING_API_KEY | |
| only: | |
| - staging | |
| production_job: | |
| stage: production | |
| script: | |
| # - apt-get update -qy | |
| # - apt-get install -y ruby-dev | |
| # - gem install dpl | |
| # - dpl --provider=heroku --app=cloudjet-dev --api-key=$HEROKU_STAGING_API_KEY | |
| - pwd | |
| # - python manage.py migrate --noinput | |
| - python manage.py collectstatic --noinput | |
| heroku run python manage.py migrate -a demoapp | |
| - python scripts/set_version_auto.py | |
| only: | |
| - master | |
| cleanup_job: | |
| stage: cleanup | |
| script: | |
| - sudo pkill -f Firefox | |
| - docker-compose stop | |
| - rm -rf pgdata | |
| - rm -rf rddata | |
| - rm -rf rdconfig | |
| - rm -rf mgdata | |
| when: always | |
| compile_then_push: | |
| stage: compile_then_push | |
| type: deploy | |
| script: | |
| - sudo chown ${USER} ./compile.sh | |
| - chmod a+x compile.sh # run compile.sh | |
| - ./compile.sh | |
| # Push to gitlab | |
| - if [[ ! -d "$HOME/demoapp-deploy" ]]; then git clone git@gitlab.com:cjs/demoapp-deploy.git $HOME/demoapp-deploy/; fi; | |
| - if [[ ! -d "$HOME/git/" ]]; then cp -r $HOME/demoapp-deploy/.git/ $HOME/git/; fi; # copy demoapp-deploy/.git to $HOME/git/ | |
| - rm -rf $HOME/demoapp-deploy # remove $HOME/demoapp-deploy | |
| - cp -r $HOME/git/ ../demoapp_compile/.git/ # copy $HOME/git/ to ../demoapp_compile/.git/ | |
| - cd ../demoapp_compile | |
| - NOW=$(date +"%F-%H-%M") | |
| - git checkout -b $NOW # create a branch name is a date | |
| - git add . # add everything new branch | |
| - git commit -m "Add new version compile $NOW" # commit add to branch | |
| - git push origin $NOW # push data to branch | |
| - rm -rf $HOME/git/ # Remove old git | |
| - cp -r ../demoapp_compile/.git $HOME/git/ # update git information | |
| - rm -rf ../demoapp_compile # remove folder demoapp_compile | |
| only: | |
| - master | |
| restart_ci_job: | |
| stage: restart_ci | |
| script: | |
| - sudo gitlab-ci-multi-runner restart & | |
| - echo $? | |
| when: manual |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment