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
19 changes: 15 additions & 4 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 .

# Copy over the agent.yml from Builder image
# COPY --from=builder /go/src/github.com/sdslabs/pinger/agent.yml .
angad-k marked this conversation as resolved.
Show resolved Hide resolved

# Final command to run pinger
CMD [ "./pinger", "version" ]
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
2 changes: 1 addition & 1 deletion build/docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,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}'"
11 changes: 11 additions & 0 deletions deploy/pinger.apache.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Listen 80
<VirtualHost *:80>
ServerName pinger.staging.sdslabs.* pinger.sdslabs.*
angad-k marked this conversation as resolved.
Show resolved Hide resolved
# 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
14 changes: 11 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,15 @@ 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`

## 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, replace
`CMD [ "./pinger", "version" ]` in the `Dockerfile` with `CMD [ "./pinger", "agent" ]`
angad-k marked this conversation as resolved.
Show resolved Hide resolved
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