mirror of
https://github.com/kerberos-io/agent.git
synced 2026-08-23 15:08:32 +00:00
Add support for cross-compilation in Docker workflows and create Darwin binary
This commit is contained in:
33
.github/workflows/docker.yml
vendored
33
.github/workflows/docker.yml
vendored
@@ -54,7 +54,7 @@ jobs:
|
||||
with:
|
||||
name: agent-${{matrix.architecture}}.tar
|
||||
path: agent-${{matrix.architecture}}.tar
|
||||
|
||||
|
||||
build-arm64:
|
||||
runs-on: ubuntu-24.04-arm
|
||||
permissions:
|
||||
@@ -92,9 +92,38 @@ jobs:
|
||||
name: agent-${{matrix.architecture}}.tar
|
||||
path: agent-${{matrix.architecture}}.tar
|
||||
|
||||
build-darwin:
|
||||
runs-on: ubuntu-24.04
|
||||
permissions:
|
||||
contents: write
|
||||
strategy:
|
||||
matrix:
|
||||
architecture: [amd64, arm64]
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v2
|
||||
- name: Build Darwin binary with Docker
|
||||
run: |
|
||||
docker build -f Dockerfile.cross \
|
||||
--build-arg GOOS=darwin \
|
||||
--build-arg GOARCH=${{matrix.architecture}} \
|
||||
-t darwin-${{matrix.architecture}} .
|
||||
CID=$(docker create darwin-${{matrix.architecture}})
|
||||
docker cp ${CID}:/home/agent ./output-${{matrix.architecture}}
|
||||
docker rm ${CID}
|
||||
- name: Tar Darwin binary and clean
|
||||
run: tar -cf agent-darwin-${{matrix.architecture}}.tar -C output-${{matrix.architecture}} . && rm -rf output-${{matrix.architecture}}
|
||||
- name: Upload darwin artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: agent-darwin-${{matrix.architecture}}.tar
|
||||
path: agent-darwin-${{matrix.architecture}}.tar
|
||||
|
||||
create-manifest:
|
||||
runs-on: ubuntu-24.04
|
||||
needs: [build-amd64, build-arm64]
|
||||
needs: [build-amd64, build-arm64, build-darwin]
|
||||
steps:
|
||||
- name: Login to DockerHub
|
||||
uses: docker/login-action@v2
|
||||
|
||||
55
Dockerfile.cross
Normal file
55
Dockerfile.cross
Normal file
@@ -0,0 +1,55 @@
|
||||
# Multi-platform build Dockerfile with GOOS/GOARCH arguments
|
||||
ARG GOOS=linux
|
||||
ARG GOARCH=amd64
|
||||
ARG BASE_IMAGE_VERSION=amd64-ddbe40e
|
||||
|
||||
# Use golang official image for cross-compilation
|
||||
FROM golang:1.24-alpine AS build-machinery
|
||||
LABEL AUTHOR=uug.ai
|
||||
|
||||
ARG GOOS
|
||||
ARG GOARCH
|
||||
|
||||
ENV CGO_ENABLED=0
|
||||
ENV GOOS=${GOOS}
|
||||
ENV GOARCH=${GOARCH}
|
||||
ENV GOSUMDB=off
|
||||
|
||||
##########################################
|
||||
# Installing some additional dependencies.
|
||||
|
||||
RUN apk add --no-cache git build-base
|
||||
|
||||
##############################################################################
|
||||
# Copy all the relevant source code in the Docker image, so we can build this.
|
||||
|
||||
WORKDIR /go/src/github.com/kerberos-io/agent
|
||||
COPY machinery ./machinery
|
||||
RUN rm -rf ./machinery/.env
|
||||
|
||||
##################################################################
|
||||
# Get the latest commit hash, so we know which version we're running
|
||||
COPY .git ./.git
|
||||
RUN cd .git && git log --format="%H" -n 1 | head -c7 > ../machinery/version
|
||||
RUN cat ./machinery/version
|
||||
|
||||
##################
|
||||
# Build Machinery
|
||||
|
||||
RUN cd machinery && \
|
||||
go mod download && \
|
||||
go build -tags timetzdata,netgo,osusergo --ldflags '-s -w' -o agent main.go && \
|
||||
mkdir -p /agent && \
|
||||
mv agent /agent/ && \
|
||||
mv version /agent/ && \
|
||||
cp -r data /agent/ && \
|
||||
mkdir -p /agent/data/cloud && \
|
||||
mkdir -p /agent/data/snapshots && \
|
||||
mkdir -p /agent/data/log && \
|
||||
mkdir -p /agent/data/recordings && \
|
||||
mkdir -p /agent/data/capture-test && \
|
||||
mkdir -p /agent/data/config
|
||||
|
||||
# Final stage - minimal runtime
|
||||
FROM scratch
|
||||
COPY --from=build-machinery /agent /home/agent
|
||||
61
Dockerfile.cross-alt
Normal file
61
Dockerfile.cross-alt
Normal file
@@ -0,0 +1,61 @@
|
||||
# Alternative: Modify existing Dockerfile to support cross-compilation
|
||||
ARG BASE_IMAGE_VERSION=amd64-ddbe40e
|
||||
ARG GOOS=linux
|
||||
ARG GOARCH=amd64
|
||||
|
||||
FROM kerberos/base:${BASE_IMAGE_VERSION} AS build-machinery
|
||||
LABEL AUTHOR=uug.ai
|
||||
|
||||
ARG GOOS
|
||||
ARG GOARCH
|
||||
|
||||
ENV GOROOT=/usr/local/go
|
||||
ENV GOPATH=/go
|
||||
ENV PATH=$GOPATH/bin:$GOROOT/bin:/usr/local/lib:$PATH
|
||||
ENV GOSUMDB=off
|
||||
ENV GOOS=${GOOS}
|
||||
ENV GOARCH=${GOARCH}
|
||||
|
||||
# For cross-compilation, disable CGO when building for different platforms
|
||||
# Enable CGO only for native linux builds
|
||||
ENV CGO_ENABLED=0
|
||||
|
||||
##########################################
|
||||
# Installing some additional dependencies.
|
||||
|
||||
RUN apt-get upgrade -y && apt-get update && apt-get install -y --fix-missing --no-install-recommends \
|
||||
git build-essential cmake pkg-config unzip libgtk2.0-dev \
|
||||
curl ca-certificates libcurl4-openssl-dev libssl-dev libjpeg62-turbo-dev && \
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
|
||||
##############################################################################
|
||||
# Copy all the relevant source code in the Docker image, so we can build this.
|
||||
|
||||
RUN mkdir -p /go/src/github.com/kerberos-io/agent
|
||||
COPY machinery /go/src/github.com/kerberos-io/agent/machinery
|
||||
RUN rm -rf /go/src/github.com/kerberos-io/agent/machinery/.env
|
||||
|
||||
##################################################################
|
||||
# Get the latest commit hash, so we know which version we're running
|
||||
COPY .git /go/src/github.com/kerberos-io/agent/.git
|
||||
RUN cd /go/src/github.com/kerberos-io/agent/.git && git log --format="%H" -n 1 | head -c7 > /go/src/github.com/kerberos-io/agent/machinery/version
|
||||
RUN cat /go/src/github.com/kerberos-io/agent/machinery/version
|
||||
|
||||
##################
|
||||
# Build Machinery
|
||||
|
||||
RUN cd /go/src/github.com/kerberos-io/agent/machinery && \
|
||||
go mod download && \
|
||||
go build -tags timetzdata,netgo,osusergo --ldflags '-s -w' -o main main.go && \
|
||||
mkdir -p /agent && \
|
||||
mv main /agent && \
|
||||
mv version /agent && \
|
||||
mv data /agent && \
|
||||
mkdir -p /agent/data/cloud && \
|
||||
mkdir -p /agent/data/snapshots && \
|
||||
mkdir -p /agent/data/log && \
|
||||
mkdir -p /agent/data/recordings && \
|
||||
mkdir -p /agent/data/capture-test && \
|
||||
mkdir -p /agent/data/config
|
||||
|
||||
# Continue with the rest of your existing Dockerfile...
|
||||
Reference in New Issue
Block a user