Refactor Dockerfile to use multi-stage builds for Metricbeat and remove outdated FROM version update step
This commit is contained in:
parent
b6c250540a
commit
b1c50472fb
2 changed files with 31 additions and 4 deletions
|
@ -27,9 +27,6 @@ jobs:
|
|||
username: ${{ vars.PHOENIX_PACKAGE_WRITER_USERNAME }}
|
||||
password: ${{ secrets.PHOENIX_PACKAGE_WRITER_TOKEN }}
|
||||
|
||||
- name: Update Dockerfile FROM version
|
||||
run: sed -i "s|^FROM .\+|FROM docker.elastic.co/beats/metricbeat-oss:${{ env.VERSION }}|" Dockerfile
|
||||
|
||||
- name: Build and push to gitea registry
|
||||
uses: docker/build-push-action@v6
|
||||
with:
|
||||
|
|
32
Dockerfile
32
Dockerfile
|
@ -1,3 +1,33 @@
|
|||
FROM docker.elastic.co/beats/metricbeat-oss:latest
|
||||
# Step 1: Prepare the build environment
|
||||
FROM golang:1.16 AS builder
|
||||
|
||||
# Define the Metricbeat version as a build argument
|
||||
ARG VERSION
|
||||
|
||||
# Install Git to clone the repository
|
||||
RUN apt-get update && apt-get install -y git && apt-get clean
|
||||
|
||||
# Clone the Elastic Beats repository and switch to the specified version
|
||||
WORKDIR /go/src/github.com/elastic/beats
|
||||
RUN git clone https://github.com/elastic/beats.git . && git checkout v${VERSION}
|
||||
|
||||
# Compile Metricbeat for the s390x architecture
|
||||
RUN GOARCH=s390x go build -o metricbeat ./metricbeat
|
||||
|
||||
# Step 2: Build the final image
|
||||
FROM debian:buster-slim
|
||||
|
||||
# Set the working directory
|
||||
WORKDIR /usr/share/metricbeat
|
||||
|
||||
# Copy the Metricbeat binary from the build stage
|
||||
COPY --from=builder /go/src/github.com/elastic/beats/metricbeat .
|
||||
|
||||
# Add a default metricbeat.yml configuration file (customize as needed)
|
||||
COPY metricbeat.yml /usr/share/metricbeat/metricbeat.yml
|
||||
|
||||
# Grant necessary permissions to execute Metricbeat
|
||||
RUN chmod +x /usr/share/metricbeat/metricbeat
|
||||
|
||||
# Define the container's entry point
|
||||
ENTRYPOINT ["/usr/share/metricbeat/metricbeat"]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue