Fakultas Ilmu Komputer UI

Commit 99baf3d3 authored by Dave Nathanael's avatar Dave Nathanael
Browse files

Add missing CI script file

parent 2dfb7a67
Pipeline #29507 failed with stages
in 2 minutes and 34 seconds
image: docker:latest
services:
- docker:dind
before_script:
# Add Docker-compose to Docker image
- apk add --no-cache py-pip
- pip install docker-compose==1.23.2
- docker info
- docker-compose --version
stages:
- test
- build
- deploy
# variables:
# HEROKU_API_KEY: //copy your heroku api key
# HEROKU_STAGING_APP: //copy your heroku staging app name here
# HEROKU_PRODUCTION_APP: //copy your production app name here
# POSTGRES_USER: postgres
# REGISTRY_NAME: registry.gitlab.com/your gitlab project's name
# CONTAINER_IMAGE: REGISTRY_NAME:$CI_BUILD_REF_NAME
# Variables that are needed to be set on GitLab's settings
# REGISTRY_USER : docker hub username
# REGISTRY_PASSWORD : docker hub password
# REGISTRY_REPO_NAME : docker hub repo name
# DATABASE_URL_STAGING
# DATABASE_URL_PRODUCTION
# HEROKU_STAGING_APP
# HEROKU_PRODUCTION_APP
# HEROKU_API_KEY
variables:
REGISTRY_NAME: $REGISTRY_USER/$REGISTRY_REPO_NAME
CONTAINER_IMAGE: $REGISTRY_USER/$REGISTRY_REPO_NAME:$CI_BUILD_REF_NAME
test:
stage: test
script:
- echo "Starting tests"
- docker-compose run web sh -c "coverage run --include="./app/*" manage.py test"
- docker-compose run web sh -c "coverage report -m"
build:
stage: build
script:
- echo "Building the app"
# uncomment below if using gitlab container registry
# - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN registry.gitlab.com
- echo "$REGISTRY_PASSWORD" | docker login -u $REGISTRY_USER --password-stdin
- docker build -t $CONTAINER_IMAGE .
- docker push $CONTAINER_IMAGE
deploy:
stage: deploy
only:
- staging
- master
script:
- echo "Deploying the app"
- >
if [[ "${CI_COMMIT_REF_NAME}" == "staging" ]];
then
DATABASE_URL=$DATABASE_URL_STAGING
HEROKU_APP=$HEROKU_STAGING_APP
elif [[ "${CI_COMMIT_REF_NAME}" == "master" ]];
then
DATABASE_URL=$DATABASE_URL_PRODUCTION
HEROKU_APP=$HEROKU_PRODUCTION_APP
fi
# uncomment below if using gitlab container registry
# - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN registry.gitlab.com
- echo "$REGISTRY_PASSWORD" | docker login -u $REGISTRY_USER --password-stdin
- docker login --username=_ --password=$HEROKU_API_KEY registry.heroku.com
- docker pull $CONTAINER_IMAGE
- docker tag $CONTAINER_IMAGE registry.heroku.com/$HEROKU_APP/web
- docker-compose run -e DATABASE_URL=$DATABASE_URL deploy sh -c "python manage.py migrate"
- docker push registry.heroku.com/$HEROKU_APP/web
- docker run --rm -e HEROKU_API_KEY=$HEROKU_API_KEY wingrunr21/alpine-heroku-cli container:release web --app $HEROKU_APP
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment