Skip to content

Commit dc76444

Browse files
committed
Build Docker Images Locally When Dockerfiles Change
1 parent 10629df commit dc76444

File tree

14 files changed

+487
-329
lines changed

14 files changed

+487
-329
lines changed

.github/actions/docker-publish/action.yml renamed to .github/actions/docker-skiko-publish/action.yml

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,66 @@
1-
name: 'Docker Publish'
2-
description: 'Build and optionally publish a Docker image to a registry'
1+
name: 'Docker Skiko Publish'
2+
description: 'Build and optionally publish a Docker image to ghcr.io for skiko'
33

44
inputs:
5-
registry:
6-
description: 'Docker registry (e.g., ghcr.io)'
7-
required: true
8-
namespace:
9-
description: 'Image namespace (e.g., owner/repo)'
10-
required: true
115
image_name:
12-
description: 'Image name (e.g., linux-amd64)'
13-
required: true
14-
context:
15-
description: 'Build context path (e.g., ./skiko/docker/linux-amd64)'
6+
description: 'Image name (e.g., linux-compat)'
167
required: true
178
platforms:
189
description: 'Target platforms (e.g., linux/amd64 or linux/amd64,linux/arm64)'
1910
required: true
2011
tag:
21-
description: 'Image tag (e.g., ubuntu-2004)'
12+
description: 'Image tag (e.g., latest)'
2213
required: true
14+
load:
15+
description: 'Whether to load the image into the local Docker daemon'
16+
required: false
17+
default: 'false'
2318
should_publish:
2419
description: 'Whether to push the image to the registry'
2520
required: true
2621
github_token:
27-
description: 'GitHub token for authentication'
28-
required: true
22+
description: 'GitHub token for authentication (required only if should_publish is true)'
23+
required: false
2924

3025
runs:
3126
using: 'composite'
3227
steps:
28+
- name: 'Set Variables'
29+
id: vars
30+
shell: bash
31+
run: |
32+
echo "image_namespace=${GITHUB_REPOSITORY,,}" >> $GITHUB_OUTPUT
33+
# Normalize tag: replace invalid docker tag characters
34+
TAG="${{ inputs.tag }}"
35+
TAG="${TAG//\//-}"
36+
echo "tag=${TAG}" >> $GITHUB_OUTPUT
37+
3338
- name: 'Set up Docker Buildx'
3439
uses: docker/setup-buildx-action@v3
3540

3641
- name: 'Log into registry'
3742
if: inputs.should_publish == 'true'
3843
uses: docker/login-action@v3
3944
with:
40-
registry: ${{ inputs.registry }}
45+
registry: ghcr.io
4146
username: ${{ github.actor }}
4247
password: ${{ inputs.github_token }}
4348

