Configuration self-hosted server of development

Recently I have decided create self-hosted software development server. I wanted to collect all software that I use for development in one place. At first I looked to Gitlab, because it includes all that I am need, but it wanted many system resources which I didn’t have. I decided collect environment by parts.

Components

I am need git web service and Gogs perfect choice for it. This open-source git web service was written on Go. It has many options as creating user and organizations, managing private and public repositories.

For continuous integration I selected Drone. It is written on Go too. Drone is very light and working only with docker containers.

For error tracking in my projects I use Sentry.

Deployment

For more simpler deployment and management all software, which is described on top, I wrote docker-compose.yml:

version: '3'

services:    
  postgresql:
    image: postgres:latest
    container_name: postgresql
    restart: always
    environment:
       - POSTGRES_USER=${POSTGRES_USER}
       - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
       - POSTGRES_MULTIPLE_DATABASES=gogs,drone,sentry
    ports:
      - 5432:5432

    volumes:
      - ./docker-postgresql-multiple-databases:/docker-entrypoint-initdb.d
      - /var/lib/postgresql:/var/lib/postgresql
      - /var/lib/postgresql/data:/var/lib/postgresql/data
       
  gogs:
    image: gogs/gogs:latest
    container_name: gogs
    restart: always
    ports:
      - 3000:3000
      - "10022:22"
    volumes:
      - /var/lib/gogs:/data
    depends_on:
       - postgresql

  drone-server:
    image: drone/drone:latest
    container_name: drone_server
    restart: always
    ports:
      - 8000:8000
      - 9000:9000
    volumes:
      - /var/lib/drone:/var/lib/drone/
    environment:
      - DRONE_OPEN=true
      - DRONE_HOST=http://${DRONE_HOST}:8000
      - DRONE_GOGS=true
      - DRONE_GOGS_PRIVATE_MODE=true
      - DRONE_GOGS_URL=https://${GOGS_SERVER}
      - DRONE_SECRET=${DRONE_SECRET}
      - DRONE_DATABASE_DRIVER=postgres
      - DRONE_DATABASE_DATASOURCE=postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@postgresql:5432/drone?sslmode=disable
    depends_on:
      - gogs
      - postgresql
      
  drone-agent:
    image: drone/agent:latest
    container_name: drone_agent
    command: agent
    restart: always
    depends_on:
      - drone-server
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    environment:
      - DRONE_SERVER=drone-server:9000
      - DRONE_SECRET=${DRONE_SECRET}

  registry:
    image: registry:2
    container_name: docker_registry
    restart: always
    ports:
      - 5000:5000
    volumes:
      - /var/registry:/var/lib/registry

  redis:
    image: redis
    container_name: redis
    restart: always

  sentry:
    image: sentry
    container_name: sentry
    restart: always
    ports:
      - 9090:9000
    depends_on:
      - redis
      - postgresql
    environment:
      SENTRY_SECRET_KEY: ${SENTRY_SECRET}
      SENTRY_POSTGRES_HOST: postgresql
      SENTRY_DB_NAME: sentry
      SENTRY_DB_USER: ${POSTGRES_USER}
      SENTRY_DB_PASSWORD: ${POSTGRES_PASSWORD}
      SENTRY_REDIS_HOST: redis

  cron:
    image: sentry
    container_name: sentry_cron
    links:
     - redis
     - postgresql
    command: "sentry run cron"
    environment:
      SENTRY_SECRET_KEY: ${SENTRY_SECRET}
      SENTRY_POSTGRES_HOST: postgresql
      SENTRY_DB_USER: sentry
      SENTRY_DB_PASSWORD: sentry
      SENTRY_REDIS_HOST: redis

  worker:
    image: sentry
    container_name: sentry_worker
    links:
     - redis
     - postgresql
    command: "sentry run worker"
    environment:
      SENTRY_SECRET_KEY: ${SENTRY_SECRET}
      SENTRY_POSTGRES_HOST: postgresql
      SENTRY_DB_USER: sentry
      SENTRY_DB_PASSWORD: sentry
      SENTRY_REDIS_HOST: redis

Important says that for creating multiple databases I use docker-postgresql-multiple-databases plugin for postgresql docker container.

Remark

For correct working drone ci with private repo in gogs, you must insert in your .drone.yml file next part:

clone:
  git:
    image: plugins/git
    depth: 50
    environment:
      - DRONE_NETRC_MACHINE={gogs server address}
      - DRONE_NETRC_USERNAME={secret key of user from drone db}
      - DRONE_NETRC_PASSWORD=x-oauth-basic

Conclusion

After simpler actions we have self-hosted development server. This software set will work on server with 2 Gb RAM, unlike Gitlab.

Полезные ссылки:

  1. Gogs
  2. Drone
  3. Sentry
 
comments powered by Disqus