Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docker: Add docker-compose.yml and modify Dockerfile #109

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ jobs:
run: make docker TAG="pinger:dev"

- name: Run container
run: docker run --rm pinger:dev
run: docker run --rm pinger:dev ./pinger version

proto:
name: Protobuf
Expand Down
21 changes: 16 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,24 +1,35 @@
# Build Pinger binary

# Use the golang image for building the binary
FROM golang:1.16.0-alpine3.13 AS builder

# Set the work directory
WORKDIR /go/src/github.com/sdslabs/pinger

# Copy over the source code to the container
COPY . .

ARG vers

# Install bash and make
RUN apk update && \
apk add make && \
apk add bash
RUN make build VERSION=$vers

# Build the actual binary
RUN make build VERSION=1.0

# Copy binary into actual image

FROM alpine:3.12.0
# Use the alpine image for running the binary
FROM alpine:3.13

# Set the work directory
WORKDIR /go/bin

# Copy over the binary from Builder image
COPY --from=builder /go/src/github.com/sdslabs/pinger/pinger .

CMD [ "./pinger", "version" ]
# Copy over the agent.yml from Builder image
COPY --from=builder /go/src/github.com/sdslabs/pinger/agent.yml .

# Final command to run pinger
CMD [ "./pinger", "agent" ]
35 changes: 35 additions & 0 deletions agent.sample.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# agent.yml

# We need to tell Pinger to run the agent in standalone mode since the
# default behaviour is something else.
standalone: true

# Configuration for where metrics are stored.
metrics:
backend: timescale
host: timescale
port: 5432
username: postgres
password: password
db_name: pinger
angad-k marked this conversation as resolved.
Show resolved Hide resolved
Comment on lines +13 to +14
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use env variables here as we discussed with viper

ssl_mode: false # Let's just keep it off for now
page:
deploy: true
allowed_origins: ["*"] # For now allow every origin
name: My Status Page

# Interval after which metrics are logged into database.
interval: 5s

checks:
- id: ping-google # unique ID
name: Ping Google # human-readable name
interval: 5s # Ping every 5 seconds
timeout: 0.5s # Timeout if it takes longer than half a second
input:
type: HTTP # Protocol
output:
type: TIMEOUT # Condition for success/failure
target: # Target to hit/request
type: URL
value: http://www.google.com/
2 changes: 1 addition & 1 deletion build/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ BIN_NAME="pinger"
# set the default version to undefined
if [ -z ${VERSION} ]
then
CURRENT_TAG="undefined"
CURRENT_TAG="dev"
else
CURRENT_TAG="${VERSION}"
fi
Expand Down
8 changes: 7 additions & 1 deletion build/docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ source ./build/util.sh
set -e
set -x

FILE=./agent.yml

if [ ! -f "$FILE" ]; then
cp agent.sample.yml agent.yml
fi

# If a tag is not specified, set the tag to "pinger:dev"
if [ -z "${TAG}" ]
then
Expand All @@ -15,6 +21,6 @@ fi
VERSION=$(echo $TAG | cut -d':' -f 2)

# Build the image using the tag.
docker build -t "${TAG}" --build-arg vers="${VERSION}" .
docker build -t "${TAG}" .

finally "Built image with tag '${TAG}'"
12 changes: 12 additions & 0 deletions deploy/pinger.apache.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Listen 80
<VirtualHost *:80>
ServerName pinger.staging.sdslabs.*
angad-k marked this conversation as resolved.
Show resolved Hide resolved
ServerAlias pinger.sdslabs.*
# Other directives here
<Location />
ProxyPass http://127.0.0.1:9010
ProxyPassReverse http://127.0.0.1:9010
Order allow,deny
Allow from all
</Location>
</VirtualHost>
19 changes: 19 additions & 0 deletions deploy/pinger.nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
server {
listen 80;
server_name pinger.staging.sdslabs.* pinger.sdslabs.*;

location / {
client_max_body_size 20M;
proxy_pass http://127.0.0.1:9010;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_read_timeout 86400;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $host:$server_port;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $host:$server_port;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-Port $server_port;
}
}
37 changes: 37 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
version: "3"

services:
adrijshikhar marked this conversation as resolved.
Show resolved Hide resolved
# Timescale DB is used to store the metrics
timescale:
image: timescale/timescaledb:2.0.0-pg12
# Setting environment variables for Timescale
environment:
POSTGRES_PASSWORD: "password"
POSTGRES_DB: "pinger"
# Healthcheck conditions are defined since pinger service needs to know if Timescale has started
# pg_isready is a binary that is available with the postgres image(timescale is built upon postgres)
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 5s
timeout: 5s
retries: 5
# Mapping the volume to make it persistent
volumes:
- db_data:/var/lib/postgresql/data
pinger:
# Depends on timescale and condition will be true when timescale can accept connections
depends_on:
timescale:
condition: service_healthy
build: ./
# PINGER_PORT is the port on the host machine where the service will be available. Set it through .env
ports:
- "${PINGER_PORT:-9010}:9010"
# Specifies the default network to be pinger
networks:
default:
name: pinger
# Specifies the volume to be used to store the db data
volumes:
db_data:
name: pinger-data
13 changes: 10 additions & 3 deletions docs/src/contributing/build-process.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ required for the frontend. Once we have our resources ready, we can build the
executable using the `make build` command. We have `VERSION` flag for setting
the version of the binary.

> **Note:** In case no `VERSION` is provided, version defaults to `dev`

```sh
# Building the binary
$ make build VERSION=1.0.1
Expand Down Expand Up @@ -57,9 +59,14 @@ command.
$ make docker TAG="pinger:v1.2.3"
```

> **Note:** In case of docker image, version is extracted from the tag.
>For example: in the aforementioned case, version of the binary will
>set to `v1.2.3`.
> **Note:** In case of docker image, version defaults to `1.0`
> **Note:** In case no `agent.yml` is provided, `agent.sample.yml` will be copied to `agent.yml`

## Docker Compose

A `docker-compose.yml` is also provided to get pinger started more easier.
Just add an `agent.yml` according to your use case and then run `docker-compose up`.
This will get both the timescale db and pinger container up and running in no time!

## Documentation

Expand Down