Skip to content

Commit 2743b68

Browse files
author
ClaraVnk
committed
Add Docker cron automation with SMTP notifications and timezone support
- Add cron scheduling for automated reports (weekly, daily, optimization) - Include SMTP configuration for email notifications - Add timezone support (TZ environment variable) - Update Dockerfile to install cron and curl dependencies - Add entrypoint script and crontab configuration - Update healthcheck to use curl instead of Python - Remove Python package build workflow (keep Docker only) - Clean up documentation files (move
1 parent adcbb00 commit 2743b68

File tree

14 files changed

+832
-584
lines changed

14 files changed

+832
-584
lines changed

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ logs/
4848
docs/
4949
*.md
5050
!README.md
51+
!docker/*.sh
5152

5253
# CI/CD
5354
.github/

.env.example

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,32 @@ OS_USERNAME=your-username
55
OS_PASSWORD=your-password
66
OS_USER_DOMAIN_NAME=default
77
OS_PROJECT_DOMAIN_NAME=default
8-
# OU
9-
# OS_PROJECT_DOMAIN_ID=your-domain-id
8+
OS_PROJECT_DOMAIN_ID=default
9+
OS_REGION_NAME=RegionOne
1010

1111
# Prometheus Configuration
1212
PROMETHEUS_PORT=8000
1313

14+
# SMTP Configuration (optionnel, pour les notifications par email)
15+
SMTP_SERVER=smtp.gmail.com
16+
SMTP_PORT=587
17+
SMTP_USERNAME=your-email@gmail.com
18+
SMTP_PASSWORD=your-app-password
19+
SMTP_FROM_EMAIL=your-email@gmail.com
20+
SMTP_TO_EMAIL=recipient@example.com
21+
22+
# Timezone
23+
TZ=Europe/Paris
24+
25+
# Cron Schedules (format: minute hour day month weekday)
26+
# Examples:
27+
# 0 8 * * 1 = Every Monday at 8:00 AM
28+
# 0 9 * * * = Every day at 9:00 AM
29+
# */30 * * * * = Every 30 minutes
30+
# 0 */6 * * * = Every 6 hours
31+
CRON_WEEKLY_REPORT=0 8 * * 1
32+
CRON_DAILY_SUMMARY=0 9 * * *
33+
CRON_OPTIMIZATION=0 10 * * *
34+
1435
# Optional: Gnocchi API URLs (comma-separated)
1536
# GNOCCHI_URLS=https://api.pub1.infomaniak.cloud/metric,https://api.pub2.infomaniak.cloud/metric

.github/workflows/README.md

Lines changed: 0 additions & 149 deletions
This file was deleted.

.github/workflows/build.yml

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Build and Publish
1+
name: Build and Publish Docker
22

33
on:
44
push:
@@ -16,44 +16,6 @@ env:
1616
IMAGE_NAME: ${{ github.repository }}
1717

1818
jobs:
19-
build-package:
20-
name: Build Python Package
21-
runs-on: ubuntu-latest
22-
23-
steps:
24-
- name: Checkout code
25-
uses: actions/checkout@v4
26-
27-
- name: Set up Python
28-
uses: actions/setup-python@v5
29-
with:
30-
python-version: '3.11'
31-
32-
- name: Install build dependencies
33-
run: |
34-
python -m pip install --upgrade pip
35-
pip install build twine
36-
37-
- name: Build package
38-
run: python -m build
39-
40-
- name: Check package
41-
run: twine check dist/*
42-
43-
- name: Upload artifacts
44-
uses: actions/upload-artifact@v4
45-
with:
46-
name: python-package
47-
path: dist/
48-
retention-days: 7
49-
50-
- name: Publish to PyPI
51-
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
52-
env:
53-
TWINE_USERNAME: __token__
54-
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
55-
run: twine upload dist/*
56-
5719
build-docker:
5820
name: Build Docker Image
5921
runs-on: ubuntu-latest

Dockerfile

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,28 @@
1-
# Dockerfile pour OpenStack Metrics Collector
1+
# Dockerfile pour OpenStack Toolbox
2+
# Suite complète avec métriques Prometheus + tâches cron automatisées
23
FROM python:3.11-slim
34

45
# Métadonnées
56
LABEL maintainer="loutre@ikmail.com"
6-
LABEL description="OpenStack Metrics Collector - Prometheus Exporter"
7-
LABEL version="1.5.0"
7+
LABEL description="OpenStack Toolbox - Complete Suite with Cron"
8+
LABEL version="1.6.0"
89

910
# Variables d'environnement
1011
ENV PYTHONUNBUFFERED=1
1112
ENV PROMETHEUS_PORT=8000
13+
ENV DEBIAN_FRONTEND=noninteractive
14+
15+
# Installer cron et les dépendances système
16+
RUN apt-get update && \
17+
apt-get install -y --no-install-recommends \
18+
cron \
19+
curl \
20+
&& rm -rf /var/lib/apt/lists/*
1221

1322
# Créer un utilisateur non-root
1423
RUN useradd -m -u 1000 -s /bin/bash openstack && \
15-
mkdir -p /app /config && \
16-
chown -R openstack:openstack /app /config
24+
mkdir -p /app /config /var/log/openstack-toolbox && \
25+
chown -R openstack:openstack /app /config /var/log/openstack-toolbox
1726

1827
# Définir le répertoire de travail
1928
WORKDIR /app
@@ -26,15 +35,25 @@ COPY --chown=openstack:openstack src/ ./src/
2635
RUN pip install --no-cache-dir --upgrade pip && \
2736
pip install --no-cache-dir .
2837

29-
# Changer vers l'utilisateur non-root
30-
USER openstack
38+
# Copier le fichier crontab et le script d'entrypoint
39+
COPY --chown=openstack:openstack docker/crontab /etc/cron.d/openstack-toolbox
40+
COPY --chown=openstack:openstack docker/entrypoint.sh /usr/local/bin/entrypoint.sh
41+
42+
# Configurer les permissions
43+
RUN chmod 0644 /etc/cron.d/openstack-toolbox && \
44+
chmod +x /usr/local/bin/entrypoint.sh && \
45+
crontab -u openstack /etc/cron.d/openstack-toolbox
46+
47+
# Créer le répertoire pour les logs cron
48+
RUN touch /var/log/cron.log && \
49+
chown openstack:openstack /var/log/cron.log
3150

3251
# Exposer le port Prometheus
3352
EXPOSE 8000
3453

3554
# Healthcheck
3655
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
37-
CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:8000/metrics')" || exit 1
56+
CMD curl -f http://localhost:8000/metrics || exit 1
3857

3958
# Point d'entrée
40-
ENTRYPOINT ["python", "-m", "src.openstack_metrics_collector"]
59+
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]

0 commit comments

Comments
 (0)