Skip to content

Commit b8b863e

Browse files
committed
feat(.github/actions): allow to cache and run Docker images
1 parent c0fc809 commit b8b863e

File tree

4 files changed

+101
-4
lines changed

4 files changed

+101
-4
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Run service
2+
description: Runs a Docker image from cache
3+
inputs:
4+
repository:
5+
required: true
6+
description: The repository of the image to warm up
7+
tag:
8+
required: true
9+
description: The tag of the image to warm up (latest tag not supported)
10+
flags:
11+
required: true
12+
description: The flags to pass to the service
13+
runs:
14+
using: "composite"
15+
steps:
16+
- name: Build cache filename
17+
id: build_cache_filename
18+
shell: bash
19+
run: |
20+
cache_filename=$(printf '%s_%s' "${{ inputs.repository }}" "${{ inputs.tag }}" | tr -cs '[:alnum:]_' '_')
21+
echo "cache_filename=$cache_filename" >> $GITHUB_OUTPUT
22+
- name: Restore image cache
23+
uses: actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4
24+
with:
25+
path: ${{ steps.build_cache_filename.outputs.cache_filename }}.tar
26+
key: ${{ inputs.repository }}:${{ inputs.tag }}
27+
- name: Load image
28+
shell: bash
29+
run: |
30+
docker load -i ${{ steps.build_cache_filename.outputs.cache_filename }}.tar
31+
- name: Run service
32+
shell: bash
33+
run: |
34+
docker run -d ${{ inputs.flags }} ${{ inputs.repository }}:${{ inputs.tag }}

.github/workflows/pull-request.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,21 @@ jobs:
2424
with:
2525
path: .git
2626
key: gitdb-${{ github.repository_id }}-${{ github.sha }}
27+
warm-services-cache:
28+
strategy:
29+
matrix:
30+
image:
31+
- repository: datadog/agent
32+
tag: 7.69.2
33+
uses: ./.github/workflows/warm-up-service.yml
34+
with:
35+
repository: ${{ matrix.image.repository }}
36+
tag: ${{ matrix.image.tag }}
2737
unit-integration-tests:
2838
name: PR Unit and Integration Tests
2939
needs:
3040
- warm-repo-cache
41+
- warm-services-cache
3142
strategy:
3243
matrix:
3344
go-version: [ "1.24", "1.25" ]
@@ -39,6 +50,7 @@ jobs:
3950
multios-unit-tests:
4051
needs:
4152
- warm-repo-cache
53+
- warm-services-cache
4254
strategy:
4355
matrix:
4456
runs-on: [ macos-latest, windows-latest, ubuntu-latest ]

.github/workflows/unit-integration-tests.yml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@ jobs:
3737
with:
3838
ref: ${{ github.sha }}
3939
clean: false
40-
4140
- name: Compute Matrix
4241
id: matrix
4342
run: |-
4443
echo -n "matrix=" >> "${GITHUB_OUTPUT}"
4544
go run ./scripts/ci_contrib_matrix.go >> "${GITHUB_OUTPUT}"
4645
4746
test-contrib-matrix:
48-
needs: set-up
47+
needs:
48+
- set-up
4949
runs-on:
5050
group: "APM Larger Runners"
5151
env:
@@ -263,8 +263,6 @@ jobs:
263263
group: "APM Larger Runners"
264264
env:
265265
INTEGRATION: true
266-
services:
267-
datadog-agent: *datadog-agent
268266
steps:
269267
- name: Restore repo cache
270268
uses: actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4
@@ -282,6 +280,15 @@ jobs:
282280
go-version: ${{ inputs.go-version }}
283281
tools-dir: ${{ github.workspace }}/_tools
284282
tools-bin: ${{ github.workspace }}/bin
283+
- name: Start datadog/agent
284+
uses: ./.github/actions/run-service
285+
with:
286+
repository: datadog/agent
287+
tag: 7.69.2
288+
# We need to specify a custom health-check. By default, this container will remain "unhealthy" since
289+
# we don't fully configure it with a valid API key (and possibly other reasons)
290+
# This command just checks for our ability to connect to port 8126
291+
flags: --name datadog-agent -e DD_HOSTNAME=github-actions-worker -e DD_APM_ENABLED=true -e DD_BIND_HOST=0.0.0.0 -e DD_API_KEY=invalid_key_but_this_is_fine -e DD_TEST_AGENT_HOST=localhost -e DD_TEST_AGENT_PORT=9126 --health-cmd "bash -c '</dev/tcp/127.0.0.1/8126'" -p 8125:8125/udp -p 8126:8126
285292
- name: Test Core
286293
env:
287294
DD_APPSEC_WAF_TIMEOUT: 1h
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Warm up service
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
repository:
7+
required: true
8+
type: string
9+
description: The repository of the image to warm up
10+
tag:
11+
required: true
12+
type: string
13+
description: The tag of the image to warm up (latest tag not supported)
14+
15+
jobs:
16+
warm-up:
17+
runs-on: ubuntu-latest
18+
outputs:
19+
cache_filename: ${{ steps.pull_image.outputs.cache_filename }}
20+
steps:
21+
- name: Restore repo cache
22+
uses: actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4
23+
with:
24+
path: .git
25+
key: gitdb-${{ github.repository_id }}-${{ github.sha }}
26+
- name: Checkout
27+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
28+
with:
29+
ref: ${{ github.sha }}
30+
clean: false
31+
- name: Pull Docker image
32+
id: pull_image
33+
shell: bash
34+
run: |
35+
image=${{ inputs.repository }}:${{ inputs.tag }}
36+
docker pull $image
37+
cache_filename=$(printf '%s_%s' "${{ inputs.repository }}" "${{ inputs.tag }}" | tr -cs '[:alnum:]_' '_')
38+
echo "cache_filename=$cache_filename" >> $GITHUB_OUTPUT
39+
docker save $image > $cache_filename.tar
40+
- name: Cache Docker image
41+
uses: actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4
42+
with:
43+
path: "${{ steps.pull_image.outputs.cache_filename }}.tar"
44+
key: "${{ inputs.repository }}:${{ inputs.tag }}"

0 commit comments

Comments
 (0)