Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
6dee3a5
chore: fork and simplify the gitlab pipelines
apiarian-datadog Feb 11, 2025
07ac616
chore: gitlab-ci.yml needs to be hidden
apiarian-datadog Feb 11, 2025
828a698
chore: a bit clearer pipeline steps
apiarian-datadog Feb 11, 2025
78d7152
chore: docs suggest we do not need to manually pass in the variables
apiarian-datadog Feb 11, 2025
74e563a
chore: check that we are using the agent branch as expected
apiarian-datadog Feb 11, 2025
0a1a423
chore: we should not alias the variables
apiarian-datadog Feb 11, 2025
30735b9
pull the lint and fmt and clippy checks into an initial stage
apiarian-datadog Feb 11, 2025
55e98d2
chore: clarify that our checks are in cargo
apiarian-datadog Feb 11, 2025
02c94d1
chore: add a bit of documenttion for our datadog_wrapper script
apiarian-datadog Feb 11, 2025
bffd627
chore: try to start using flavors instead of architectures
apiarian-datadog Feb 11, 2025
8017a4a
chore: config needs to know about the flavors
apiarian-datadog Feb 11, 2025
a5620f3
chore: if in the template, not the job
apiarian-datadog Feb 12, 2025
13db576
chore: move the rest of the code checks into the flavors loop
apiarian-datadog Feb 12, 2025
95d194c
chore: separate out the compile stage for go
apiarian-datadog Feb 12, 2025
2a575d2
chore: speed up builds by skipping checks for now
apiarian-datadog Feb 12, 2025
33f0c78
Revert "chore: speed up builds by skipping checks for now"
apiarian-datadog Feb 12, 2025
83abe10
chore: fix another typo
apiarian-datadog Feb 12, 2025
ab9cc90
chore: fix scratch cmd path
apiarian-datadog Feb 12, 2025
16bb63a
chore: drop the serverless-init bits for go agent compilation in gitlab
apiarian-datadog Feb 12, 2025
0edab6c
chore: do we need to say dockerfile experimental if that tag was last…
apiarian-datadog Feb 12, 2025
78ea098
chore: missed a few bits
apiarian-datadog Feb 12, 2025
a43c9e9
chore: fix lint and correct alpine flag check
apiarian-datadog Feb 12, 2025
3c4b9f1
chore: also compile bottlecap
apiarian-datadog Feb 12, 2025
597b311
chore: build the layers
apiarian-datadog Feb 12, 2025
21a143d
chore: building the layer probably does not need ALPINE stuff
apiarian-datadog Feb 12, 2025
6ca47d7
chore: fix typo
apiarian-datadog Feb 12, 2025
aba4411
chore: use the new layer builders instead of the old ones
apiarian-datadog Feb 12, 2025
d530262
chore: move layer check into the flavor loop
apiarian-datadog Feb 12, 2025
33bb3e1
chore: move layer publish into the flavors loop
apiarian-datadog Feb 12, 2025
a133afc
chore: add an easy-to-use sanbox job
apiarian-datadog Feb 12, 2025
0465f9c
chore: move cargo deps around
apiarian-datadog Feb 12, 2025
cf23570
chore: publis private images with flavors
apiarian-datadog Feb 12, 2025
1840f9b
chore: layers for all
apiarian-datadog Feb 12, 2025
c6f67b1
chore: move layer signing under flavors
apiarian-datadog Feb 12, 2025
3682a33
chore: bring back mutli-arch primate image builds
apiarian-datadog Feb 13, 2025
280e9c4
chore: move build and publish public images in the loop too
apiarian-datadog Feb 13, 2025
4d2b8be
separate sandbox from publish for convenience
apiarian-datadog Feb 13, 2025
41f53d6
chore: clean up all the extra files
apiarian-datadog Feb 13, 2025
d0061ff
chore: missed a bit
apiarian-datadog Feb 13, 2025
ca02731
chore: rename stages
apiarian-datadog Feb 13, 2025
62e13a4
chore: bring back some dockerfiles i accidentally deleted
apiarian-datadog Feb 13, 2025
64029a6
chore: we only need layer size checks for prod deploys
apiarian-datadog Feb 13, 2025
7b68904
bring back the variables
apiarian-datadog Feb 13, 2025
722a068
Revert "bring back the variables"
apiarian-datadog Feb 13, 2025
b1a7f65
chore: do we need to forward pipeline variablles?
apiarian-datadog Feb 13, 2025
0cda5dc
chore: add a note about the important forwarding flag
apiarian-datadog Feb 13, 2025
5a813e3
chore: prevent actual gitlab pushes
apiarian-datadog Feb 13, 2025
26e1c6a
Revert "chore: prevent actual gitlab pushes"
apiarian-datadog Feb 13, 2025
cc2ee94
chore: logical sorting and better naming
apiarian-datadog Feb 13, 2025
5fcf2bc
chore: mark the existing scripts as potentially dangerous for now
apiarian-datadog Feb 13, 2025
7673d54
Revert "chore: mark the existing scripts as potentially dangerous for…
apiarian-datadog Feb 14, 2025
44310e2
chore: rename sanbox layer publish
apiarian-datadog Feb 18, 2025
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
53 changes: 14 additions & 39 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ variables:
value: ""

