CI/CD Workflow for screenly/balena-prometheus-exporter
Overview
Currently, a CI/CD workflow is not set up for the screenly/balena-prometheus-exporter project. To implement a CI/CD pipeline, here are the proposed next steps.
Suggested Next Steps
Choose a CI/CD Platform: Select a CI/CD service such as GitHub Actions, GitLab CI, CircleCI, or Travis CI.
Create Configuration Files: Depending on the chosen platform, create the necessary configuration files that define the workflow.
Set Up Environment Variables: Ensure that sensitive information, such as
BALENA_TOKEN
, is set as an environment variable in the CI/CD environment.Define Build and Deploy Steps: Establish the steps required to build, test, and deploy the application using the Docker container specified in the Dockerfile.
Example CI/CD Configuration
Below is an example configuration using GitHub Actions.
File: .github/workflows/ci.yml
name: CI/CD Pipeline
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.10
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Build Docker image
run: |
docker build -t balena-exporter .
- name: Run tests
run: |
python -m unittest discover -s tests
- name: Push Docker image
run: |
echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin
docker tag balena-exporter yourusername/balena-exporter:latest
docker push yourusername/balena-exporter:latest
Explanation of the Configuration
Trigger: The workflow triggers on push and pull request actions to the
main
branch.Jobs: The job
build
runs on the latest Ubuntu virtual environment.Steps:
- Checkout code: This step checks out the repository code.
- Set up Python: It sets up Python 3.10.
- Install dependencies: Installs the required Python packages specified in
requirements.txt
. - Build Docker image: Builds the Docker image using the provided Dockerfile.
- Run tests: Executes the tests located in the
tests
directory. - Push Docker image: Authenticates with Docker Hub and pushes the newly built image.
Environment Variables
Ensure that the following environment variables are set in the CI/CD platform’s settings:
BALENA_TOKEN
: Required for authentication against the Balena API.DOCKER_USERNAME
: Docker Hub username for pushing images.DOCKER_PASSWORD
: Docker Hub password for authentication.
By following these steps, a basic CI/CD workflow for the screenly/balena-prometheus-exporter can be established, leading to improved development speed and reliability.