Skip to content

Commit

Permalink
Enhance multi-arch support, add log rename filter, and resolve OpenSS…
Browse files Browse the repository at this point in the history
…L issues
  • Loading branch information
bardabun committed Nov 17, 2024
1 parent 375bbf8 commit 61d55d7
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 91 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ jobs:
# Build Docker Image
- name: Build Docker Image
run: |
docker build -f Dockerfile.amd64 -t logzio/docker-logs-collector-amd64:latest .
docker buildx build --platform linux/amd64 --load -t logzio/docker-logs-collector:amd64-test .
# Install Docker Compose
- name: Install Docker Compose
Expand Down
15 changes: 5 additions & 10 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,8 @@ on:

jobs:
build-and-push-images:
name: Build and Push Docker Images
name: Build and Push Multi-Arch Docker Image
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
architecture: [amd64, arm64]
steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand All @@ -28,16 +24,15 @@ jobs:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and push image
- name: Build and push multi-arch image
uses: docker/build-push-action@v5
with:
context: .
file: Dockerfile.${{ matrix.architecture }}
platforms: linux/${{ matrix.architecture }}
push: true
platforms: linux/amd64,linux/arm64
tags: |
logzio/docker-logs-collector-${{ matrix.architecture }}:latest
logzio/docker-logs-collector-${{ matrix.architecture }}:${{ github.ref_name }}
logzio/docker-logs-collector:latest
logzio/docker-logs-collector:${{ github.ref_name }}
- name: Logout from Docker Hub
if: always()
Expand Down
29 changes: 21 additions & 8 deletions Dockerfile.amd64 → Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Dockerfile.amd64
# syntax=docker/dockerfile:1

FROM python:3.12.4-slim AS base
FROM python:3.12.4-slim-bullseye AS base