stages:
- prepare
- generate
- build
- run

ci image:
stage: build
stage: prepare
image: registry.ddbuild.io/images/docker:20.10
tags: ["arch:arm64"]
rules:
Expand All @@ -44,55 +45,29 @@ generator:
cache: *go-cache
artifacts:
paths:
- .gitlab/pipeline-bottlecap.yaml
- .gitlab/pipeline-go-agent.yaml
- .gitlab/pipeline-lambda-extension.yaml
- .gitlab/pipeline.yaml
reports:
dotenv: .env
script:
- if [[ "$CI_COMMIT_TAG" =~ ^v[0-9]+$ ]]; then echo "VERSION=${CI_COMMIT_TAG//[!0-9]/}" >> .env; fi
- apk add --no-cache gomplate
- gomplate --config .gitlab/config.yaml

bottlecap-only:
stage: build
generated pipeline:
stage: run
trigger:
include:
- artifact: .gitlab/pipeline-bottlecap.yaml
job: generator
strategy: depend
rules:
- when: on_success

go-agent-only:
stage: build
trigger:
include:
- artifact: .gitlab/pipeline-go-agent.yaml
job: generator
strategy: depend
rules:
- if: $CI_PIPELINE_SOURCE == "web"
when: manual
variables:
AGENT_BRANCH: $AGENT_BRANCH
LAYER_SUFFIX: $LAYER_SUFFIX
AGENT_VERSION: $AGENT_VERSION

lambda-extension:
stage: build
trigger:
include:
- artifact: .gitlab/pipeline-lambda-extension.yaml
- artifact: .gitlab/pipeline.yaml
job: generator
strategy: depend
forward:
yaml_variables: true
# Without this pipeline_variables: true bit the pipeline we trigger will
# not get the variables that we set as part of our release process in our
# manual pipeline runs.
pipeline_variables: true
needs:
- job: generator
artifacts: true
rules:
- if: $CI_PIPELINE_SOURCE == "web"
variables:
VERSION: $VERSION
AGENT_BRANCH: $AGENT_BRANCH
LAYER_SUFFIX: $LAYER_SUFFIX
AGENT_VERSION: $AGENT_VERSION
- when: on_success
12 changes: 4 additions & 8 deletions .gitlab/config.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
# gomplate template generation pipeline

inputFiles:
- .gitlab/templates/bottlecap.yaml.tpl
- .gitlab/templates/go-agent.yaml.tpl
- .gitlab/templates/lambda-extension.yaml.tpl
- .gitlab/templates/pipeline.yaml.tpl

outputFiles:
- .gitlab/pipeline-bottlecap.yaml
- .gitlab/pipeline-go-agent.yaml
- .gitlab/pipeline-lambda-extension.yaml
- .gitlab/pipeline.yaml