4449
- name: 'Extract metadata'
4550
id: meta
4651
uses: docker/metadata-action@v5
4752
with:
48-
images: ${{ inputs.registry }}/${{ inputs.namespace }}/${{ inputs.image_name }}
53+
images: ghcr.io/${{ steps.vars.outputs.image_namespace }}/${{ inputs.image_name }}
4954
tags: |
50-
type=raw,value=${{ inputs.tag }}
55+
type=raw,value=${{ steps.vars.outputs.tag }}
5156
5257
- name: 'Build and push'
5358
uses: docker/build-push-action@v5
5459
with:
55-
context: ${{ inputs.context }}
60+
context: ./skiko/docker/${{ inputs.image_name }}
5661
platforms: ${{ inputs.platforms }}
5762
push: ${{ inputs.should_publish == 'true' }}
63+
load: ${{ inputs.load == 'true' }}
5864
tags: ${{ steps.meta.outputs.tags }}
5965
labels: ${{ steps.meta.outputs.labels }}
6066
cache-from: type=gha
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
name: 'Docker Skiko Run'
2+
description: 'Build Docker image locally if needed and run commands inside it'
3+
4+
inputs:
5+
image_name:
6+
description: 'Image name (e.g., linux-compat)'
7+
required: true
8+
platforms:
9+
description: 'Target platforms (e.g., linux/amd64)'
10+
required: true
11+
default: 'linux/amd64'
12+
command:
13+
description: 'Command to run inside the container'
14+
required: true
15+
working_directory:
16+
description: 'Working directory relative to project root (e.g., samples/SkiaAndroidSample)'
17+
required: false
18+
default: '.'
19+
virtual-display:
20+
description: 'Enable virtual display for UI testing (enables e2e UI interaction tests with real windows)'
21+
required: false
22+
default: 'false'
23+
24+
runs:
25+
using: 'composite'
26+
steps:
27+
- name: 'Detect Docker changes'
28+
id: filter
29+
uses: dorny/paths-filter@v3
30+
with:
31+
base: ${{ github.base_ref || 'master' }}
32+
filters: |
33+
docker-changed:
34+
- '.github/actions/docker-skiko-publish/**'
35+
- '.github/workflows/docker-publish.yml'
36+
- 'skiko/docker/${{ inputs.image_name }}/**'
37+
38+
- name: 'Set Variables'
39+
id: vars
40+
shell: bash
41+
run: |
42+
IMAGE_NAMESPACE="${GITHUB_REPOSITORY,,}"
43+
echo "image_namespace=${IMAGE_NAMESPACE}" >> $GITHUB_OUTPUT
44+
45+
# Determine which tag to use
46+
# github.base_ref is set for PRs regardless of event type (pull_request or workflow_call)
47+
if [[ -n "${{ github.base_ref }}" && "${{ steps.filter.outputs.docker-changed }}" != "true" ]]; then
48+
# For PRs without docker changes, use base branch tag (pre-built image)
49+
TAG="${{ github.base_ref }}"
50+
else
51+
# For PRs with docker changes or non-PRs, use current branch tag
52+
TAG="${GITHUB_REF_NAME}"
53+
fi
54+
TAG="${TAG//\//-}"
55+
56+
# Try to pull image from GHCR
57+
# This checks both if the image exists in the registry and loads it into the local daemon
58+
if docker pull "ghcr.io/${IMAGE_NAMESPACE}/${{ inputs.image_name }}:${TAG}" >/dev/null 2>&1; then
59+
IMAGE_EXISTS="true"
60+
else
61+
IMAGE_EXISTS="false"
62+
fi
63+
64+
echo "tag=${TAG}" >> $GITHUB_OUTPUT
65+
echo "image_exists=${IMAGE_EXISTS}" >> $GITHUB_OUTPUT
66+
67+
- name: 'Build Docker image locally (if needed)'
68+
if: steps.filter.outputs.docker-changed == 'true' || steps.vars.outputs.image_exists == 'false'
69+
uses: ./.github/actions/docker-skiko-publish
70+
with:
71+
image_name: ${{ inputs.image_name }}
72+
platforms: ${{ inputs.platforms }}
73+
tag: ${{ steps.vars.outputs.tag }}
74+
load: true
75+
should_publish: false
76+
77+
- name: 'Prepare command'
78+
id: cmd
79+
shell: bash
80+
run: |
81+
CMD="${{ inputs.command }}"
82+
if [[ "${{ inputs.virtual-display }}" == "true" ]]; then
83+
CMD="Xvfb :1 -screen 0 1920x1080x24 -extension RANDR +extension GLX & export DISPLAY=:1.0 && ${CMD}"
84+
fi
85+
{
86+
echo "command<<EOF"
87+
echo "${CMD}"
88+
echo "EOF"
89+
} >> $GITHUB_OUTPUT
90+
91+
- name: 'Run command in container'
92+
shell: bash
93+
run: |
94+
docker run --rm \
95+
-v "${{ github.workspace }}":/workspace \
96+
-w /workspace/${{ inputs.working_directory }} \
97+
"ghcr.io/${{ steps.vars.outputs.image_namespace }}/${{ inputs.image_name }}:${{ steps.vars.outputs.tag }}" \
98+
bash -c "${{ steps.cmd.outputs.command }}"

.github/actions/setup-prerequisites/action.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
11
name: 'Setup Prerequisites'
2+
description: 'Shared steps to prepare build environment'
3+
24
runs:
35
using: "composite"
46
steps:
7+
- name: Free up space on GitHub runner
8+
if: runner.os == 'Linux'
9+
shell: bash
10+
run: |
11+
df -h
12+
sudo rm -rf /usr/share/dotnet
13+
sudo rm -rf /opt/ghc
14+
sudo rm -rf /opt/hostedtoolcache/CodeQL
15+
df -h
16+
517
- name: Setup Gradle
618
uses: gradle/actions/setup-gradle@v4
719
with:

0 commit comments

Comments
 (0)