Deploy Sentry with Docker

An easy guide on how to set up Sentry using Docker Compose

Tue, 15 Jan 2019

sentry-banner

Sentry is a an open-source error tracking platform that helps developer to mointor and fix crashes in real time. It supports most popular languages, including but not limited to Java, JavaScript, Node.js, Android, iOS and Python.

For more details, please visit Sentry Introduction that I wrote in previous post.

In this tutorial, we will go through how to set up Sentry via Docker and how to rebuild docker image after installing additional plugin.

Introduction

Sentry Server is written in Python. It uses Django as the web framework. Sentry also relies on the following services:

  • Postgres
  • Redis
  • Memcached

Sentry can be installed via Docker or via Python. We will only cover how to install via Docker in this tutorial.

Prerequisite

Getting Started

  1. Visit Sentry On-Premise Github, and clone the repo to a directory

    git clone --depth=1 https://github.com/getsentry/onpremise.git
  2. Open docker-compose.yml, we are going to customize the services we need.

    version: '3.4'
    
    x-defaults: &defaults
      restart: unless-stopped
      build: .
      depends_on:
        - redis
        - postgres
        - memcached
        #- smtp
    
      environment:
        # Run `docker-compose run web config generate-secret-key`
        # to get the SENTRY_SECRET_KEY value.
        SENTRY_SECRET_KEY: ''
        SENTRY_MEMCACHED_HOST: memcached
        SENTRY_REDIS_HOST: redis
        SENTRY_POSTGRES_HOST: postgres
        SENTRY_EMAIL_HOST: smtp
      volumes:
        - sentry-data:/var/lib/sentry/files
    
    services:
      #smtp:
        #restart: unless-stopped
        #image: tianon/exim4
    
      memcached:
        restart: unless-stopped
        image: memcached:1.4
    
      redis:
        restart: unless-stopped
        image: redis:3.2-alpine
    
      postgres:
        restart: unless-stopped
        image: postgres:9.5
        volumes:
          - sentry-postgres:/var/lib/postgresql/data
    
      web:
        <<: *defaults
        ports:
          - '9000:9000'
    
      cron:
        <<: *defaults
        command: run cron
    
      worker:
        <<: *defaults
        command: run worker
    
    volumes:
        sentry-data:
        sentry-postgres:

    Since we do not want to host a SMTP server by ourselves (will shows you how to set up external SMTP later), so we can comment out all the SMTP related lines.

  3. Build and tag the Docker services. It will pull the required docker images specified in docker-compose.yml and Dockerfile, i.e. redis:3.2-alpine, postgres:9.5, memcached:1.4 and sentry:9.0-onbuild.

    docker-compose build
  4. After finish building the docker images, we have to generate a secrete key for Sentry

    docker-compose run --rm web config generate-secret-key

    Add copy the key to docker-compose.yml in SENTRY_SECRET_KEY.

  5. After we have configured the key, we have to run data migration on the postgres database.

    docker-compose run --rm web upgrade

    In the meantime, there will be interactive prompts to create an admin user account.

  6. Starts all the services in detached mode.

    docker-compose up -d

    By running docker ps, you should see 6 running containers as follows:

    CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
    d746f33fc02c        sentry_worker       "/entrypoint.sh run …"   8 days ago          Up 2 days           9000/tcp                 sentry_worker_1
    9f392974eb82        sentry_cron         "/entrypoint.sh run …"   8 days ago          Up 2 days           9000/tcp                 sentry_cron_1
    288c296596b4        sentry_web          "/entrypoint.sh run …"   8 days ago          Up 2 days           0.0.0.0:9000->9000/tcp   sentry_web_1
    0e2b7144edce        postgres:9.5        "docker-entrypoint.s…"   8 days ago          Up 2 days           5432/tcp                 sentry_postgres_1
    2f1f93436a77        redis:3.2-alpine    "docker-entrypoint.s…"   8 days ago          Up 2 days           6379/tcp                 sentry_redis_1
    ed98daa7e684        memcached:1.4       "docker-entrypoint.s…"   8 days ago          Up 2 days           11211/tcp                sentry_memcached_1
  7. Sentry can now be accessed via localhost:9000

Set up mail server

  1. Edit config.yml, add the corresponding mail server settings:

    ###############
    # Mail Server #
    ###############
    mail.backend: 'smtp'  # Use dummy if you want to disable email entirely
    mail.host: 'smtp.gmail.com'
    mail.port: 587
    mail.username: 'YOUR_EMAIL@gmail.com'
    mail.password: 'EMAIL_PASSWORD'
    mail.use-tls: true
    mail.list-namespace: example.com
    # The email address to send on behalf of
    mail.from: 'YOUR_EMAIL@gmail.com'
  2. You have to stop and remove previous built containers and images

    docker-compose down
  3. Then rebuild, run migrations and restart services

    docker-compose build # Build the services again after updating
    docker-compose run --rm web upgrade # Run new migrations
    docker-compose up -d # Recreate the services

Google SSO

GitHub - getsentry/sentry-auth-google: Google Apps SSO provider for Sentry

  1. Edit requirements.txt, this is the place for specifying dependencies for Python application. Add a new line:

    # Add plugins here
    https://github.com/getsentry/sentry-auth-google/archive/52020f577f587595fea55f5d05520f1473deaad1.zip
  2. Open sentry.conf.py, and add Google SSO into the config file:

    SENTRY_FEATURES['organizations:sso'] = True
    
    if 'GOOGLE_CLIENT_ID' in os.environ:
        GOOGLE_CLIENT_ID = env('GOOGLE_CLIENT_ID')
        GOOGLE_CLIENT_SECRET = env('GOOGLE_CLIENT_SECRET')
  3. Open docker-compose.yml, add add the GOOGLE_CLIENT_ID and GOOGLE_CLIENT_SECRET

    GOOGLE_CLIENT_ID: 'ID_HERE.apps.googleusercontent.com'
    GOOGLE_CLIENT_SECRET: 'SECRET_HERE'
Loading...
Benny O

Benny O