datasources:
architectures:
url: .gitlab/datasources/architectures.yaml
flavors:
url: .gitlab/datasources/flavors.yaml

environments:
url: .gitlab/datasources/environments.yaml
Expand Down
3 changes: 0 additions & 3 deletions .gitlab/datasources/architectures.yaml

This file was deleted.

43 changes: 43 additions & 0 deletions .gitlab/datasources/flavors.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
flavors:
- name: amd64
arch: amd64
alpine: 0
needs_code_checks: true
needs_layer_publish: true
suffix: amd64

- name: arm64
arch: arm64
alpine: 0
needs_code_checks: true
needs_layer_publish: true
suffix: arm64

- name: amd64, alpine
arch: amd64
alpine: 1
needs_code_checks: false
needs_layer_publish: false
suffix: amd64-alpine

- name: arm64, alpine
arch: arm64
alpine: 1
needs_code_checks: false
needs_layer_publish: false
suffix: arm64-alpine

# Unfortunately our mutli-arch images don't fit nicely into the flavors
# structure above.
multi_arch_image_flavors:
- name: basic
alpine: 0
platform: linux/amd64,linux/arm64
dependency_names: [amd64, arm64]
suffix: ""

- name: alpine
alpine: 1
platform: linux/amd64,linux/arm64
dependency_names: ["amd64, alpine", "arm64, alpine"]
suffix: "-alpine"
31 changes: 31 additions & 0 deletions .gitlab/scripts/Dockerfile.bottlecap.alpine.compile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
FROM alpine:3.16 AS compiler
ARG PLATFORM
RUN apk add --no-cache curl gcc musl-dev make unzip bash autoconf automake libtool g++

SHELL ["/bin/bash", "-c"]

# Install Protocol Buffers, from package instead of manually
RUN apk add --no-cache protoc

# Install Rust Toolchain
RUN curl https://sh.rustup.rs -sSf | \
sh -s -- --profile minimal --default-toolchain stable-$PLATFORM-unknown-linux-musl -y
ENV PATH=/root/.cargo/bin:$PATH
RUN rustup component add rust-src --toolchain stable-$PLATFORM-unknown-linux-musl

# Build Bottlecap
RUN mkdir -p /tmp/dd
COPY ./bottlecap/src /tmp/dd/bottlecap/src
COPY ./bottlecap/Cargo.toml /tmp/dd/bottlecap/Cargo.toml
COPY ./bottlecap/Cargo.lock /tmp/dd/bottlecap/Cargo.lock
# Added `-C link-arg=-lgcc` for alpine.
ENV RUSTFLAGS="-C panic=abort -C link-arg=-lgcc"
WORKDIR /tmp/dd/bottlecap
RUN --mount=type=cache,target=/root/.cargo/registry cargo +stable build --release --target $PLATFORM-unknown-linux-musl
RUN cp /tmp/dd/bottlecap/target/$PLATFORM-unknown-linux-musl/release/bottlecap /tmp/dd/bottlecap/bottlecap

# keep the smallest possible docker image
FROM scratch
COPY --from=compiler /tmp/dd/bottlecap/bottlecap /
ENTRYPOINT ["/bottlecap"]

25 changes: 25 additions & 0 deletions .gitlab/scripts/Dockerfile.bottlecap.compile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
FROM public.ecr.aws/lambda/provided:al2 AS compiler
ARG PLATFORM
RUN yum install -y curl gcc gcc-c++ make unzip

