Skip to content
This repository has been archived by the owner on Sep 12, 2023. It is now read-only.

Added Docker and Docker Compose configuration for AWS Health Exporter #60

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
docker-compose.yaml
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
AWS_ACCESS_KEY_ID=your-access-key-id
AWS_SECRET_ACCESS_KEY=your-secret-access-key
AWS_REGION=us-east-1
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#env variables

.env

# Compiled Object files, Static and Dynamic libs (Shared Objects)
*.o
*.a
Expand Down Expand Up @@ -25,4 +29,4 @@ _testmain.go

aws-health-exporter

.idea
.idea
30 changes: 23 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,28 @@
FROM golang:alpine
# Start from the full Golang image to build the binary
FROM golang:1.20-alpine3.18 as builder

ARG SOURCE_COMMIT
# Define ARG for source commit with default value as N/A
ARG SOURCE_COMMIT=N/A

ADD . /go/src/github.com/Jimdo/aws-health-exporter
WORKDIR /go/src/github.com/Jimdo/aws-health-exporter
# Set the current working directory inside the container
WORKDIR /app

# Download the necessary Go modules
COPY go.mod go.sum ./
RUN go mod download

# Copy the Go source code into the container
COPY . .

# Build the Go application with SOURCE_COMMIT as build argument
RUN DATE=$(date -u '+%Y-%m-%d-%H%M UTC'); \
go install -ldflags="-X 'main.Version=${SOURCE_COMMIT}' -X 'main.BuildTime=${DATE}'" ./...
CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o aws_health_exporter -ldflags="-X 'main.Version=${SOURCE_COMMIT}' -X 'main.BuildTime=${DATE}'" .

# Use the Google Distroless image for the final image
FROM gcr.io/distroless/base

# Copy the binary from builder
COPY --from=builder /app/aws_health_exporter .

ENTRYPOINT [ "/go/bin/aws-health-exporter" ]
EXPOSE 9383
# Run the binary
ENTRYPOINT ["./aws_health_exporter"]
15 changes: 15 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: '3.8'
services:
aws-health-exporter:
env_file:
- .env
build:
context: .
dockerfile: Dockerfile
environment:
- AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}
- AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}
- AWS_REGION=${AWS_REGION}
command: ["--aws.region", "${AWS_REGION}"]
ports:
- 9383:9383