Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
**/node_modules
**/node_modules
.git
.github
**/*.md
**/*_test.go
43 changes: 10 additions & 33 deletions .github/workflows/multi-agent-docker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:


- name: Checkout Repo
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
token: ${{ secrets.GHCR_TOKEN }}
ssh-key: ${{ secrets.CHECK_AGENT_ACCESS }}
Expand All @@ -64,66 +64,40 @@ jobs:
echo "Available disk space:"
df -h

- name: Set up GOPRIVATE
run: echo "GOPRIVATE=your.private.repo" >> $GITHUB_ENV

# - name: Caching Go Modules and Build Cache
# uses: actions/cache@v3
# with:
# path: |
# ~/.cache/go-build
# ~/go/pkg/mod
# key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}

- name: Set up QEMU
uses: docker/setup-qemu-action@v2
uses: docker/setup-qemu-action@v3

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

- name: Login to Registry
uses: docker/login-action@v2
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GHCR_TOKEN }}

- name: Extract Metadata
id: meta
uses: docker/metadata-action@v4
uses: docker/metadata-action@v5
with:
images: ${{ matrix.agent.image }}

- name: Setting Release Number
run: |
# For workflow_dispatch, always use the tag input
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
echo "RELEASE_VERSION=${{ github.event.inputs.tag }}" >> $GITHUB_ENV
echo "Using manual tag: ${{ github.event.inputs.tag }}"
# For tag push, extract the tag name
elif [[ "${{ github.ref }}" == refs/tags/* ]]; then
echo "RELEASE_VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
echo "Using git tag: ${GITHUB_REF#refs/tags/}"
# Fallback for branch pushes
else
BRANCH=$(echo "${{ github.ref }}" | sed 's|refs/heads/||' | sed 's|/|-|g')
SHA_SHORT=$(echo "${{ github.sha }}" | cut -c1-7)
echo "RELEASE_VERSION=${BRANCH}-${SHA_SHORT}" >> $GITHUB_ENV
echo "Using branch+SHA: ${BRANCH}-${SHA_SHORT}"
fi

# - name: Setting Release Number
# run: |

# TAG_INPUT="${{ github.event.inputs.tag }}"
# echo "Debug: TAG_INPUT = '$TAG_INPUT'"

# if [ -n "${{ github.event.inputs.release_version }}" ]; then
# echo "RELEASE_VERSION=${{ github.event.inputs.release_version }}" >> $GITHUB_ENV
# else
# echo "RELEASE_VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
# fi

- name: Setting Platforms
id: set-platforms
run: |
Expand All @@ -136,15 +110,18 @@ jobs:
fi

- name: Build and Push
uses: docker/build-push-action@v3
uses: docker/build-push-action@v6
with:
context: ./
file: ${{ matrix.agent.dockerfile }}
push: true
platforms: ${{ env.PLATFORMS }}
cache-from: type=gha,scope=${{ matrix.agent.name }}
cache-to: type=gha,scope=${{ matrix.agent.name }},mode=max
secrets: |
GITHUB_TOKEN=${{ secrets.GHCR_TOKEN }}
build-args: |
AGENT_VERSION=${{ env.RELEASE_VERSION }}
GITHUB_TOKEN=${{ secrets.GHCR_TOKEN }}
APP_BINARY=${{ matrix.agent.binary }}
tags: |
${{ matrix.agent.image }}:${{ env.RELEASE_VERSION }}
Expand Down
43 changes: 21 additions & 22 deletions Dockerfiles/DockerfileKube.base
Original file line number Diff line number Diff line change
@@ -1,54 +1,53 @@
# Stage 1: Build Stage
FROM golang:1.24.2 AS build
# Use BUILDPLATFORM so Go compiles natively on the runner's arch (x86_64),
# then cross-compile for TARGETARCH via GOOS/GOARCH — no QEMU needed.
FROM --platform=$BUILDPLATFORM golang:1.24.2 AS build

ARG TARGETARCH
ARG TARGETOS=linux
ARG GITHUB_TOKEN

Check warning on line 8 in Dockerfiles/DockerfileKube.base

View workflow job for this annotation

GitHub Actions / Build & Push Docker Images (Matrix) (synthetics, mw-synthetics, Dockerfiles/DockerfileKube.base, ...

Sensitive data should not be used in the ARG or ENV commands

SecretsUsedInArgOrEnv: Do not use ARG or ENV instructions for sensitive data (ARG "GITHUB_TOKEN") More info: https://docs.docker.com/go/dockerfile/rule/secrets-used-in-arg-or-env/

Check warning on line 8 in Dockerfiles/DockerfileKube.base

View workflow job for this annotation

GitHub Actions / Build & Push Docker Images (Matrix) (kube-agent, mw-kube-agent, Dockerfiles/DockerfileKube.base, ...

Sensitive data should not be used in the ARG or ENV commands

SecretsUsedInArgOrEnv: Do not use ARG or ENV instructions for sensitive data (ARG "GITHUB_TOKEN") More info: https://docs.docker.com/go/dockerfile/rule/secrets-used-in-arg-or-env/

Check warning on line 8 in Dockerfiles/DockerfileKube.base

View workflow job for this annotation

GitHub Actions / Build & Push Docker Images (Matrix) (opsai, mw-opsai, Dockerfiles/DockerfileKube.base, ghcr.io/mi...

Sensitive data should not be used in the ARG or ENV commands

SecretsUsedInArgOrEnv: Do not use ARG or ENV instructions for sensitive data (ARG "GITHUB_TOKEN") More info: https://docs.docker.com/go/dockerfile/rule/secrets-used-in-arg-or-env/

Check warning on line 8 in Dockerfiles/DockerfileKube.base

View workflow job for this annotation

GitHub Actions / Build & Push Docker Images (Matrix) (synthetics, mw-synthetics, Dockerfiles/DockerfileKube.base, ...

Sensitive data should not be used in the ARG or ENV commands

SecretsUsedInArgOrEnv: Do not use ARG or ENV instructions for sensitive data (ARG "GITHUB_TOKEN") More info: https://docs.docker.com/go/dockerfile/rule/secrets-used-in-arg-or-env/

Check warning on line 8 in Dockerfiles/DockerfileKube.base

View workflow job for this annotation

GitHub Actions / Build & Push Docker Images (Matrix) (opsai, mw-opsai, Dockerfiles/DockerfileKube.base, ghcr.io/mi...

Sensitive data should not be used in the ARG or ENV commands

SecretsUsedInArgOrEnv: Do not use ARG or ENV instructions for sensitive data (ARG "GITHUB_TOKEN") More info: https://docs.docker.com/go/dockerfile/rule/secrets-used-in-arg-or-env/

Check warning on line 8 in Dockerfiles/DockerfileKube.base

View workflow job for this annotation

GitHub Actions / Build & Push Docker Images (Matrix) (kube-agent, mw-kube-agent, Dockerfiles/DockerfileKube.base, ...

Sensitive data should not be used in the ARG or ENV commands

SecretsUsedInArgOrEnv: Do not use ARG or ENV instructions for sensitive data (ARG "GITHUB_TOKEN") More info: https://docs.docker.com/go/dockerfile/rule/secrets-used-in-arg-or-env/

WORKDIR /app

# Install dependencies and update CA certificates in a single layer
RUN apt-get update && \
apt-get install -y --no-install-recommends ca-certificates openssl && \
update-ca-certificates && \
rm -rf /var/lib/apt/lists/*

# Copy only necessary files to the build stage
# Set up private repo access before downloading modules
RUN git config --global url."https://${GITHUB_TOKEN}:x-oauth-basic@github.com/".insteadOf "https://github.com/"

COPY go.mod go.sum ./
RUN go mod tidy
ENV GOPRIVATE=github.com/middleware-labs
RUN go mod download

COPY . .

# Set up environment variables for build
ENV CGO_ENABLED=0
ARG GITHUB_TOKEN
ENV GITHUB_TOKEN=$GITHUB_TOKEN
RUN git config --global url."https://${GITHUB_TOKEN}:x-oauth-basic@github.com/".insteadOf "https://github.com/"
RUN GOPRIVATE=github.com/middleware-labs go mod tidy

# Build the Go binary
# Cross-compile for the target platform natively
ARG AGENT_VERSION
ENV AGENT_VERSION=$AGENT_VERSION
ARG APP_BINARY
ENV APP_BINARY=$APP_BINARY
# Dynamically select the main.go file based on APP_BINARY by removing 'mw-' prefix
RUN AGENT_FOLDER="$(echo $APP_BINARY | sed 's/^mw-//')" && \
SRC="cmd/${AGENT_FOLDER}/main.go" && \
if [ ! -f "$SRC" ]; then echo "Source file $SRC does not exist!" && exit 1; fi && \
CGO_ENABLED=0 go build -ldflags "-s -w -X main.agentVersion=${AGENT_VERSION}" -o /tmp/mw-agent "$SRC"
CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build \
-ldflags "-s -w -X main.agentVersion=${AGENT_VERSION}" \
-o /tmp/mw-agent "$SRC"

# Stage 2: Production Stage
FROM ubuntu:24.04 AS prod
RUN apt-get update && apt-get install -y systemd
RUN apt-get update && apt-get install -y --no-install-recommends systemd ca-certificates curl && \
rm -rf /var/lib/apt/lists/*

WORKDIR /app

# Install kubectl
ARG TARGETARCH
ARG APP_BINARY
RUN apt-get install -y curl
RUN if [ "$APP_BINARY" = "mw-opsai" ]; then \
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" && \
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/${TARGETARCH}/kubectl" && \
install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl && \
rm kubectl; \
fi

RUN rm -fr /var/lib/apt/lists/*

# Copy necessary files from the build stage
COPY --from=build /etc/ssl/certs /etc/ssl/certs
COPY --from=build /tmp/mw-agent /usr/bin/mw-agent
Expand Down
Loading