The open-telemetry/opentelemetry-dotnet project does not currently have a CI/CD workflow set up. However, the addition of a CI/CD pipeline can greatly enhance the efficiency and reliability of the deployment processes for this project. Below are suggested next steps and detailed examples demonstrating how to set up a CI/CD workflow using common tools.

Next Steps to Set Up CI/CD

  1. Choose a CI/CD Platform: Select a CI/CD service such as GitHub Actions, Azure Pipelines, GitLab CI, Travis CI, or CircleCI based on your preferences and infrastructure.

  2. Create CI Configuration: Write configurations for building and testing the application. For example, if using GitHub Actions, create a .github/workflows/ci.yml file.

  3. Integrate Docker Builds: Since the project uses Docker, configure your pipeline to build Docker images using the provided Dockerfile and docker-compose.yml.

  4. Configure Deployment Steps: If applicable, decide on the deployment strategy for your application, including staging and production environments.

  5. Add Testing Stages: Incorporate stages for running unit and integration tests as part of your CI pipeline.

Example: GitHub Actions Configuration

Below is an example of a GitHub Actions workflow that builds the Docker images for both the web API and worker service defined in docker-compose.yml and runs tests:

Create a file at .github/workflows/ci.yml with the following content:

name: CI Pipeline

on:
  push:
    branches:
      - main
  pull_request:
    branches:
      - main

jobs:
  build:
    runs-on: ubuntu-latest

    services:
      zipkin:
        image: openzipkin/zipkin
        ports:
          - 9411:9411

      rabbitmq:
        image: rabbitmq:3-management-alpine
        ports:
          - 5672:5672
          - 15672:15672

    steps:
      - name: Checkout Code
        uses: actions/checkout@v2

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

      - name: Build Docker Images
        run: |
          docker-compose -f docker-compose.yml build

      - name: Publish Worker Service
        run: |
          docker run --rm \
            -v ${{ github.workspace }}:/app \
            -w /app/examples/MicroserviceExample/WorkerService \
            mcr.microsoft.com/dotnet/sdk:8.0 \
            dotnet publish -c Release -o out -p:IntegrationBuild=true

      - name: Run Tests
        run: |
          docker run -v ${{ github.workspace }}:/app \
          mcr.microsoft.com/dotnet/sdk:8.0 \
          dotnet test /app/tests/*.csproj

Example: Dockerfile for Worker Service

The Dockerfile should look as follows:

ARG SDK_VERSION=8.0
FROM mcr.microsoft.com/dotnet/sdk:${SDK_VERSION} AS build
ARG PUBLISH_CONFIGURATION=Release
ARG PUBLISH_FRAMEWORK=net8.0
WORKDIR /app
COPY . ./
RUN dotnet publish ./examples/MicroserviceExample/WorkerService -c "${PUBLISH_CONFIGURATION}" -f "${PUBLISH_FRAMEWORK}" -o /out -p:IntegrationBuild=true

FROM mcr.microsoft.com/dotnet/aspnet:${SDK_VERSION} AS runtime
WORKDIR /app
COPY --from=build /out ./
ENTRYPOINT ["dotnet", "WorkerService.dll"]

Example: Running Docker Compose

The docker-compose.yml file provides a straightforward method to set up both the web API and the worker service along with dependencies:

version: '3.8'

services:
  zipkin:
    image: openzipkin/zipkin
    ports:
      - 9411:9411

  rabbitmq:
    image: rabbitmq:3-management-alpine
    ports:
      - 5672:5672
      - 15672:15672

  webapi:
    build:
      context: ../..
      dockerfile: ./examples/MicroserviceExample/WebApi/Dockerfile
    image: opentelemetry-example-webapi
    environment:
      - ASPNETCORE_ENVIRONMENT=Development
      - RABBITMQ_HOSTNAME=rabbitmq
      - RABBITMQ_DEFAULT_USER=guest
      - RABBITMQ_DEFAULT_PASS=guest
      - ZIPKIN_HOSTNAME=zipkin
    ports:
      - 5000:5000
    depends_on:
      - rabbitmq
      - zipkin

  workerservice:
    build:
      context: ../..
      dockerfile: ./examples/MicroserviceExample/WorkerService/Dockerfile
    image: opentelemetry-example-workerservice
    environment:
      - DOTNET_ENVIRONMENT=Development
      - RABBITMQ_HOSTNAME=rabbitmq
      - RABBITMQ_DEFAULT_USER=guest
      - RABBITMQ_DEFAULT_PASS=guest
      - ZIPKIN_HOSTNAME=zipkin
    restart: on-failure
    depends_on:
      - rabbitmq
      - zipkin

These examples provide a solid foundation for setting up a CI/CD workflow with the open-telemetry/opentelemetry-dotnet project, focusing on Docker image builds and tests within a GitHub Actions framework. Adjust as needed based on specific requirements or integration with other CI/CD platforms.

To learn more about GitHub Actions, refer to the official documentation: https://docs.github.com/en/actions.

To further explore Docker in CI/CD, check the Docker documentation: https://docs.docker.com/ci-cd/.