From 8b75f909f7a4f3517403a6655eb61c29965fb6fa Mon Sep 17 00:00:00 2001 From: Yvonnick Esnault Date: Sat, 29 Apr 2017 10:54:15 +0200 Subject: [PATCH] chore (*): docker-compose (#579) * chore: docker-compose file Signed-off-by: Yvonnick Esnault * doc: title Signed-off-by: Yvonnick Esnault * Update run-with-docker-compose.md * chore: use caddy built from master Signed-off-by: Yvonnick Esnault --- doc/overview/introduction.md | 14 ++- doc/tutorials/run-with-docker-compose.md | 72 +++++++++++++++ docker-compose.yml | 112 +++++++++++++++++++++++ ui/Dockerfile | 3 +- 4 files changed, 191 insertions(+), 10 deletions(-) create mode 100644 doc/tutorials/run-with-docker-compose.md create mode 100644 docker-compose.yml diff --git a/doc/overview/introduction.md b/doc/overview/introduction.md index 9a605358dc..82a53ca7cf 100644 --- a/doc/overview/introduction.md +++ b/doc/overview/introduction.md @@ -1,13 +1,13 @@ ## What is CDS? CDS is a Continuous Delivery solution with an architecture featuring: - + * A complete isolation between tenants * High availability oriented architecture * Automatic scaling * Automation oriented with iso-feature API, CLI and WebUI -Designed for scalability, CDS tasks can run either on cloud infrastructure or on your own machines, should you start some workers using a [hatchery](/doc/overview/hatchery.md). +Designed for scalability, CDS tasks can run either on cloud infrastructure or on your own machines, should you start some workers using a [hatchery](/doc/overview/hatchery.md). CDS exposes an API available to [workers](/doc/overview/worker.md) and humans through cli or WebUI. @@ -33,7 +33,7 @@ An application is composed of one or multiple pipelines, that can be triggered: * Declaration of worker models (specific hosts, docker image, openstack recipe) * Conditional build path depending of build parameters (ie: git branch) -### Deployment +### Deployment * Completely cross platform workers (built in Go) without any dependency * Support for deployment environments (different sets of variable for the same deployment pipeline) @@ -58,17 +58,14 @@ On this view, you can see how an application attaches pipelines and environment ### Action requirements and worker capabilities -CDS is built on simples principes: +CDS is built on simples principles: * Any client operation is an Action and has requirements. * Every worker registered has capabilities and build if and only if all requirements are met. - ![Action and Workers](/doc/img/action-worker.png) - -Relation between workers and actions. - +Relation between workers and actions. ### Harness PaaS with worker models and [hatcheries](/doc/overview/hatchery.md) @@ -93,4 +90,5 @@ We wanted a CD ecosystem where workers are easy to setup anywhere. ## Next Steps + * [Run with Docker-Compose](/doc/tutorials/run-with-docker-compose.md) * [Quick start](/doc/overview/quickstart.md) diff --git a/doc/tutorials/run-with-docker-compose.md b/doc/tutorials/run-with-docker-compose.md new file mode 100644 index 0000000000..7e7cf5ad03 --- /dev/null +++ b/doc/tutorials/run-with-docker-compose.md @@ -0,0 +1,72 @@ +## Run with Docker-Compose + +The [docker-compose.yml](/docker-compose.yml) contains: +- cds-db service with a postgresql +- cds-cache service with a redis +- cds-migrate service to prepare DB tables. +- cds-api service +- cds-ui service +- cds-hatchery-swarm service +- cds-hatchery-local service + +Docker compose is very convenient to launch CDS for testing it. But this is not recommended for a Production Installation. + +## How to run + +```bash +$ git clone https://github.com/ovh/cds.git +cd cds +export HOSTNAME=$(hostname) + +# Create PG Database +docker-compose up --no-recreate -d cds-db + +# check if db is UP +# check if last log is "LOG: database system is ready to accept connections" +docker-compose logs + +docker-compose up --no-recreate cds-migrate +# You should have this log: "cds_cds-migrate_1 exited with code 0" + +# run last API and UI +docker-compose up cds-api cds-ui + +``` + +Open a browser on http://localhost:2015, then register a new user. +As there is no SMTP server configured in docker-compose.yml file, +run `docker-compose logs` to get URL for validate the registration. + +## Prepare Project, Pipeline and Application + +On UI: + +- Create a project +- Create an application, with an void pipeline +- Create a pipeline, with a stage and a job +- Inside job, add a step of type "script" +- In script content, add theses lines: +```bash +#!/bin/bash +set -ex +echo "foo" +sleep 10 +echo "bar" +``` + +## Run Pipeline + +Run pipeline. As you can see now, you pipeline is in "waiting status". You have +to run a CDS Worker or a CDS Hatchery which aims to create workers. + +Let's run an hatchery with docker-compose. Two ways: +- a containers with a hatchery `local`. Workers will be spawn inside this container. +- a containers with a hatchery `swarm`. Each worker will be in their own container. + +If your host expose docker API, you can run `docker-compose up cds-hatchery-swarm` + +Otherwise, you can run `docker-compose up cds-hatchery-local` + +*Running a hatchery "local" in a container is not recommanded. Use this way only for test purpose*. + +After running a Hatchery, your pipeline will be in "Building" status, then "Success" status. diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000000..abecc87c9c --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,112 @@ +version: '3' + +services: + cds-db: + image: postgres:9.6.2 + environment: + POSTGRES_PASSWORD: cds + POSTGRES_USER: cds + + cds-cache: + image: redis:alpine + command: redis-server --requirepass cds + ports: + - "6379:6379" + + cds-migrate: + image: ovhcom/cds-api:latest + command: /app/api-linux-amd64 database upgrade --db-host cds-db --db-user cds --db-password cds --db-name cds --db-sslmode disable --migrate-dir /app/sql + links: + - cds-db + + cds-api: + image: ovhcom/cds-api:latest + command: /app/api-linux-amd64 + volumes: + - cds-artefacts-volume:/app/artefacts + environment: + CDS_VCS_REPOSITORIES_GITHUB_STATUSES_URL_DISABLED: "true" + CDS_VCS_REPOSITORIES_GITHUB_STATUSES_DISABLED: "true" + CDS_VCS_REPOSITORIES_CACHERLOADER_DISABLED: "true" + CDS_VCS_REPOSITORIES_BITBUCKET_STATUSES_DISABLED: "true" + CDS_DB_HOST: cds-db + CDS_DB_PASSWORD: cds + CDS_DB_TIMEOUT: 10000 + CDS_DB_USER: cds + CDS_DB_NAME: cds + CDS_DB_MAXCONN: 40 + CDS_DB_PORT: 5432 + CDS_DB_SSLMODE: disable + CDS_URL_API: ${HOSTNAME}:8081 + CDS_URL_UI: ${HOSTNAME}:8080 + CDS_SMTP_DISABLE: "true" + CDS_SMTP_TLS: "false" + CDS_SMTP_FROM: noreply.cds@foo.cds + CDS_SMTP_HOST: smtp.foo.cds + CDS_SMTP_PORT: 25 + CDS_AUTH_LOCALMODE: session + CDS_AUTH_LDAP_ENABLE: "false" + CDS_AUTH_DEFAULTGROUP: cdsdemo + CDS_LOG_LEVEL: info + CDS_SERVER_HTTP_SESSIONTTL: 600 + CDS_CACHE_TTL: 60 + CDS_CACHE_REDIS_HOST: cds-cache:6379 + CDS_CACHE_REDIS_PASSWORD: cds + CDS_CACHE_MODE: redis + CDS_DIRECTORIES_DOWNLOAD: /app + CDS_VCS_POLLING_DISABLED: "false" + CDS_SERVER_HTTP_PORT: 8081 + CDS_SERVER_GRPC_PORT: 8082 + CDS_SCHEDULERS_DISABLED: "false" + CDS_DIRECTORIES_KEYS: /app/keys + CDS_ARTIFACT_MODE: local + CDS_ARTIFACT_LOCAL_BASEDIR: /app/artefacts + CDS_AUTH_SHAREDINFRA_TOKEN: changeitchangeitchangeitchangeitchangeitchangeitchangeitchangeit + CDS_SERVER_SECRETS_KEY: changeitchangeitchangeitchangeit + ports: + - "8081:8081" + - "8082:8082" + links: + - cds-db + - cds-cache + + cds-ui: + image: ovhcom/cds-ui:latest + environment: + BACKEND_HOST: ${HOSTNAME}:8081 + BASE_URL: / + ports: + - "2015:2015" + links: + - cds-api + + cds-hatchery-swarm: + image: ovhcom/cds-hatchery:latest + command: /app/hatchery-linux-amd64 swarm + environment: + CDS_LOG_LEVEL: notice + CDS_RATIO_SERVICE: 50 + CDS_TOKEN: changeitchangeitchangeitchangeitchangeitchangeitchangeitchangeit + DOCKER_HOST: tcp://${HOSTNAME}:2375 + CDS_API: http://cds-api:8081 + CDS_NAME: ${HOSTNAME}-swarm + CDS_MAX_WORKER: 2 + CDS_MAX_CONTAINERS: 4 + CDS_PROVISION: 0 + CDS_REQUEST_API_TIMEOUT: 120 + links: + - cds-api + + cds-hatchery-local: + image: ovhcom/cds-hatchery:latest + command: /app/hatchery-linux-amd64 local + environment: + CDS_TOKEN: changeitchangeitchangeitchangeitchangeitchangeitchangeitchangeit + CDS_API: http://cds-api:8081 + CDS_NAME: ${HOSTNAME}-local + links: + - cds-api + +volumes: + cds-artefacts-volume: + driver: local diff --git a/ui/Dockerfile b/ui/Dockerfile index e2fb51430c..19c19688d6 100644 --- a/ui/Dockerfile +++ b/ui/Dockerfile @@ -5,8 +5,7 @@ RUN apt-get update && \ LAST_RELEASE=$(curl -s https://api.github.com/repos/ovh/cds/releases | grep tag_name | head -n 1 | cut -d '"' -f 4) && \ curl -s https://api.github.com/repos/ovh/cds/releases | grep ${LAST_RELEASE} | grep browser_download_url | grep 'ui.tar.gz' | cut -d '"' -f 4 | xargs wget && \ tar xzf ui.tar.gz && mv dist/* . && \ - wget https://caddyserver.com/download/linux/amd64 && mv amd64 caddy.tar.gz && \ - tar xzf caddy.tar.gz && \ + wget https://github.com/ovh/cds/releases/download/0.8.0/caddy-linux-amd64 && mv caddy-linux-amd64 caddy && \ chmod +rx caddy setup && \ chown -R nobody:nogroup /app && \ rm -rf /var/lib/apt/lists/*