# Install Protocol Buffers compiler by hand, since AL2 does not have a recent enough version.
COPY ./scripts/install-protoc.sh /
RUN chmod +x /install-protoc.sh && /install-protoc.sh
RUN curl https://sh.rustup.rs -sSf | \
sh -s -- --profile minimal --default-toolchain stable-$PLATFORM-unknown-linux-gnu -y
ENV PATH=/root/.cargo/bin:$PATH
RUN rustup component add rust-src --toolchain stable-$PLATFORM-unknown-linux-gnu
RUN mkdir -p /tmp/dd
COPY ./bottlecap/src /tmp/dd/bottlecap/src
COPY ./bottlecap/Cargo.toml /tmp/dd/bottlecap/Cargo.toml
COPY ./bottlecap/Cargo.lock /tmp/dd/bottlecap/Cargo.lock
ENV RUSTFLAGS="-C panic=abort"
WORKDIR /tmp/dd/bottlecap
RUN --mount=type=cache,target=/usr/local/cargo/registry cargo +stable build --release --target $PLATFORM-unknown-linux-gnu
RUN cp /tmp/dd/bottlecap/target/$PLATFORM-unknown-linux-gnu/release/bottlecap /tmp/dd/bottlecap/bottlecap

# keep the smallest possible docker image
FROM scratch
COPY --from=compiler /tmp/dd/bottlecap/bottlecap /
ENTRYPOINT ["/bottlecap"]

26 changes: 26 additions & 0 deletions .gitlab/scripts/Dockerfile.build_layer
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
FROM ubuntu:22.04 as compresser
ARG DATADOG_WRAPPER=datadog_wrapper
ARG SUFFIX

RUN apt-get update
RUN apt-get install -y zip binutils upx

COPY .binaries/datadog-agent-$SUFFIX /datadog-agent-go
RUN strip /datadog-agent-go
RUN upx -1 /datadog-agent-go

RUN mkdir /extensions
WORKDIR /extensions

COPY .binaries/bottlecap-$SUFFIX /extensions/datadog-agent

COPY ./scripts/$DATADOG_WRAPPER /$DATADOG_WRAPPER
RUN chmod +x /$DATADOG_WRAPPER

RUN zip -r datadog_extension.zip /extensions /$DATADOG_WRAPPER /datadog-agent-go

# keep the smallest possible docker image
FROM scratch
COPY --from=compresser /extensions/datadog_extension.zip /
ENTRYPOINT ["/datadog_extension.zip"]

5 changes: 5 additions & 0 deletions .gitlab/scripts/Dockerfile.extension_image
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM scratch
ARG TARGETARCH
COPY .layers/datadog_extension-$TARGETARCH/extensions/datadog-agent opt/extensions/datadog-agent
COPY .layers/datadog_extension-$TARGETARCH/datadog-agent-go opt/datadog-agent-go
COPY --chmod=0755 scripts/datadog_wrapper opt/datadog_wrapper
5 changes: 5 additions & 0 deletions .gitlab/scripts/Dockerfile.extension_image.alpine
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM scratch
ARG TARGETARCH
COPY .layers/datadog_extension-$TARGETARCH-alpine/extensions/datadog-agent opt/extensions/datadog-agent
COPY .layers/datadog_extension-$TARGETARCH-alpine/datadog-agent-go opt/datadog-agent-go
COPY --chmod=0755 scripts/datadog_wrapper opt/datadog_wrapper
50 changes: 50 additions & 0 deletions .gitlab/scripts/Dockerfile.go_agent.alpine.compile
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
FROM alpine:3.16 AS compiler
ARG EXTENSION_VERSION
ARG AGENT_VERSION
ARG BUILD_TAGS

RUN apk add --no-cache git make musl-dev gcc
COPY --from=golang:1.23.6-alpine /usr/local/go/ /usr/lib/go

ENV GOROOT=/usr/lib/go
ENV GOPATH=/go
ENV PATH=/go/bin:$PATH

RUN mkdir -p ${GOPATH}/src ${GOPATH}/bin
RUN mkdir -p /tmp/dd/datadog-agent

# cache dependencies
COPY ./scripts/.cache/go.mod /tmp/dd/datadog-agent
COPY ./scripts/.cache/go.sum /tmp/dd/datadog-agent
WORKDIR /tmp/dd/datadog-agent

# copy source files (/tgz gets unzip automatically by Docker)
ADD ./scripts/.src/datadog-agent.tgz /tmp/dd

# build the extension
WORKDIR /tmp/dd/datadog-agent/cmd/serverless
# add the current version number to the tags package before compilation

