Skip to content
Snippets Groups Projects
.gitlab-ci.yml 1.22 KiB
Newer Older
Pernille Welle-Watne's avatar
Pernille Welle-Watne committed
stages:
  - build
  - test
Pernille Welle-Watne's avatar
Pernille Welle-Watne committed
  - deploy
variables:
  IMAGE: ${CI_REGISTRY}/${CI_PROJECT_NAMESPACE}/${CI_PROJECT_NAME}
  HEROKU_APP_NAME: safe-meadow-86842

build:
  stage: build
  image: docker:stable
  services:
    - docker:dind
  variables:
    DOCKER_DRIVER: overlay2
  script:
    - docker login -u $CI_REGISTRY_USER -p $CI_JOB_TOKEN $CI_REGISTRY
    - docker pull $IMAGE:build-python || true
    - docker pull $IMAGE:production || true
    - docker build
      --target build-python
      --cache-from $IMAGE:build-python
      --tag $IMAGE:build-python
      --file ./Dockerfile
      "."
    - docker build
      --cache-from $IMAGE:production
      --tag $IMAGE:production
      --file ./Dockerfile
      "."
    - docker push $IMAGE:build-python
    - docker push $IMAGE:production

test:
  stage: test
  image: $IMAGE:production
  services:
    - postgres:latest
  variables:
    POSTGRES_DB: test
    POSTGRES_USER: runner
    POSTGRES_PASSWORD: ""
    DATABASE_URL: postgres://runner@postgres:5432/test
  script:
    - python manage.py test

Pernille Welle-Watne's avatar
Pernille Welle-Watne committed
deploy:
  stage: deploy
  script:
Pernille Welle-Watne's avatar
Pernille Welle-Watne committed
    - apt-get update -qy
    - apt-get install -y ruby-dev
    - gem install dpl
    - dpl --provider=heroku --app=$HEROKU_APP_NAME --api-key=$HEROKU_AUTH_TOKEN