# Install dependencies using apt-get
RUN apt-get update && apt-get install -y --no-install-recommends \
Expand All @@ -15,10 +15,23 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
gdb \
&& rm -rf /var/lib/apt/lists/*

# Create the plugins directory and download the Logz.io plugin
# Define build argument for architecture
ARG TARGETARCH

# Set the plugin URL based on the architecture
ENV LOGZIO_PLUGIN_URL_AMD64=https://github.com/logzio/fluent-bit-logzio-output/raw/master/build/out_logzio-linux.so
ENV LOGZIO_PLUGIN_URL_ARM64=https://github.com/logzio/fluent-bit-logzio-output/raw/master/build/out_logzio-linux-arm64.so

# Determine the correct plugin URL based on TARGETARCH
RUN mkdir -p /fluent-bit/plugins && \
wget -O /fluent-bit/plugins/out_logzio.so \
https://github.com/logzio/fluent-bit-logzio-output/raw/master/build/out_logzio-linux.so
if [ "$TARGETARCH" = "amd64" ]; then \
export LOGZIO_PLUGIN_URL=$LOGZIO_PLUGIN_URL_AMD64; \
elif [ "$TARGETARCH" = "arm64" ]; then \
export LOGZIO_PLUGIN_URL=$LOGZIO_PLUGIN_URL_ARM64; \
else \
echo "Unsupported architecture: $TARGETARCH"; exit 1; \
fi && \
wget -O /fluent-bit/plugins/out_logzio.so $LOGZIO_PLUGIN_URL

# Set working directory
WORKDIR /opt/fluent-bit
Expand All @@ -31,9 +44,9 @@ COPY docker-metadata.lua /fluent-bit/etc/docker-metadata.lua
COPY create_fluent_bit_config.py /opt/fluent-bit/docker-collector-logs/create_fluent_bit_config.py

# Use official Fluent Bit image for Fluent Bit binaries
FROM fluent/fluent-bit:3.1.4 AS fluent-bit
FROM fluent/fluent-bit:1.9.10 AS fluent-bit

# Copy Fluent Bit binary and plugins.conf to the base image
# Copy Fluent Bit binary to the base image
FROM base
COPY --from=fluent-bit /fluent-bit/bin/fluent-bit /usr/local/bin/fluent-bit

Expand All @@ -42,4 +55,4 @@ COPY start.sh /start.sh
RUN chmod +x /start.sh

# Set the entrypoint to run the shell script
ENTRYPOINT ["/start.sh"]
ENTRYPOINT ["/start.sh"]
46 changes: 0 additions & 46 deletions Dockerfile.arm64

This file was deleted.

10 changes: 2 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,11 @@ If you want to ship metrics to Logz.io, see [docker-collector-metrics](https://g
Download the appropriate Docker image for your architecture (amd64 or arm64):

```shell
# For amd64 architecture
docker pull logzio/docker-logs-collector-amd64:latest

# For arm64 architecture
docker pull logzio/docker-logs-collector-arm64:latest
docker pull logzio/docker-logs-collector:latest
```

### 2. Run the container

Replace `<ARCH>` in the image name with either amd64 or arm64 based on your system architecture.

For a complete list of options, see the parameters below the code block.👇

```shell
Expand All @@ -38,7 +32,7 @@ docker run --name docker-logs-collector \
-v /var/run/docker.sock:/var/run/docker.sock:ro \
-v /var/lib/docker/containers:/var/lib/docker/containers \
-e HEADERS="user-agent:logzio-docker-logs" \
logzio/docker-logs-collector-<ARCH>:latest
logzio/docker-logs-collector:latest
```

#### Parameters
Expand Down
22 changes: 7 additions & 15 deletions create_fluent_bit_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,40 +165,32 @@ def generate_filters(config):
return filters

def _get_modify_filters(config):
filters = ""
modify_filters_added = False

# Add additional fields if specified
if config.additional_fields:
fields = config.additional_fields.split(',')
filters += """
filters = """
[FILTER]
Name modify
Match *
Rename log message
"""
# Add additional fields if specified
if config.additional_fields:
fields = config.additional_fields.split(',')
for field in fields:
try:
key, value = field.split(':', 1)
filters += f" Add {key.strip()} {value.strip()}\n"
except ValueError:
print(f"Warning: Skipping invalid additional field '{field}'. Expected format 'key:value'.")
modify_filters_added = True

# Add set fields if specified
if config.set_fields:
if not modify_filters_added:
filters += """
[FILTER]
Name modify
Match *
"""
fields = config.set_fields.split(',')
for field in fields:
try:
key, value = field.split(':', 1)
filters += f" Set {key.strip()} {value.strip()}\n"
except ValueError:
print(f"Warning: Skipping invalid set field '{field}'. Expected format 'key:value'.")

return filters

def _get_output_config(config):
Expand All @@ -210,7 +202,7 @@ def _get_output_config(config):
logzio_url {config.logzio_url}
logzio_type {config.logzio_type}
id {config.output_id}
headers user-agent:logzio-docker-fluentbit-logs
headers user-agent:logzio-docker-collector-logs
"""
if config.headers:
output_config += f" headers {config.headers}\n"
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ services:
LOG_LEVEL: "info"

docker-logs-collector:
image: logzio/docker-logs-collector-amd64:latest
image: logzio/docker-logs-collector:amd64-test
container_name: docker-logs-collector
environment:
- LOGZIO_LOGS_TOKEN=${LOGZIO_LOGS_TOKEN}
Expand Down
2 changes: 0 additions & 2 deletions docker-metadata.lua
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,6 @@ function M.enrich_with_docker_metadata(tag, timestamp, record)

local new_record = record
new_record['docker_container_id'] = container_id
new_record['message'] = record.log
new_record['log'] = nil

local cached_data = M.cache[container_id]
if cached_data == nil or (current_time - cached_data['time'] > M.CACHE_TTL_SEC) then
Expand Down

0 comments on commit 61d55d7

Please sign in to comment.