This repository helps you with end to end setup of commonly required services for any project in a quick way (< 1 hr) and at the same time provides you with a standard way to add new services specific to your project.
Common services are as follows:
- Loki - database to store logs
- Prometheus - time series database to store different metrics
- Minio - s3 compatible object storage (e.g., it is used by loki to store old logs)
- Grafana - data visualisation platform (e.g., logs can be viewed here)
- Promtail - used to push local logs to loki
- Cadvisor - exposes container metrics
- Node Exporter - exposes node metrics
- Vault - used for secrets management
- Webhook Server - used to enable cd through an API
- Caddy - used to expose services to end users
- Uptime - used to monitor services
In general every project requires observability, ci/cd pipelines, environment management, etc and these things don't change from project to project. This repository helps standardise setup of these so that separate effort on each project can be minimised.
- A VM with Ubuntu 22.04 (sudo access will be required)
- A wildcard domain mapped to the above VM (if you want to expose service publicly) - e.g.
*.mydomain.com
- Allow public inbound traffic on port 80 and Port 443 on the above VM (if you want to expose service publicly)
- Allow public inbound traffic on port 9000 (if you want to expose deployment webhook publicly)
- Run
sudo apt-get install build-essential
to install essential packages - Run
sudo wget https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 -O /usr/bin/yq && sudo chmod +x /usr/bin/yq
to install yq
- Create a fork of this repository
- Clone the forked repository in the VM
- Create a copy of sample.env file (
cp common/sample.env .env
) - Update the environment variables in the .env file as required
- Create a copy of example docker-compose file (
cp docker-compose.yaml.example docker-compose.yaml
) - Create a copy of example Caddyfile (
cp Caddyfile.example Caddyfile
) - Run
make install-docker
to install docker - Exit out of VM and re-connect to the VM to reflect the latest user changes
- Run
make setup-daemon
to configure the docker daemon - Run
sudo make setup-webhook
to start the webhook service (usekill -9 $(lsof -t -i:9000)
to kill any existing service on 9000 port) - Run
make deploy
to deploy all the services
- Go to Actions tab in the repo and enable actions
- Add
{Environment}_WEBHOOK_PASSWORD
and{Environment}_WEBHOOK_URL
as repository secrets (theEnvironment
here should be in uppercase letters and can be any name that you want to give to environment e.g., DEV)
- Go the Actions tab and open Deploy Service Action from the left bar
- Click on Run workflow and provide environment (this should be same as you used while setting up Action) and the service name you want to deploy
- Run
sudo journalctl -u webhook.service
to view logs
-
Deploy a newly added service or pull and redeploy a service
make deploy [services=<service_name>]
-
Stop a service
make stop [services=<service_name>]
-
Restart a service
make restart [services=<service_name>]
-
Delete a service
make down [services=<service_name>]
Note: Volumes are preserved
-
Pull images
make pull [services=<service_name>]
-
Build images
make build [services=<service_name>]
-
Migrate Volume from localhost to localhost/remote
make migrate-volume
Note
Optional environment variable to tweak behaviour of Makefile:
ENABLE_FORCE_RECREATE
(set this to 1 to enable force recreations of containers every time a service is deployed)DISABLE_ANSI
(set this to 1 to prevent ANSI output from Docker CLI)DISABLE_REMOVE_ORPHANS
(orphan containers are removed by default when your runmake deploy
without <service_name>, set this to 1 to disable this behaviour)DISABLE_PULL
(images are pulled/rebuilt by default (if you provide<service_name>
, image for only that service is pulled/rebuilt) when you runmake deploy [services=<service_name>]
, set this to 1 to disable this behaviour)<service_name>
accepts either one or multiple values separated by spaceENABLE_GIT_PULL
(set this to 1 to automatically pull the latest code from the checked out branch before deploying services)