RUN --mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/root/.cache/go-build \
if [ -z "$AGENT_VERSION" ]; then \
/usr/lib/go/bin/go build -ldflags="-w -extldflags '-static' \
-X github.com/DataDog/datadog-agent/pkg/serverless/tags.currentExtensionVersion=$EXTENSION_VERSION" \
-tags "${BUILD_TAGS}" -o datadog-agent; \
else \
/usr/lib/go/bin/go build -ldflags="-w -extldflags '-static' \
-X github.com/DataDog/datadog-agent/pkg/serverless/tags.currentExtensionVersion=$EXTENSION_VERSION \
-X github.com/DataDog/datadog-agent/pkg/version.agentVersionDefault=$AGENT_VERSION" \
-tags "${BUILD_TAGS}" -o datadog-agent; \
fi

RUN /usr/lib/go/bin/go tool nm datadog-agent | grep -w 'github.com/DataDog/datadog-agent/pkg/version.agentVersionDefault' || \
(echo "agentVersionDefault variable doesn't exist" && exit 1)

RUN strip datadog-agent

# keep the smallest possible docker image
FROM scratch
COPY --from=compiler /tmp/dd/datadog-agent/cmd/serverless/datadog-agent /
ENTRYPOINT ["/datadog-agent"]

52 changes: 52 additions & 0 deletions .gitlab/scripts/Dockerfile.go_agent.compile
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
FROM public.ecr.aws/lambda/provided:al2 AS compiler
ARG EXTENSION_VERSION
ARG AGENT_VERSION
ARG BUILD_TAGS
RUN mkdir -p /tmp/dd/datadog-agent

RUN yum install -y wget tar gzip gcc
RUN arch="$(uname -m)"; \
if [ "${arch}" = 'aarch64' ]; then \
arch='arm64'; \
fi; \
if [ "${arch}" = 'x86_64' ]; then \
arch='amd64'; \
fi; \
wget -O go1.23.6.linux-${arch}.tar.gz https://go.dev/dl/go1.23.6.linux-${arch}.tar.gz; \
tar -C /usr/local -xzf go1.23.6.linux-${arch}.tar.gz

# cache dependencies
COPY ./scripts/.cache/go.mod /tmp/dd/datadog-agent
COPY ./scripts/.cache/go.sum /tmp/dd/datadog-agent
WORKDIR /tmp/dd/datadog-agent

# copy source files (/tgz gets unzip automatically by Docker)
ADD ./scripts/.src/datadog-agent.tgz /tmp/dd

# build the extension
WORKDIR /tmp/dd/datadog-agent/cmd/serverless
# add the current version number to the tags package before compilation

RUN --mount=type=cache,target=/root/go/pkg/mod \
--mount=type=cache,target=/root/.cache/go-build \
if [ -z "$AGENT_VERSION" ]; then \
/usr/local/go/bin/go build -ldflags="-w \
-X github.com/DataDog/datadog-agent/pkg/serverless/tags.currentExtensionVersion=$EXTENSION_VERSION" \
-tags "${BUILD_TAGS}" -o datadog-agent; \
else \
/usr/local/go/bin/go build -ldflags="-w \
-X github.com/DataDog/datadog-agent/pkg/serverless/tags.currentExtensionVersion=$EXTENSION_VERSION \
-X github.com/DataDog/datadog-agent/pkg/version.agentVersionDefault=$AGENT_VERSION" \
-tags "${BUILD_TAGS}" -o datadog-agent; \
fi

RUN /usr/local/go/bin/go tool nm datadog-agent | grep -w 'github.com/DataDog/datadog-agent/pkg/version.agentVersionDefault' || \
(echo "agentVersionDefault variable doesn't exist" && exit 1)

RUN strip datadog-agent

# keep the smallest possible docker imag
FROM scratch
COPY --from=compiler /tmp/dd/datadog-agent/cmd/serverless/datadog-agent /
ENTRYPOINT ["/datadog-agent"]

Loading
Loading