Skip to content
Merged
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
35 changes: 35 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: CI

on:
push:
paths-ignore:
- '**.md'
- 'extra/**'
- 'capture/**'
- 'ansible/**'
- 'dashboards/**'
- 'scripts/**'
- '.gitignore'
- 'LICENSE'
branches:
- master

env:
ghcr_repo_addr: ghcr.io/shayan-ghani/container-exporter:latest

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: deploy from ghcr
run: |
IMAGE=${{env.ghcr_repo_addr}} docker compose -f ./container-exporter.yml up -d
55 changes: 49 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ permissions:

env:
ghcr_repo_addr: ghcr.io/shayan-ghani/container-exporter:latest
docker_repo_addr: shayanghani/container-exporter:latest
docker_hub_user: shayanghani

jobs:

Expand All @@ -38,10 +40,18 @@ jobs:
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4

- name: Login to GHCR
run: |
echo ${{ secrets.GHCR_TOKEN }} | docker login ghcr.io -u ${{ github.repository_owner }} --password-stdin
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ env.docker_hub_user }}
password: ${{ secrets.DOCKER_TOKEN }}

- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GHCR_TOKEN }}

- name: Set up QEMU
uses: docker/setup-qemu-action@v3
Expand All @@ -54,16 +64,49 @@ jobs:
with:
context: .
push: true
tags: ${{env.ghcr_repo_addr}}
tags: |
${{env.ghcr_repo_addr}}
${{env.docker_repo_addr}}



healthcheck:
runs-on: ubuntu-latest
needs: docker-build
steps:
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4

- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GHCR_TOKEN }}

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: deploy from ghcr
run: |
IMAGE=${{env.ghcr_repo_addr}} docker compose -f ./container-exporter.yml up -d

- name: check metrics api and print out metrics
run: |
bash ./scripts/healthcheck-ci.sh


# test:

# ## pytest to be implemented here ...

release:
if: github.event_name != 'pull_request'
if: github.event_name != 'pull_request' && github.ref_name == 'master'
runs-on: ubuntu-latest
needs: docker-build
needs: healthcheck
steps:
-
name: Bump version and push tag
Expand Down
53 changes: 53 additions & 0 deletions .github/workflows/dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: CI

on:
push:
paths-ignore:
- '**.md'
- 'extra/**'
- 'capture/**'
- 'ansible/**'
- 'dashboards/**'
- 'scripts/**'
- '.gitignore'
- 'LICENSE'
branches:
- dev
- ci
pull_request:
paths-ignore:
- 'extra/**'
- 'capture/**'
- 'ansible/**'
- 'dashboards/**'
- 'scripts/**'
- '.gitignore'
- 'LICENSE'

permissions:
contents: write
pull-requests: read

env:
ghcr_repo_addr: ghcr.io/shayan-ghani/container-exporter:latest

jobs:
probe:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: deploy
run: |
docker compose -f ./container-exporter-local.yml up --build -d

- name: check for metrics and overall api health
run: |
bash ./scripts/healthcheck-ci.sh
9 changes: 7 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,15 @@ WORKDIR /opt/src

COPY requirements.txt .

RUN pip install --no-cache-dir -r requirements.txt
RUN pip install --no-cache-dir -r requirements.txt \
&& apt-get update && apt-get install -y --no-install-recommends curl \
&& rm -rf /var/lib/apt/lists/*

COPY . .

CMD "./start.sh" $CONTAINER_EXPORTER_PORT
RUN chmod +x /opt/src/scripts/healthcheck.sh

HEALTHCHECK --interval=30s --timeout=5s --start-period=5s --retries=2 \
CMD /opt/src/scripts/healthcheck.sh

CMD ["./start.sh"]
2 changes: 0 additions & 2 deletions container-exporter-local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ services:
container_name: container-exporter
volumes:
- /var/run/docker.sock:/var/run/docker.sock
environment:
CONTAINER_EXPORTER_PORT: ${CONTAINER_EXPORTER_PORT}
ports:
- 8000:8000
restart: always
4 changes: 1 addition & 3 deletions container-exporter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ version: !!str 3.7

services:
cxp:
image: devopsteen/cxp:latest # use alpine tag for a lighter image
image: "${IMAGE:-shayanghani/container-exporter:latest}"
container_name: container-exporter
volumes:
- /var/run/docker.sock:/var/run/docker.sock
ports:
- 8000:8000
environment:
CONTAINER_EXPORTER_PORT: ${CONTAINER_EXPORTER_PORT}
restart: always
26 changes: 26 additions & 0 deletions scripts/healthcheck-ci.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

log_dir="/opt/src/logs"
mkdir -p $log_dir

for i in 1 2
do
sleep 5

if ! curl http://localhost:8000/ > "${log_dir}/index.txt"; then
echo "Port 8000 not responding"
exit 1
fi


if ! curl --max-time 6 --silent --show-error http://localhost:8000/metrics > "${log_dir}/metrics.txt"; then
echo "/metrics endpoint not responding"
exit 1
fi

echo -e "METRICS : \n\n"
cat "${log_dir}/metrics.txt" | grep 'container_name' | sort | uniq
done


exit 0
21 changes: 21 additions & 0 deletions scripts/healthcheck.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

log_dir="/opt/src/logs"
mkdir -p $log_dir


if ! curl http://localhost:8000/ > "${log_dir}/index.txt"; then
echo "Port 8000 not responding"
exit 1
fi


if ! curl --max-time 6 --silent --show-error http://localhost:8000/metrics > "${log_dir}/metrics.txt"; then
echo "/metrics endpoint not responding"
exit 1
fi

echo -e "METRICS : \n\n"


exit 0