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/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}'"
29 changes: 29 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
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:
- ./pinger_data:/var/lib/postgresql/data
angad-k marked this conversation as resolved.
Show resolved Hide resolved
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"